PHP 클래스 Spot\Mapper

상속: use trait Spot\Di\InjectableTrait
파일 보기 프로젝트 열기: vlucas/spot2 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$_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