PHP Class phpDataMapper_Base, phpDataMapper

Mostra file Open project: vlucas/phpDataMapper Class Usage Examples

Protected Properties

Property Type Description
$_adapter Stored adapter connections
$_adapterRead
$_collectionClass
$_datasource Data source setup info
$_entityClass Class Names for required classes - Here so they can be easily overridden
$_errors Array of error messages and types
$_exceptionClass
$_fields Store cached field info
$_primaryKey
$_queryClass
$_queryLog Query log
$_relations

Public Methods

Method Description
__construct ( phpDataMapper_Adapter_Interface $adapter, $adapterRead = null ) Constructor Method
adapter ( ) Get current adapter object
adapterRead ( ) Get adapter object that will serve as the 'slave' for reads
all ( array $conditions = [] ) Find records with given conditions If all parameters are empty, find all records
collectionClass ( ) : string Get collection class name to use
datasource ( ) Get name of the data source
debug ( $entity = null ) Prints all executed SQL queries - useful for debugging
delete ( mixed $conditions ) Delete items matching given conditions
dropDatasource ( ) Drop/delete data source Destructive and dangerous - drops entire data source and all data
entityClass ( ) : string Get entity class name to use
error ( string $field, mixed $msg ) Add an error to error messages array
errors ( $msgs = null ) : array Get array of error messages
fieldExists ( $field ) Check if field exists in defined fields
fields ( ) : array Get formatted fields with all neccesary array keys and values.
first ( array $conditions = [] ) Find first record matching given conditions
get ( $primaryKeyValue ) Load record from primary key
getEntityRelationWithValues ( phpDataMapper_Entity $entity ) Replace entity value placeholders on relation definitions Currently replaces 'entity.[col]' with the column value from the passed entity object
getRelationsFor ( phpDataMapper_Entity $entity ) Load defined relations
getResultSet ( $stmt ) Get result set for given PDO Statement
hasErrors ( string $field = null ) : boolean Check if any errors exist
init ( ) Initialization function, run immediately after __construct() so that the constructor is never overridden
insert ( mixed $entity ) Insert record
isEmpty ( mixed $value ) : boolean Check if a value is empty, excluding 0 (annoying PHP issue)
loadClass ( $className ) Attempt to load class file based on phpDataMapper naming conventions
logQuery ( string $sql, array $data = null ) Log query
migrate ( ) Migrate table structure changes from model to database
primaryKey ( phpDataMapper_Entity $entity ) Get value of primary key for given row result
primaryKeyField ( ) Get value of primary key for given row result
query ( string $sql, array $binds = [] ) Find records with custom SQL query
queryClass ( ) : string Get query class name to use
queryCount ( ) : integer Get count of all queries that have been executed
relations ( ) Get defined relations
save ( mixed $entity ) Save record Will update if primary key found, insert if not Performs validation automatically before saving record
select ( mixed $fields = "*" ) Begin a new database query - get query builder Acts as a kind of factory to get the current adapter's query builder object
truncateDatasource ( ) Truncate data source Should delete all rows and reset serial/auto_increment keys to 0
update ( phpDataMapper_Entity $entity ) Update given row object
validate ( phpDataMapper_Entity $entity ) Run set validation rules on fields

Protected Methods

Method Description
saveRelatedRowsFor ( $entity, array $fillData = [] ) Save related rows of data

Method Details

__construct() public method

Constructor Method
public __construct ( phpDataMapper_Adapter_Interface $adapter, $adapterRead = null )
$adapter phpDataMapper_Adapter_Interface

adapter() public method

Get current adapter object
public adapter ( )

adapterRead() public method

Get adapter object that will serve as the 'slave' for reads
public adapterRead ( )

all() public method

Find records with given conditions If all parameters are empty, find all records
public all ( array $conditions = [] )
$conditions array Array of conditions in column => value pairs

collectionClass() public method

Get collection class name to use
public collectionClass ( ) : string
return string

datasource() public method

Get name of the data source
public datasource ( )

debug() public method

Prints all executed SQL queries - useful for debugging
public debug ( $entity = null )

delete() public method

Delete items matching given conditions
public delete ( mixed $conditions )
$conditions mixed Array of conditions in column => value pairs or Entity object

dropDatasource() public method

Drop/delete data source Destructive and dangerous - drops entire data source and all data
public dropDatasource ( )

entityClass() public method

