PHP Class Spot\Mapper

Inheritance: use trait Spot\Di\InjectableTrait
Afficher le fichier Open project: vlucas/spot2 Class Usage Examples

Protected Properties

Свойство Type Description
$_collectionClass Class Names for required classes - Here so they can be easily overridden
$_hooks Array of hooks
$_queryClass
$entityManager Entity manager
$entityName
$eventEmitter
$locator
$withRelations Temporary relations

Méthodes publiques

Méthode Description
__construct ( spot\Locator $locator, $entityName ) Constructor Method
all ( ) : Query Find all records
belongsTo ( EntityInterface $entity, $foreignEntity, $localKey ) Relation: BelongsTo
build ( array $data ) : object Get a new entity object, set given data on it
collection ( $cursor, $with = [] ) Create collection from Spot\Query object
collectionClass ( ) : string Get collection class name to use
config ( ) : Config Get config class from locator
connection ( string $connectionName = null ) : Doctrine\DBAL\Connection Get connection to use
connectionIs ( $type ) : boolean Test to see if collection is of the given type
convertToDatabaseValues ( string $entityName, array $data ) : array Prepare data to be dumped to the data store
convertToPHPValues ( string $entityName, array $data ) : array Retrieve data from the data store and map it to PHP values
create ( array $data, array $options = [] ) : object Get a new entity object, set given data on it, and save it
delete ( mixed $conditions = [] ) Delete items matching given conditions
dropTable ( ) Drop/delete table Destructive and dangerous - drops entire data source and all data
entity ( ) : string Get name of the Entity class mapper was instantiated with
entityManager ( ) : Manager Entity manager class for storing information and meta-data about entities
eventEmitter ( ) : Spot\EventEmitter Event emitter for this mapper
exec ( string $sql, array $params = [] ) Execute custom query with no handling - just return affected rows Useful for UPDATE, DELETE, and INSERT queries
fieldExists ( string $field ) Check if field exists in defined fields
fieldInfo ( string $field ) Check if field exists in defined fields
fieldType ( string $field ) : mixed Return field type
fields ( ) : array Get formatted fields with all neccesary array keys and values.
fieldsDefined ( ) : array Get field information exactly how it is defined in the class
first ( array $conditions = [] ) Find first record matching given conditions
get ( mixed $identifier = false ) : mixed Get a new entity object, or an existing entity from identifiers
getMapper ( string $entityName ) : Mapper Get mapper for specified entity
hasMany ( EntityInterface $entity, $entityName, $foreignKey, $localValue = null ) Relation: HasMany
hasManyThrough ( EntityInterface $entity, $hasManyEntity, $throughEntity, $selectField, $whereField ) Relation: HasManyThrough
hasOne ( EntityInterface $entity, $foreignEntity, $foreignKey ) Relation: HasOne
insert ( mixed $entity, array $options = [] ) Insert record
loadEvents ( ) Reset and load Events for mapped entity
loadRelations ( EntityInterface $entity ) Load Relations for mapped entity
migrate ( ) Migrate table structure changes from model to database
prepareEntity ( EntityInterface $entity ) : boolean | null Prepare entity and load necessary objects on it
primaryKey ( EntityInterface $entity ) Get value of primary key for given row result
primaryKeyField ( ) Get value of primary key for given row result
query ( string $sql, array $params = [] ) Find records with custom query
queryBuilder ( ) : Query Begin a new database query - get query builder Acts as a kind of factory to get the current adapter's query builder object
queryClass ( ) : string Get query class name to use
relations ( ) Get defined relations
resolver ( ) Query resolver class for perparing and executing queries, then returning the results
save ( EntityInterface $entity, array $options = [] ) Save record Will update if primary key found, insert if not Performs validation automatically before saving record
saveBelongsToRelations ( EntityInterface $entity, array $options = [] ) : mixed Save related entities that have been assigned or loaded (only BelongsTo relations) See saveHasRelations.
saveHasRelations ( EntityInterface $entity, array $options = [] ) : mixed Save related entities that have been assigned or loaded (only HasOne, HasMany and HasManyThrough relations) See saveBelongsToRelations.
scopes ( ) : array Return scopes defined by this mapper. Scopes are called from the Spot\Query object as a sort of in-context dynamic query method
select ( mixed $fields = "*" ) : Query Begin a new database query - get query builder Acts as a kind of factory to get the current adapter's query builder object
table ( ) : string Get table name
transaction ( Closure $work, $entityName = null ) Transaction with closure
truncateTable ( $cascade = false ) Truncate table Should delete all rows and reset serial/auto_increment keys
update ( EntityInterface $entity, array $options = [] ) Update given entity object
upsert ( array $data, array $where ) : object Upsert save entity - insert or update on duplicate key. Intended to be used in conjunction with fields that are marked 'unique'
validate ( EntityInterface $entity, array $options = [] ) : boolean Run set validation rules on fields
where ( array $conditions = [] ) : Query Find records with given conditions If all parameters are empty, find all records

