Interface EntityInterface
Describes the methods that any class representing a data storage should comply with.
In 4.x the following methods will officially be added to the interface:
Property Summary
-
$id public @property
mixed
Alias for commonly used primary key.
Method Summary
-
accessible() public deprecated
Stores whether or not a property value can be changed or set in this entity. The special property
*
can also be marked as accessible or protected, meaning that any other property specified before will take its value. For example$entity->accessible('*', true)
means that any property not specified already will be accessible by default. -
clean() public
Sets the entire entity as clean, which means that it will appear as no properties being modified or added at all. This is an useful call for an initial object hydration
-
dirty() public deprecated
Sets the dirty status of a single property. If called with no second argument, it will return whether the property was modified or not after the object creation.
-
errors() public deprecated
Sets the error messages for a field or a list of fields. When called without the second argument it returns the validation errors for the specified fields. If called with no arguments it returns all the validation error messages stored in this entity.
-
extract() public
Returns an array with the requested properties stored in this entity, indexed by property name
-
extractOriginal() public @method
-
extractOriginalChanged() public @method
-
get() public
Returns the value of a property by name
-
getDirty() public @method
-
getError() public @method
-
getErrors() public @method
-
getHidden() public @method
-
getSource() public @method
-
getVirtual() public @method
-
getVisible() public @method
-
has() public
Returns whether this entity contains a property named $property regardless of if it is empty.
-
hasErrors() public @method
-
hiddenProperties() public
Get/Set the hidden properties on this entity.
-
isAccessible() public @method
-
isDirty() public @method
-
isNew() public
Returns whether or not this entity has already been persisted. This method can return null in the case there is no prior information on the status of this entity.
-
set() public
Sets one or multiple properties to the specified value
-
setAccess() public @method
-
setDirty() public @method
-
setError() public @method
-
setErrors() public @method
-
setHidden() public @method
-
setSource() public @method
-
setVirtual() public @method
-
toArray() public
Returns an array with all the visible properties set in this entity.
-
unsetProperty() public
Removes a property or list of properties from this entity
-
virtualProperties() public
Get/Set the virtual properties on this entity.
-
visibleProperties() public
Get the list of visible properties.
Method Detail
accessible() ¶ public
accessible(string|array $property, bool|null $set = null): Cake\Datasource\EntityInterface|bool
Stores whether or not a property value can be changed or set in this entity.
The special property *
can also be marked as accessible or protected, meaning
that any other property specified before will take its value. For example
$entity->accessible('*', true)
means that any property not specified already
will be accessible by default.
Parameters
-
string|array
$property Either a single or list of properties to change its accessibility.
-
bool|null
$set optional true marks the property as accessible, false will mark it as protected.
Returns
Cake\Datasource\EntityInterface|bool
clean() ¶ public
clean(): void
Sets the entire entity as clean, which means that it will appear as no properties being modified or added at all. This is an useful call for an initial object hydration
Returns
void
dirty() ¶ public
dirty(string|null $property = null, bool|null $isDirty = null): bool
Sets the dirty status of a single property. If called with no second argument, it will return whether the property was modified or not after the object creation.
When called with no arguments it will return whether or not there are any dirty property in the entity
Parameters
-
string|null
$property optional the field to set or check status for
-
bool|null
$isDirty optional true means the property was changed, false means it was not changed and null will make the function return current state for that property
Returns
bool
errors() ¶ public
errors(string|array|null $field = null, string|array|null $errors = null, bool $overwrite = false): arrayCake\Datasource\EntityInterface
Sets the error messages for a field or a list of fields. When called without the second argument it returns the validation errors for the specified fields. If called with no arguments it returns all the validation error messages stored in this entity.
When used as a setter, this method will return this entity instance for method chaining.
Parameters
-
string|array|null
$field optional The field to get errors for.
-
string|array|null
$errors optional The errors to be set for $field
-
bool
$overwrite optional Whether or not to overwrite pre-existing errors for $field
Returns
arrayCake\Datasource\EntityInterface
extract() ¶ public
extract(array $properties, bool $onlyDirty = false): array
Returns an array with the requested properties stored in this entity, indexed by property name
Parameters
-
array
$properties list of properties to be returned
-
bool
$onlyDirty optional Return the requested property only if it is dirty
Returns
array
extractOriginal() ¶ public @method
extractOriginal(array $properties): array
Parameters
-
array
$properties
Returns
array
extractOriginalChanged() ¶ public @method
extractOriginalChanged(array $properties): array
Parameters
-
array
$properties
Returns
array
get() ¶ public
get(string $property): mixed
Returns the value of a property by name
Parameters
-
string
$property the name of the property to retrieve
Returns
mixed
has() ¶ public
has(string|array $property): bool
Returns whether this entity contains a property named $property regardless of if it is empty.
Parameters
-
string|array
$property The property to check.
Returns
bool
hasErrors() ¶ public @method
hasErrors(mixed $includeNested = true): bool
Parameters
-
$includeNested optional
Returns
bool
hiddenProperties() ¶ public
hiddenProperties(array|null $properties = null): arrayCake\Datasource\EntityInterface
Get/Set the hidden properties on this entity.
If the properties argument is null, the currently hidden properties will be returned. Otherwise the hidden properties will be set.
Parameters
-
array|null
$properties optional Either an array of properties to hide or null to get properties
Returns
arrayCake\Datasource\EntityInterface
isAccessible() ¶ public @method
isAccessible(mixed $property): bool
Parameters
-
$property
Returns
bool
isDirty() ¶ public @method
isDirty(mixed $property = null): bool
Parameters
-
$property optional
Returns
bool
isNew() ¶ public
isNew(bool|null $new = null): bool
Returns whether or not this entity has already been persisted. This method can return null in the case there is no prior information on the status of this entity.
If called with a boolean, this method will set the status of this instance.
Using true
means that the instance has not been persisted in the database, false
that it already is.
Parameters
-
bool|null
$new optional Indicate whether or not this instance has been persisted.
Returns
bool
set() ¶ public
set(string|array $property, mixed $value = null, array $options = []): Cake\Datasource\EntityInterface
Sets one or multiple properties to the specified value
Parameters
-
string|array
$property the name of property to set or a list of properties with their respective values
-
mixed
$value optional The value to set to the property 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 property. Allowed option keys are
setter
andguard
Returns
Cake\Datasource\EntityInterface
setAccess() ¶ public @method
setAccess(mixed $property, mixed $set): $this
Parameters
-
$property
-
$set
Returns
$this
setDirty() ¶ public @method
setDirty(mixed $property, mixed $isDirty = true): $this
Parameters
-
$property
-
$isDirty optional
Returns
$this
setError() ¶ public @method
setError(mixed $field, mixed $errors, mixed $overwrite = false): array
Parameters
-
$field
-
$errors
-
$overwrite optional
Returns
array
setErrors() ¶ public @method
setErrors(array $fields, mixed $overwrite = false): array
Parameters
-
array
$fields -
$overwrite optional
Returns
array
setHidden() ¶ public @method
setHidden(array $properties, mixed $merge = false): $this
Parameters
-
array
$properties -
$merge optional
Returns
$this
setVirtual() ¶ public @method
setVirtual(array $properties, mixed $merge = false): $this
Parameters
-
array
$properties -
$merge optional
Returns
$this
toArray() ¶ public
toArray(): array
Returns an array with all the visible properties set in this entity.
Note hidden properties are not visible, and will not be output by toArray().
Returns
array
unsetProperty() ¶ public
unsetProperty(string|array $property): Cake\Datasource\EntityInterface
Removes a property or list of properties from this entity
Parameters
-
string|array
$property The property to unset.
Returns
Cake\Datasource\EntityInterface
virtualProperties() ¶ public
virtualProperties(array|null $properties = null): arrayCake\Datasource\EntityInterface
Get/Set the virtual properties on this entity.
If the properties argument is null, the currently virtual properties will be returned. Otherwise the virtual properties will be set.
Parameters
-
array|null
$properties optional Either an array of properties to treat as virtual or null to get properties
Returns
arrayCake\Datasource\EntityInterface
visibleProperties() ¶ public
visibleProperties(): array
Get the list of visible properties.
Returns
array