PHP Класс Spot\Mapper

Наследование: use trait Spot\Di\InjectableTrait
Показать файл Открыть проект Примеры использования класса

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

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

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

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

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

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

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

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

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

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

Find all records
public all ( ) : Query
Результат Query

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

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

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
Результат object Instance of $entityClass with $data set on it

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

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

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

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

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

Get config class from locator
public config ( ) : Config
Результат Config

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

Get connection to use
public connection ( string $connectionName = null ) : Doctrine\DBAL\Connection
$connectionName string Named connection or entity class name
Результат Doctrine\DBAL\Connection

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

Test to see if collection is of the given type
public connectionIs ( $type ) : boolean
Результат boolean

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

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
Результат array

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

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
Результат array

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

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()
Результат object Instance of $entityClass with $data set on it

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

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

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

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

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

Get name of the Entity class mapper was instantiated with
public entity ( ) : string
Результат string $entityName

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

Entity manager class for storing information and meta-data about entities
public entityManager ( ) : Manager
Результат Spot\Entity\Manager

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

Event emitter for this mapper
public eventEmitter ( ) : Spot\EventEmitter
Результат Spot\EventEmitter

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

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

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

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

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

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

Return field type
public fieldType ( string $field ) : mixed
$field string Field name
Результат mixed Field type string or boolean false

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

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

Get field information exactly how it is defined in the class
public fieldsDefined ( ) : 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() публичный Метод

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
Результат mixed Depends on input false If $identifier is scalar and no entity exists

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

Get mapper for specified entity
public getMapper ( string $entityName ) : Mapper
$entityName string Name of Entity object to load mapper for
Результат Mapper

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

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

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

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

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

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

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

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

Reset and load Events for mapped entity
public loadEvents ( )

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

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

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

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

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

Prepare entity and load necessary objects on it
public prepareEntity ( EntityInterface $entity ) : boolean | null
$entity EntityInterface
Результат boolean | null

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

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

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

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

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

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
Результат Query

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

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

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

Get defined relations
public relations ( )

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

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

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

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

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
Результат mixed

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

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
Результат mixed

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

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
Результат array Array of closures with method name as the key

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 = "*" ) : Query
$fields mixed String for single field or array of fields
Результат Query

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

Get table name
public table ( ) : string
Результат string Name of table defined on entity class

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

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

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

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

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

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

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

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
Результат object Instance of $entityClass with $data set on it

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

Run set validation rules on fields
public validate ( EntityInterface $entity, array $options = [] ) : boolean
$entity EntityInterface
$options array
Результат boolean

validateRelatedEntity() защищенный Метод

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
Результат array Related entity errors

validateRelations() защищенный Метод

Validate related entities using relations
protected validateRelations ( EntityInterface $entity ) : EntityInterface
$entity EntityInterface
Результат EntityInterface

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

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
Результат Query

with() защищенный Метод

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

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

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

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

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

Array of hooks
protected $_hooks

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

protected $_queryClass

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

Entity manager
protected static $entityManager

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

protected $entityName

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

protected static $eventEmitter

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

protected $locator

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

Temporary relations
protected $withRelations