PHP 클래스 Mongolid\DataMapper\DataMapper

The DataMapper will always use a Schema trough the SchemaMapper to parse the document in and out of the database.
상속: implements Mongolid\Schema\HasSchemaInterface
파일 보기 프로젝트 열기: leroy-merlin-br/mongolid 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$schemaClass string Name of the schema class to be used.

보호된 프로퍼티들

프로퍼티 타입 설명
$assembler EntityAssembler Have the responsibility of assembling the data coming from the database into actual entities.
$connPool Mongolid\Connection\Pool Connections that are going to be used to interact with the database.
$eventService Mongolid\Event\EventTriggerService In order to dispatch events when necessary.
$schema Mongolid\Schema\Schema Schema object. Will be set after the $schemaClass.

공개 메소드들

메소드 설명
__construct ( Pool $connPool )
all ( ) : Cursor Retrieve a database cursor that will return all documents as $this->schema->entityClass objects upon iteration.
delete ( mixed $entity, array $options = [] ) : boolean Removes the given document from the collection.
first ( mixed $query = [], array $projection = [], boolean $cacheable = false ) : mixed Retrieve one $this->schema->entityClass objects that matches the given query.
firstOrFail ( mixed $query = [], array $projection = [], boolean $cacheable = false ) : mixed Retrieve one $this->schema->entityClass objects that matches the given query. If no document was found, throws ModelNotFoundException.
getSchema ( ) : Schema
insert ( mixed $entity, array $options = [], boolean $fireEvents = true ) : boolean Inserts the given object into database. Returns success if write concern is acknowledged. Since it's an insert, it will fail if the _id already exists.
save ( mixed $entity, array $options = [] ) : boolean Upserts the given object into database. Returns success if write concern is acknowledged.
setSchema ( Schema $schema ) Set a Schema object that describes an Entity in MongoDB.
update ( mixed $entity, array $options = [] ) : boolean Updates the given object into database. Returns success if write concern is acknowledged. Since it's an update, it will fail if the document with the given _id did not exists.
where ( mixed $query = [], array $projection = [], boolean $cacheable = false ) : Cursor Retrieve a database cursor that will return $this->schema->entityClass objects that upon iteration.

보호된 메소드들

메소드 설명
fireEvent ( string $event, mixed $entity, boolean $halt = false ) : mixed Triggers an event. May return if that event had success.
getAssembler ( ) : EntityAssembler Retrieves an EntityAssembler instance.
getCollection ( ) : MongoDB\Collection Retrieves the Collection object.
getSchemaMapper ( ) : SchemaMapper Returns a SchemaMapper with the $schema or $schemaClass instance.
parseToDocument ( mixed $entity ) : array Parses an object with SchemaMapper and the given Schema.
prepareArrayFieldOfQuery ( array $value ) : array Prepares an embedded array of an query. It will convert string ObjectIDs in operators into actual objects.
prepareProjection ( array $fields ) : array Converts the given projection fields to Mongo driver format.
prepareValueQuery ( mixed $value ) : array Transforms a value that is not an array into an MongoDB query (array).

비공개 메소드들

메소드 설명
afterSuccess ( mixed $entity ) Perform actions on object before firing the after event.
mergeOptions ( array $defaultOptions = [], array $toMergeOptions = [] ) : array Merge all options.

메소드 상세

__construct() 공개 메소드

public __construct ( Pool $connPool )
$connPool Mongolid\Connection\Pool The connections that are going to be used to interact with the database.

all() 공개 메소드

Retrieve a database cursor that will return all documents as $this->schema->entityClass objects upon iteration.
public all ( ) : Cursor
리턴 Mongolid\Cursor\Cursor

delete() 공개 메소드

Notice: Deletes with Unacknowledged WriteConcern will not fire deleted event.
public delete ( mixed $entity, array $options = [] ) : boolean
$entity mixed The entity used in the operation.
$options array Possible options to send to mongo driver.
리턴 boolean Success (but always false if write concern is Unacknowledged)

fireEvent() 보호된 메소드

Triggers an event. May return if that event had success.
protected fireEvent ( string $event, mixed $entity, boolean $halt = false ) : mixed
$event string Identification of the event.
$entity mixed Event payload.
$halt boolean True if the return of the event handler will be used in a conditional.
리턴 mixed Event handler return.

first() 공개 메소드

Retrieve one $this->schema->entityClass objects that matches the given query.
public first ( mixed $query = [], array $projection = [], boolean $cacheable = false ) : mixed
$query mixed MongoDB query to retrieve the document.
$projection array Fields to project in Mongo query.
$cacheable boolean Retrieves the first through a CacheableCursor.
리턴 mixed First document matching query as an $this->schema->entityClass object

firstOrFail() 공개 메소드

