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
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$schemaClass string Name of the schema class to be used.

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

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