Class Marshaller
Contains logic to convert array data into document objects.
Useful when converting request data into documents.
Property Summary
-
$index protected
Cake\ElasticSearch\Index
Index instance this marshaller is for.
Method Summary
-
__construct() public
Constructor
-
_prepareDataAndOptions() protected
Returns data and options prepared to validate and marshall.
-
_validate() protected
Returns the validation errors for a data set based on the passed options
-
createAndHydrate() protected
Creates and Hydrates Document whilst honouring accessibleFields etc
-
many() public
Hydrate a collection of entities.
-
merge() public
Merges
$data
into$document
. -
mergeMany() public
Update a collection of entities.
-
mergeNested() protected
Merge an embedded document.
-
newNested() protected
Marshal an embedded document.
-
one() public
Hydrate a single document.
Method Detail
__construct() ¶ public
__construct(Cake\ElasticSearch\Index $index)
Constructor
Parameters
-
Cake\ElasticSearch\Index
$index The index instance this marshaller is for.
_prepareDataAndOptions() ¶ protected
_prepareDataAndOptions(array $data, array $options): array
Returns data and options prepared to validate and marshall.
Parameters
-
array
$data The data to prepare.
-
array
$options The options passed to this marshaller.
Returns
array
_validate() ¶ protected
_validate(array $data, array $options, bool $isNew): array
Returns the validation errors for a data set based on the passed options
Parameters
-
array
$data The data to validate.
-
array
$options The options passed to this marshaller.
-
bool
$isNew Whether it is a new entity or one to be updated.
Returns
array
Throws
RuntimeException
If no validator can be created.
createAndHydrate() ¶ protected
createAndHydrate(string $class, array $data, array $options = [], string $indexClass = null): Cake\ElasticSearch\Document
Creates and Hydrates Document whilst honouring accessibleFields etc
Parameters
-
string
$class Class name of Document to create
-
array
$data The data to hydrate with
-
array
$options optional Options to control the hydration
-
string
$indexClass optional Index class to get embeds from (for nesting)
Returns
Cake\ElasticSearch\Document
many() ¶ public
many(array $data, array $options = []): array
Hydrate a collection of entities.
Options:
- fieldList: A whitelist of fields to be assigned to the entity. If not present, the accessible fields list in the entity will be used.
- accessibleFields: A list of fields to allow or deny in entity accessible fields.
Parameters
-
array
$data A list of entity data you want converted into objects.
-
array
$options optional Options
Returns
array
merge() ¶ public
merge(Cake\Datasource\EntityInterface $entity, array $data, array $options = []): Cake\Datasource\EntityInterface
Merges $data
into $document
.
Options:
- fieldList: A whitelist of fields to be assigned to the entity. If not present the accessible fields list in the entity will be used.
- associated: A list of embedded documents you want to marshal.
Parameters
-
Cake\Datasource\EntityInterface
$entity the entity that will get the data merged in
-
array
$data key value list of fields to be merged into the entity
-
array
$options optional List of options.
Returns
Cake\Datasource\EntityInterface
mergeMany() ¶ public
mergeMany(iterable $entities, array $data, array $options = []): array
Update a collection of entities.
Merges each of the elements from $data
into each of the entities in $entities
.
Records in $data
are matched against the entities using the id field.
Entries in $entities
that cannot be matched to any record in
$data
will be discarded. Records in $data
that could not be matched will
be marshalled as a new entity.
Options:
- fieldList: A whitelist of fields to be assigned to the entity. If not present, the accessible fields list in the entity will be used.
Parameters
-
iterable
$entities An array of Elasticsearch entities
-
array
$data A list of entity data you want converted into objects.
-
array
$options optional Options
Returns
array
mergeNested() ¶ protected
mergeNested(Cake\ElasticSearch\Association\Embedded $embed, Cake\ElasticSearch\Document|array $existing, array $data): Cake\ElasticSearch\Document|array
Merge an embedded document.
Parameters
-
Cake\ElasticSearch\Association\Embedded
$embed The embed definition.
-
Cake\ElasticSearch\Document|array
$existing The existing entity or entities.
-
array
$data The data to marshal
Returns
Cake\ElasticSearch\Document|array
newNested() ¶ protected
newNested(Cake\ElasticSearch\Association\Embedded $embed, array $data, array $options = []): Cake\ElasticSearch\Document|array
Marshal an embedded document.
Parameters
-
Cake\ElasticSearch\Association\Embedded
$embed The embed definition.
-
array
$data The data to marshal
-
array
$options optional The options to pass on
Returns
Cake\ElasticSearch\Document|array
one() ¶ public
one(array $data, array $options = []): Cake\ElasticSearch\Document
Hydrate a single document.
Options:
- fieldList: A whitelist of fields to be assigned to the entity. If not present, the accessible fields list in the entity will be used.
- accessibleFields: A list of fields to allow or deny in entity accessible fields.
- associated: A list of embedded documents you want to marshal.
Parameters
-
array
$data The data to hydrate.
-
array
$options optional List of options
Returns
Cake\ElasticSearch\Document