Retrieve one $this->schema->entityClass objects that matches the given query. If no document was found, throws ModelNotFoundException.
public firstOrFail ( mixed $query = [], array $projection = [], boolean $cacheable = false ) : mixed
$query mixed MongoDB query to retrieve the document.
$projection array Fields to project in Mongo query.
$cacheable boolean Retrieves the first through a CacheableCursor.
리턴 mixed First document matching query as an $this->schema->entityClass object

getAssembler() 보호된 메소드

Retrieves an EntityAssembler instance.
protected getAssembler ( ) : EntityAssembler
리턴 EntityAssembler

getCollection() 보호된 메소드

Retrieves the Collection object.
protected getCollection ( ) : MongoDB\Collection
리턴 MongoDB\Collection

getSchema() 공개 메소드

public getSchema ( ) : Schema
리턴 Mongolid\Schema\Schema

getSchemaMapper() 보호된 메소드

Returns a SchemaMapper with the $schema or $schemaClass instance.
protected getSchemaMapper ( ) : SchemaMapper
리턴 SchemaMapper

insert() 공개 메소드

Notice: Inserts with Unacknowledged WriteConcern will not fire inserted event.
public insert ( mixed $entity, array $options = [], boolean $fireEvents = true ) : boolean
$entity mixed The entity used in the operation.
$options array Possible options to send to mongo driver.
$fireEvents boolean Whether events should be fired.
리턴 boolean Success (but always false if write concern is Unacknowledged)

parseToDocument() 보호된 메소드

Parses an object with SchemaMapper and the given Schema.
protected parseToDocument ( mixed $entity ) : array
$entity mixed The object to be parsed.
리턴 array Document

prepareArrayFieldOfQuery() 보호된 메소드

Prepares an embedded array of an query. It will convert string ObjectIDs in operators into actual objects.
protected prepareArrayFieldOfQuery ( array $value ) : array
$value array Array that will be treated.
리턴 array Prepared array.

prepareProjection() 보호된 메소드

How to use: As Mongo projection using boolean values: From: ['name' => true, '_id' => false] To: ['name' => true, '_id' => false] As Mongo projection using integer values From: ['name' => 1, '_id' => -1] To: ['name' => true, '_id' => false] As an array of string: From: ['name', '_id'] To: ['name' => true, '_id' => true] As an array of string to exclude some fields: From: ['name', '-_id'] To: ['name' => true, '_id' => false]
protected prepareProjection ( array $fields ) : array
$fields array Fields to project.
리턴 array

prepareValueQuery() 보호된 메소드

This method will take care of converting a single value into a query for an _id, including when a objectId is passed as a string.
protected prepareValueQuery ( mixed $value ) : array
$value mixed The _id of the document.
리턴 array Query for the given _id

save() 공개 메소드

Notice: Saves with Unacknowledged WriteConcern will not fire saved event.
public save ( mixed $entity, array $options = [] ) : boolean
$entity mixed The entity used in the operation.
$options array Possible options to send to mongo driver.
리턴 boolean Success (but always false if write concern is Unacknowledged)

setSchema() 공개 메소드

Set a Schema object that describes an Entity in MongoDB.
public setSchema ( Schema $schema )
$schema Mongolid\Schema\Schema

update() 공개 메소드

Notice: Updates with Unacknowledged WriteConcern will not fire updated event.
public update ( mixed $entity, array $options = [] ) : boolean
$entity mixed The entity used in the operation.
$options array Possible options to send to mongo driver.
리턴 boolean Success (but always false if write concern is Unacknowledged)

where() 공개 메소드

Retrieve a database cursor that will return $this->schema->entityClass objects that upon iteration.
public where ( mixed $query = [], array $projection = [], boolean $cacheable = false ) : Cursor
$query mixed MongoDB query to retrieve documents.
$projection array Fields to project in Mongo query.
$cacheable boolean Retrieves a CacheableCursor instead.
리턴 Mongolid\Cursor\Cursor

프로퍼티 상세

$assembler 보호되어 있는 프로퍼티

Have the responsibility of assembling the data coming from the database into actual entities.
protected EntityAssembler,Mongolid\DataMapper $assembler
리턴 EntityAssembler

$connPool 보호되어 있는 프로퍼티

Connections that are going to be used to interact with the database.
protected Pool,Mongolid\Connection $connPool
리턴 Mongolid\Connection\Pool

$eventService 보호되어 있는 프로퍼티

In order to dispatch events when necessary.
protected EventTriggerService,Mongolid\Event $eventService
리턴 Mongolid\Event\EventTriggerService

$schema 보호되어 있는 프로퍼티

Schema object. Will be set after the $schemaClass.
protected Schema,Mongolid\Schema $schema
리턴 Mongolid\Schema\Schema

$schemaClass 공개적으로 프로퍼티

Name of the schema class to be used.
public string $schemaClass
리턴 string