Interface EntityInterface
Describes the methods that any class representing a data storage should comply with.
Properties summary
- $id public
mixed
Alias for commonly used primary key.
Method Summary
- clean() public
Sets the entire entity as clean, which means that it will appear as no fields being modified or added at all. This is an useful call for an initial object hydration
- extract() public
Returns an array with the requested fields stored in this entity, indexed by field name
- extractOriginal() public
Returns an array with the requested original fields stored in this entity, indexed by field name.
- extractOriginalChanged() public
Returns an array with only the original fields stored in this entity, indexed by field name.
- has() public
Returns whether this entity contains a field named $field regardless of if it is empty.
Method Detail
clean() public
clean()
Sets the entire entity as clean, which means that it will appear as no fields being modified or added at all. This is an useful call for an initial object hydration
extract() public
extract(array $fields, bool $onlyDirty)
Returns an array with the requested fields stored in this entity, indexed by field name
Parameters
-
string[]
$fields list of fields to be returned
-
bool
$onlyDirty optional Return the requested field only if it is dirty
Returns
array
extractOriginal() public
extractOriginal(array $fields)
Returns an array with the requested original fields stored in this entity, indexed by field name.
Parameters
-
string[]
$fields List of fields to be returned
Returns
array
extractOriginalChanged() public
extractOriginalChanged(array $fields)
Returns an array with only the original fields stored in this entity, indexed by field name.
Parameters
-
string[]
$fields List of fields to be returned
Returns
array
get() public
get(string $field)
Returns the value of a field by name
Parameters
-
string
$field the name of the field to retrieve
Returns
mixed
getDirty() public
getDirty()
Gets the dirty fields.
Returns
string[]
getError() public
getError(string $field)
Returns validation errors of a field
Parameters
-
string
$field Field name to get the errors from
Returns
array
getErrors() public
getErrors()
Returns all validation errors.
Returns
array
getHidden() public
getHidden()
Gets the hidden fields.
Returns
string[]
getOriginal() public
getOriginal(string $field)
Returns the original value of a field.
Parameters
-
string
$field The name of the field.
Returns
mixed
getOriginalValues() public
getOriginalValues()
Gets all original values of the entity.
Returns
array
getSource() public
getSource()
Returns the alias of the repository from which this entity came from.
Returns
string
getVirtual() public
getVirtual()
Gets the virtual fields on this entity.
Returns
string[]
getVisible() public
getVisible()
Get the list of visible fields.
Returns
string[]
A list of fields that are 'visible' in all representations.
has() public
has(mixed $field)
Returns whether this entity contains a field named $field regardless of if it is empty.
Parameters
-
string|string[]
$field The field to check.
Returns
bool
hasErrors() public
hasErrors(bool $includeNested)
Returns whether this entity has errors.
Parameters
-
bool
$includeNested optional true will check nested entities for hasErrors()
Returns
bool
isAccessible() public
isAccessible(string $field)
Checks if a field is accessible
Parameters
-
string
$field Field name to check
Returns
bool
isDirty() public
isDirty(?string $field)
Checks if the entity is dirty or if a single field of it is dirty.
Parameters
-
string|null
$field optional The field to check the status for. Null for the whole entity.
Returns
bool
Whether the field was changed or not
isNew() public
isNew()
Returns whether or not this entity has already been persisted.
Returns
bool
Whether or not the entity has been persisted.
set() public
set(mixed $field, mixed $value, array $options)
Sets one or multiple fields to the specified value
Parameters
-
string|array
$field the name of field to set or a list of fields with their respective values
-
mixed
$value optional The value to set to the field or an array if the first argument is also an array, in which case will be treated as $options
-
array
$options optional options to be used for setting the field. Allowed option keys are
setter
andguard
Returns
$this
setAccess() public
setAccess(mixed $field, bool $set)
Stores whether or not a field value can be changed or set in this entity.
Parameters
-
string|array
$field single or list of fields to change its accessibility
-
bool
$set true marks the field as accessible, false will mark it as protected.
Returns
$this
setDirty() public
setDirty(string $field, bool $isDirty)
Sets the dirty status of a single field.
Parameters
-
string
$field the field to set or check status for
-
bool
$isDirty optional true means the field was changed, false means it was not changed. Default true.
Returns
$this
setError() public
setError(string $field, mixed $errors, bool $overwrite)
Sets errors for a single field
Parameters
-
string
$field The field to get errors for, or the array of errors to set.
-
string|array
$errors The errors to be set for $field
-
bool
$overwrite optional Whether or not to overwrite pre-existing errors for $field
Returns
$this
setErrors() public
setErrors(array $errors, bool $overwrite)
Sets error messages to the entity
Parameters
-
array
$errors The array of errors to set.
-
bool
$overwrite optional Whether or not to overwrite pre-existing errors for $fields
Returns
$this
setHidden() public
setHidden(array $fields, bool $merge)
Sets hidden fields.
Parameters
-
string[]
$fields An array of fields to hide from array exports.
-
bool
$merge optional Merge the new fields with the existing. By default false.
Returns
$this
setNew() public
setNew(bool $new)
Set the status of this entity.
Using true
means that the entity has not been persisted in the database, false
indicates that the entity has been persisted.
Parameters
-
bool
$new Indicate whether or not this entity has been persisted.
Returns
$this
setSource() public
setSource(string $alias)
Sets the source alias
Parameters
-
string
$alias the alias of the repository
Returns
$this
setVirtual() public
setVirtual(array $fields, bool $merge)
Sets the virtual fields on this entity.
Parameters
-
string[]
$fields An array of fields to treat as virtual.
-
bool
$merge optional Merge the new fields with the existing. By default false.
Returns
$this
toArray() public
toArray()
Returns an array with all the visible fields set in this entity.
Note hidden fields are not visible, and will not be output by toArray().
Returns
array
unset() public
unset(mixed $field)
Removes a field or list of fields from this entity
Parameters
-
string|string[]
$field The field to unset.
Returns
$this
Property Detail
$id public
Alias for commonly used primary key.
Type
mixed
© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/4.0/interface-Cake.Datasource.EntityInterface.html