PHP Класс phpDataMapper_Base, phpDataMapper

Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$_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

Открытые методы

Метод Описание
__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

Защищенные методы

Метод Описание
saveRelatedRowsFor ( $entity, array $fillData = [] ) Save related rows of data

Описание методов

__construct() публичный Метод

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

adapter() публичный Метод

Get current adapter object
public adapter ( )

adapterRead() публичный Метод

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

all() публичный Метод

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() публичный Метод

Get collection class name to use
public collectionClass ( ) : string
Результат string

datasource() публичный Метод

Get name of the data source
public datasource ( )

debug() публичный Метод

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

delete() публичный Метод

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

dropDatasource() публичный Метод

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

entityClass() публичный Метод

Get entity class name to use
public entityClass ( ) : string
Результат string

error() публичный Метод

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() публичный Метод

Get array of error messages
public errors ( $msgs = null ) : array
Результат array

fieldExists() публичный Метод

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

fields() публичный Метод

Merges defaults with defined field values to ensure all options exist for each field.
public fields ( ) : array
Результат array Defined fields plus all defaults for full array of all possible options

first() публичный Метод

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

get() публичный Метод

Load record from primary key
public get ( $primaryKeyValue )

getEntityRelationWithValues() публичный Метод

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() публичный Метод

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

getResultSet() публичный Метод

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

hasErrors() публичный Метод

Check if any errors exist
public hasErrors ( string $field = null ) : boolean
$field string OPTIONAL field name
Результат boolean

init() публичный Метод

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

insert() публичный Метод

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

isEmpty() публичный Метод

Check if a value is empty, excluding 0 (annoying PHP issue)
public isEmpty ( mixed $value ) : boolean
$value mixed
Результат boolean

loadClass() публичный статический Метод

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

logQuery() публичный статический Метод

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

migrate() публичный Метод

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

primaryKey() публичный Метод

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

primaryKeyField() публичный Метод

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

query() публичный Метод

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() публичный Метод

Get query class name to use
public queryClass ( ) : string
Результат string

queryCount() публичный Метод

Get count of all queries that have been executed
public queryCount ( ) : integer
Результат integer

relations() публичный Метод

Get defined relations
public relations ( )

save() публичный Метод

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() защищенный Метод

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

select() публичный Метод

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() публичный Метод

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

update() публичный Метод

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

validate() публичный Метод

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

Описание свойств

$_adapter защищенное свойство

Stored adapter connections
protected $_adapter

$_adapterRead защищенное свойство

protected $_adapterRead

$_collectionClass защищенное свойство

protected $_collectionClass

$_datasource защищенное свойство

Data source setup info
protected $_datasource

$_entityClass защищенное свойство

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

$_errors защищенное свойство

Array of error messages and types
protected $_errors

$_exceptionClass защищенное свойство

protected $_exceptionClass

$_fields защищенное свойство

Store cached field info
protected $_fields

$_primaryKey защищенное свойство

protected $_primaryKey

$_queryClass защищенное свойство

protected $_queryClass

$_queryLog защищенное статическое свойство

Query log
protected static $_queryLog

$_relations защищенное свойство

protected $_relations