PHP Class Mongolid\DataMapper\DataMapper

The DataMapper will always use a Schema trough the SchemaMapper to parse the document in and out of the database.
Inheritance: implements Mongolid\Schema\HasSchemaInterface
Afficher le fichier Open project: leroy-merlin-br/mongolid Class Usage Examples

Méthodes publiques

Свойство Type Description
$schemaClass string Name of the schema class to be used.

Protected Properties

Свойство Type Description
$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.

Méthodes publiques

Méthode Description
__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.

Méthodes protégées

Méthode Description
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).

Private Methods

Méthode Description
afterSuccess ( mixed $entity ) Perform actions on object before firing the after event.
mergeOptions ( array $defaultOptions = [], array $toMergeOptions = [] ) : array Merge all options.

Method Details

__construct() public méthode

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

all() public méthode

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

delete() public méthode

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.
Résultat boolean Success (but always false if write concern is Unacknowledged)

fireEvent() protected méthode

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.
Résultat mixed Event handler return.

first() public méthode

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.
Résultat mixed First document matching query as an $this->schema->entityClass object

firstOrFail() public méthode

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.
Résultat mixed First document matching query as an $this->schema->entityClass object

getAssembler() protected méthode

Retrieves an EntityAssembler instance.
protected getAssembler ( ) : EntityAssembler
Résultat EntityAssembler

getCollection() protected méthode

Retrieves the Collection object.
protected getCollection ( ) : MongoDB\Collection
Résultat MongoDB\Collection

getSchema() public méthode

public getSchema ( ) : Schema
Résultat Mongolid\Schema\Schema

getSchemaMapper() protected méthode

Returns a SchemaMapper with the $schema or $schemaClass instance.
protected getSchemaMapper ( ) : SchemaMapper
Résultat SchemaMapper

insert() public méthode

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.
Résultat boolean Success (but always false if write concern is Unacknowledged)

parseToDocument() protected méthode

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

prepareArrayFieldOfQuery() protected méthode

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.
Résultat array Prepared array.

prepareProjection() protected méthode

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.
Résultat array

prepareValueQuery() protected méthode

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.
Résultat array Query for the given _id

save() public méthode

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.
Résultat boolean Success (but always false if write concern is Unacknowledged)

setSchema() public méthode

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

update() public méthode

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.
Résultat boolean Success (but always false if write concern is Unacknowledged)

where() public méthode

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.
Résultat Mongolid\Cursor\Cursor

Property Details

$assembler protected_oe property

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

$connPool protected_oe property

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

$eventService protected_oe property

In order to dispatch events when necessary.
protected EventTriggerService,Mongolid\Event $eventService
Résultat Mongolid\Event\EventTriggerService

$schema protected_oe property

Schema object. Will be set after the $schemaClass.
protected Schema,Mongolid\Schema $schema
Résultat Mongolid\Schema\Schema

$schemaClass public_oe property

Name of the schema class to be used.
public string $schemaClass
Résultat string