CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 3.0 Red Velvet API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 3.0
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Global
  • Cake
    • Auth
    • Cache
    • Collection
    • Console
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Filesystem
    • Form
    • I18n
    • Log
    • Network
    • ORM
      • Association
      • Behavior
      • Exception
      • Rule
    • Routing
    • Shell
    • TestSuite
    • Utility
    • Validation
    • View

Class Marshaller

Contains logic to convert array data into entities.

Useful when converting request data into entities.

Namespace: Cake\ORM
See: \Cake\ORM\Table::newEntity()
See: \Cake\ORM\Table::newEntities()
See: \Cake\ORM\Table::patchEntity()
See: \Cake\ORM\Table::patchEntities()

Property Summary

  • $_table protected
    Cake\ORM\Table

    The table instance this marshaller is for.

Method Summary

  • __construct() public

    Constructor.

  • _belongsToMany() protected

    Marshals data for belongsToMany associations.

  • _buildPropertyMap() protected

    Build the map of property => association names.

  • _loadAssociatedByIds() protected

    Loads a list of belongs to many from ids.

  • _loadBelongsToMany() protected deprecated

    Loads a list of belongs to many from ids.

  • _marshalAssociation() protected

    Create a new sub-marshaller and marshal the associated data.

  • _mergeAssociation() protected

    Creates a new sub-marshaller and merges the associated data.

  • _mergeBelongsToMany() protected

    Creates a new sub-marshaller and merges the associated data for a BelongstoMany association.

  • _mergeJoinData() protected

    Merge the special _joinData property into the entity set.

  • _normalizeAssociations() protected

    Returns an array out of the original passed associations list where dot notation is transformed into nested arrays so that they can be parsed by other routines

  • _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

  • many() public

    Hydrate many entities and their associated data.

  • merge() public

    Merges $data into $entity and recursively does the same for each one of the association names passed in $options. When merging associations, if an entity is not present in the parent entity for a given association, a new one will be created.

  • mergeMany() public

    Merges each of the elements from $data into each of the entities in $entities and recursively does the same for each of the association names passed in $options. When merging associations, if an entity is not present in the parent entity for a given association, a new one will be created.

  • one() public

    Hydrate one entity and its associated data.

Method Detail

__construct() ¶ public

__construct(Cake\ORM\Table $table)

Constructor.

Parameters
Cake\ORM\Table $table

The table this marshaller is for.

_belongsToMany() ¶ protected

_belongsToMany(Association $assoc, array $data, array $options = []): array

Marshals data for belongsToMany associations.

Builds the related entities and handles the special casing for junction table entities.

Parameters
Association $assoc

The association to marshal.

array $data

The data to convert into entities.

array $options optional

List of options.

Returns
array

_buildPropertyMap() ¶ protected

_buildPropertyMap(array $options): array

Build the map of property => association names.

Parameters
array $options

List of options containing the 'associated' key.

Returns
array

_loadAssociatedByIds() ¶ protected

_loadAssociatedByIds(Association $assoc, array $ids): array

Loads a list of belongs to many from ids.

Parameters
Association $assoc

The association class for the belongsToMany association.

array $ids

The list of ids to load.

Returns
array

_loadBelongsToMany() ¶ protected

_loadBelongsToMany(Association $assoc, array $ids): array

Loads a list of belongs to many from ids.

Parameters
Association $assoc

The association class for the belongsToMany association.

array $ids

The list of ids to load.

Returns
array

_marshalAssociation() ¶ protected

_marshalAssociation(Cake\ORM\Association $assoc, array $value, array $options): mixed

Create a new sub-marshaller and marshal the associated data.

Parameters
Cake\ORM\Association $assoc

The association to marshall

array $value

The data to hydrate

array $options

List of options.

Returns
mixed

_mergeAssociation() ¶ protected

_mergeAssociation(Cake\Datasource\EntityInterface $original, Cake\ORM\Association $assoc, array $value, array $options): mixed

Creates a new sub-marshaller and merges the associated data.

Parameters
Cake\Datasource\EntityInterface $original

The original entity

Cake\ORM\Association $assoc

The association to merge

array $value

The data to hydrate

array $options

List of options.

Returns
mixed

_mergeBelongsToMany() ¶ protected

_mergeBelongsToMany(Cake\Datasource\EntityInterface $original, Cake\ORM\Association $assoc, array $value, array $options): array

Creates a new sub-marshaller and merges the associated data for a BelongstoMany association.

Parameters
Cake\Datasource\EntityInterface $original

The original entity

Cake\ORM\Association $assoc

The association to marshall

array $value

The data to hydrate

array $options

List of options.

Returns
array

_mergeJoinData() ¶ protected

_mergeJoinData(Cake\Datasource\EntityInterface $original, Cake\ORM\Association $assoc, array $value, array $options): array

Merge the special _joinData property into the entity set.

Parameters
Cake\Datasource\EntityInterface $original

The original entity

Cake\ORM\Association $assoc

The association to marshall

array $value

The data to hydrate

array $options

List of options.

Returns
array

_normalizeAssociations() ¶ protected

_normalizeAssociations(array $associations): array

Returns an array out of the original passed associations list where dot notation is transformed into nested arrays so that they can be parsed by other routines

Parameters
array $associations

The array of included associations.

Returns
array

_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.

many() ¶ public

many(array $data, array $options = []): array

Hydrate many entities and their associated data.

Options:

  • associated: Associations listed here will be marshalled as well.
  • 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

The data to hydrate.

array $options optional

List of options

Returns
array
See Also
\Cake\ORM\Table::newEntities()

merge() ¶ public

merge(Cake\Datasource\EntityInterface $entity, array $data, array $options = []): Cake\Datasource\EntityInterface

Merges $data into $entity and recursively does the same for each one of the association names passed in $options. When merging associations, if an entity is not present in the parent entity for a given association, a new one will be created.

When merging HasMany or BelongsToMany associations, all the entities in the $data array will appear, those that can be matched by primary key will get the data merged, but those that cannot, will be discarded.

Options:

  • associated: Associations listed here will be marshalled as well.
  • validate: Whether or not to validate data before hydrating the entities. Can also be set to a string to use a specific validator. Defaults to true/default.
  • 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
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(array|Traversable $entities, array $data, array $options = []): array

Merges each of the elements from $data into each of the entities in $entities and recursively does the same for each of the association names passed in $options. When merging associations, if an entity is not present in the parent entity for a given association, a new one will be created.

Records in $data are matched against the entities using the primary key column. 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.

When merging HasMany or BelongsToMany associations, all the entities in the $data array will appear, those that can be matched by primary key will get the data merged, but those that cannot, will be discarded.

Options:

  • associated: Associations listed here will be marshalled as well.
  • 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|Traversable $entities

the entities that will get the data merged in

array $data

list of arrays to be merged into the entities

array $options optional

List of options.

Returns
array

one() ¶ public

one(array $data, array $options = []): Cake\ORM\Entity

Hydrate one entity and its associated data.

Options:

  • associated: Associations listed here will be marshalled as well.
  • 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

The data to hydrate.

array $options optional

List of options

Returns
Cake\ORM\Entity
See Also
\Cake\ORM\Table::newEntity()

Property Detail

$_table ¶ protected

The table instance this marshaller is for.

Type
Cake\ORM\Table
OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs