PHP Class Mongolid\Model\DocumentEmbedder

Datei anzeigen Open project: leroy-merlin-br/mongolid

Public Methods

Method Description
attach ( mixed $parent, string $field, object | array &$entity ) : boolean Attach a new _id reference into $field of $parent.
detach ( mixed $parent, string $field, mixed &$entity ) : boolean Removes an _id reference from $field of $parent.
embed ( mixed $parent, string $field, mixed &$entity ) : boolean Embeds the given $entity into $field of $parent. This method will also consider the _id of the $entity in order to update it if it is already present in $field.
unembed ( mixed $parent, string $field, mixed &$entity ) : boolean Removes the given $entity from $field of $parent. This method will consider the _id of the $entity in order to remove it.

Protected Methods

Method Description
getId ( mixed &$object ) : MongoDB\BSON\ObjectID | mixed Gets the _id of the given object or array. If there is no _id in it a new _id will be generated and set on the object (while still returning it).

Method Details

attach() public method

Attach a new _id reference into $field of $parent.
public attach ( mixed $parent, string $field, object | array &$entity ) : boolean
$parent mixed The object where $entity will be referenced.
$field string The field where the _id reference of $entity will be stored.
$entity object | array The object that is being attached.
return boolean Success

detach() public method

Removes an _id reference from $field of $parent.
public detach ( mixed $parent, string $field, mixed &$entity ) : boolean
$parent mixed The object where $entity reference will be removed.
$field string The field where the _id reference of $entity is stored.
$entity mixed The object being detached or its _id.
return boolean Success

embed() public method

Embeds the given $entity into $field of $parent. This method will also consider the _id of the $entity in order to update it if it is already present in $field.
public embed ( mixed $parent, string $field, mixed &$entity ) : boolean
$parent mixed The object where the $entity will be embedded.
$field string Name of the field of the object where the document will be embedded.
$entity mixed Entity that will be embedded within $parent.
return boolean Success

getId() protected method

Gets the _id of the given object or array. If there is no _id in it a new _id will be generated and set on the object (while still returning it).
protected getId ( mixed &$object ) : MongoDB\BSON\ObjectID | mixed
$object mixed The object|array that the _id will be retrieved from.
return MongoDB\BSON\ObjectID | mixed

unembed() public method

Removes the given $entity from $field of $parent. This method will consider the _id of the $entity in order to remove it.
public unembed ( mixed $parent, string $field, mixed &$entity ) : boolean
$parent mixed The object where the $entity will be removed.
$field string Name of the field of the object where the document is.
$entity mixed Entity that will be removed from $parent.
return boolean Success