Get entity class name to use
public entityClass ( ) : string
return string

error() public method

Add an error to error messages array
public error ( string $field, mixed $msg )
$field string Field name that error message relates to
$msg mixed Error message text - String or array of messages

errors() public method

Get array of error messages
public errors ( $msgs = null ) : array
return array

fieldExists() public method

Check if field exists in defined fields
public fieldExists ( $field )

fields() public method

Merges defaults with defined field values to ensure all options exist for each field.
public fields ( ) : array
return array Defined fields plus all defaults for full array of all possible options

first() public method

Find first record matching given conditions
public first ( array $conditions = [] )
$conditions array Array of conditions in column => value pairs

get() public method

Load record from primary key
public get ( $primaryKeyValue )

getEntityRelationWithValues() public method

Replace entity value placeholders on relation definitions Currently replaces 'entity.[col]' with the column value from the passed entity object
public getEntityRelationWithValues ( phpDataMapper_Entity $entity )
$entity phpDataMapper_Entity

getRelationsFor() public method

Load defined relations
public getRelationsFor ( phpDataMapper_Entity $entity )
$entity phpDataMapper_Entity

getResultSet() public method

Get result set for given PDO Statement
public getResultSet ( $stmt )

hasErrors() public method

Check if any errors exist
public hasErrors ( string $field = null ) : boolean
$field string OPTIONAL field name
return boolean

init() public method

Initialization function, run immediately after __construct() so that the constructor is never overridden
public init ( )

insert() public method

Insert record
public insert ( mixed $entity )
$entity mixed Entity object or array of field => value pairs

isEmpty() public method

Check if a value is empty, excluding 0 (annoying PHP issue)
public isEmpty ( mixed $value ) : boolean
$value mixed
return boolean

loadClass() public static method

Attempt to load class file based on phpDataMapper naming conventions
public static loadClass ( $className )

logQuery() public static method

Log query
public static logQuery ( string $sql, array $data = null )
$sql string
$data array

migrate() public method

Migrate table structure changes from model to database
public migrate ( )

primaryKey() public method

Get value of primary key for given row result
public primaryKey ( phpDataMapper_Entity $entity )
$entity phpDataMapper_Entity

primaryKeyField() public method

Get value of primary key for given row result
public primaryKeyField ( )

query() public method

Find records with custom SQL query
public query ( string $sql, array $binds = [] )
$sql string SQL query to execute
$binds array Array of bound parameters to use as values for query

queryClass() public method

Get query class name to use
public queryClass ( ) : string
return string

queryCount() public method

Get count of all queries that have been executed
public queryCount ( ) : integer
return integer

relations() public method

Get defined relations
public relations ( )

save() public method

Save record Will update if primary key found, insert if not Performs validation automatically before saving record
public save ( mixed $entity )
$entity mixed Entity object or array of field => value pairs

saveRelatedRowsFor() protected method

Save related rows of data
protected saveRelatedRowsFor ( $entity, array $fillData = [] )
$fillData array

select() public method

Begin a new database query - get query builder Acts as a kind of factory to get the current adapter's query builder object
public select ( mixed $fields = "*" )
$fields mixed String for single field or array of fields

truncateDatasource() public method

Truncate data source Should delete all rows and reset serial/auto_increment keys to 0
public truncateDatasource ( )

update() public method

Update given row object
public update ( phpDataMapper_Entity $entity )
$entity phpDataMapper_Entity

validate() public method

Run set validation rules on fields
public validate ( phpDataMapper_Entity $entity )
$entity phpDataMapper_Entity

Property Details

$_adapter protected_oe property

Stored adapter connections
protected $_adapter

$_adapterRead protected_oe property

protected $_adapterRead

$_collectionClass protected_oe property

protected $_collectionClass

$_datasource protected_oe property

Data source setup info
protected $_datasource

$_entityClass protected_oe property

Class Names for required classes - Here so they can be easily overridden
protected $_entityClass

$_errors protected_oe property

Array of error messages and types
protected $_errors

$_exceptionClass protected_oe property

protected $_exceptionClass

$_fields protected_oe property

Store cached field info
protected $_fields

$_primaryKey protected_oe property

protected $_primaryKey

$_queryClass protected_oe property

protected $_queryClass

$_queryLog protected_oe static_oe property

Query log
protected static $_queryLog

$_relations protected_oe property

protected $_relations