Méthodes protégées

Méthode Description
validateRelatedEntity ( EntityInterface $relatedEntity, EntityInterface $entity, RelationAbstract $relation ) : array Validate related entity if it is new or modified only
validateRelations ( EntityInterface $entity ) : EntityInterface Validate related entities using relations
with ( $collection, $entityName, $with = [] ) Eager-load associations for an entire collection

Method Details

__construct() public méthode

Constructor Method
public __construct ( spot\Locator $locator, $entityName )
$locator spot\Locator

all() public méthode

Find all records
public all ( ) : Query
Résultat Query

belongsTo() public méthode

BelongsTo assumes that the localKey will reference the foreignEntity's primary key. If this is not the case, you probably want to use the 'hasOne' relationship instead.
public belongsTo ( EntityInterface $entity, $foreignEntity, $localKey )
$entity EntityInterface

build() public méthode

Get a new entity object, set given data on it
public build ( array $data ) : object
$data array array of key/values to set on new Entity instance
Résultat object Instance of $entityClass with $data set on it

collection() public méthode

Create collection from Spot\Query object
public collection ( $cursor, $with = [] )

collectionClass() public méthode

Get collection class name to use
public collectionClass ( ) : string
Résultat string

config() public méthode

Get config class from locator
public config ( ) : Config
Résultat Config

connection() public méthode

Get connection to use
public connection ( string $connectionName = null ) : Doctrine\DBAL\Connection
$connectionName string Named connection or entity class name
Résultat Doctrine\DBAL\Connection

connectionIs() public méthode

Test to see if collection is of the given type
public connectionIs ( $type ) : boolean
Résultat boolean

convertToDatabaseValues() public méthode

Prepare data to be dumped to the data store
public convertToDatabaseValues ( string $entityName, array $data ) : array
$entityName string
$data array Key/value pairs of data to store
Résultat array

convertToPHPValues() public méthode

Retrieve data from the data store and map it to PHP values
public convertToPHPValues ( string $entityName, array $data ) : array
$entityName string
$data array Key/value pairs of data to store
Résultat array

create() public méthode

Get a new entity object, set given data on it, and save it
public create ( array $data, array $options = [] ) : object
$data array array of key/values to set on new Entity instance
$options array array of save options that will be passed to insert()
Résultat object Instance of $entityClass with $data set on it

delete() public méthode

Delete items matching given conditions
public delete ( mixed $conditions = [] )
$conditions mixed Optional array of conditions in column => value pairs

dropTable() public méthode

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

entity() public méthode

Get name of the Entity class mapper was instantiated with
public entity ( ) : string
Résultat string $entityName

entityManager() public méthode

Entity manager class for storing information and meta-data about entities
public entityManager ( ) : Manager
Résultat Spot\Entity\Manager

eventEmitter() public méthode

Event emitter for this mapper
public eventEmitter ( ) : Spot\EventEmitter
Résultat Spot\EventEmitter

exec() public méthode

Execute custom query with no handling - just return affected rows Useful for UPDATE, DELETE, and INSERT queries
public exec ( string $sql, array $params = [] )
$sql string Raw query or SQL to run against the datastore
$params array

fieldExists() public méthode

Check if field exists in defined fields
public fieldExists ( string $field )
$field string Field name to check for existence

fieldInfo() public méthode

Check if field exists in defined fields
public fieldInfo ( string $field )
$field string Field name to check for existence

fieldType() public méthode

Return field type
public fieldType ( string $field ) : mixed
$field string Field name
Résultat mixed Field type string or boolean false

fields() public méthode

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

fieldsDefined() public méthode

Get field information exactly how it is defined in the class
public fieldsDefined ( ) : array
Résultat array Defined fields plus all defaults for full array of all possible options

first() public méthode

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

get() public méthode

Get a new entity object, or an existing entity from identifiers
public get ( mixed $identifier = false ) : mixed
$identifier mixed Primary key or array of key/values
Résultat mixed Depends on input false If $identifier is scalar and no entity exists

getMapper() public méthode

Get mapper for specified entity
public getMapper ( string $entityName ) : Mapper
$entityName string Name of Entity object to load mapper for
Résultat Mapper

hasMany() public méthode

Relation: HasMany
public hasMany ( EntityInterface $entity, $entityName, $foreignKey, $localValue = null )
$entity EntityInterface

hasManyThrough() public méthode

Relation: HasManyThrough
public hasManyThrough ( EntityInterface $entity, $hasManyEntity, $throughEntity, $selectField, $whereField )
$entity EntityInterface

hasOne() public méthode

HasOne assumes that the foreignKey will be on the foreignEntity.
public hasOne ( EntityInterface $entity, $foreignEntity, $foreignKey )
$entity EntityInterface

insert() public méthode

Insert record
public insert ( mixed $entity, array $options = [] )
$entity mixed Entity object or array of field => value pairs
$options array Array of adapter-specific options

loadEvents() public méthode

Reset and load Events for mapped entity
public loadEvents ( )

loadRelations() public méthode

Load Relations for mapped entity
public loadRelations ( EntityInterface $entity )
$entity EntityInterface

migrate() public méthode

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

prepareEntity() public méthode

Prepare entity and load necessary objects on it
public prepareEntity ( EntityInterface $entity ) : boolean | null
$entity EntityInterface
Résultat boolean | null

primaryKey() public méthode

Get value of primary key for given row result
public primaryKey ( EntityInterface $entity )
$entity EntityInterface Instance of an entity to find the primary key of

primaryKeyField() public méthode

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

query() public méthode

Find records with custom query
public query ( string $sql, array $params = [] )
$sql string Raw query or SQL to run against the datastore
$params array

queryBuilder() public méthode

Begin a new database query - get query builder Acts as a kind of factory to get the current adapter's query builder object
public queryBuilder ( ) : Query
Résultat Query

queryClass() public méthode

Get query class name to use
public queryClass ( ) : string
Résultat string

relations() public méthode

Get defined relations
public relations ( )

resolver() public méthode

Query resolver class for perparing and executing queries, then returning the results
public resolver ( )

save() public méthode

Save record Will update if primary key found, insert if not Performs validation automatically before saving record
public save ( EntityInterface $entity, array $options = [] )
$entity EntityInterface Entity object
$options array

saveBelongsToRelations() public méthode

Save related entities that have been assigned or loaded (only BelongsTo relations) See saveHasRelations.
public saveBelongsToRelations ( EntityInterface $entity, array $options = [] ) : mixed
$entity EntityInterface
$options array
Résultat mixed

saveHasRelations() public méthode

Save related entities that have been assigned or loaded (only HasOne, HasMany and HasManyThrough relations) See saveBelongsToRelations.
public saveHasRelations ( EntityInterface $entity, array $options = [] ) : mixed
$entity EntityInterface
$options array
Résultat mixed

scopes() public méthode

Return scopes defined by this mapper. Scopes are called from the Spot\Query object as a sort of in-context dynamic query method
public scopes ( ) : array
Résultat array Array of closures with method name as the key

select() public méthode

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 = "*" ) : Query
$fields mixed String for single field or array of fields
Résultat Query

table() public méthode

Get table name
public table ( ) : string
Résultat string Name of table defined on entity class

transaction() public méthode

Transaction with closure
public transaction ( Closure $work, $entityName = null )
$work Closure

truncateTable() public méthode

Truncate table Should delete all rows and reset serial/auto_increment keys
public truncateTable ( $cascade = false )

update() public méthode

Update given entity object
public update ( EntityInterface $entity, array $options = [] )
$entity EntityInterface Entity object
$options array

upsert() public méthode

Upsert save entity - insert or update on duplicate key. Intended to be used in conjunction with fields that are marked 'unique'
public upsert ( array $data, array $where ) : object
$data array array of key/values to set on new Entity instance
$where array array of keys to select record by for updating if it already exists
Résultat object Instance of $entityClass with $data set on it

validate() public méthode

Run set validation rules on fields
public validate ( EntityInterface $entity, array $options = [] ) : boolean
$entity EntityInterface
$options array
Résultat boolean

validateRelatedEntity() protected méthode

Validate related entity if it is new or modified only
protected validateRelatedEntity ( EntityInterface $relatedEntity, EntityInterface $entity, RelationAbstract $relation ) : array
$relatedEntity EntityInterface
$entity EntityInterface
$relation Spot\Relation\RelationAbstract
Résultat array Related entity errors

validateRelations() protected méthode

Validate related entities using relations
protected validateRelations ( EntityInterface $entity ) : EntityInterface
$entity EntityInterface
Résultat EntityInterface

where() public méthode

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

with() protected méthode

Eager-load associations for an entire collection
protected with ( $collection, $entityName, $with = [] )

Property Details

$_collectionClass protected_oe property

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

$_hooks protected_oe property

Array of hooks
protected $_hooks

$_queryClass protected_oe property

protected $_queryClass

$entityManager protected_oe static_oe property

Entity manager
protected static $entityManager

$entityName protected_oe property

protected $entityName

$eventEmitter protected_oe static_oe property

protected static $eventEmitter

$locator protected_oe property

protected $locator

$withRelations protected_oe property

Temporary relations
protected $withRelations