Describes the methods that any class representing a data storage should comply with.
mixed
Alias for commonly used primary key.
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
Returns an array with the requested fields stored in this entity, indexed by field name
Returns an array with the requested original fields stored in this entity, indexed by field name.
Returns an array with only the original fields stored in this entity, indexed by field name.
Returns the value of a field by name
Accessible configuration for this entity.
Gets the dirty fields.
Returns validation errors of a field
Returns all validation errors.
Gets the hidden fields.
Returns the original value of a field.
Gets all original values of the entity.
Returns the alias of the repository from which this entity came from.
Gets the virtual fields on this entity.
Get the list of visible fields.
Returns whether this entity contains a field named $field and is not set to null.
Returns whether this entity has errors.
Checks if a field is accessible
Checks if the entity is dirty or if a single field of it is dirty.
Returns whether this entity has already been persisted.
Sets one or multiple fields to the specified value
Stores whether a field value can be changed or set in this entity.
Sets the dirty status of a single field.
Sets errors for a single field
Sets error messages to the entity
Sets hidden fields.
Set the status of this entity.
Sets the source alias
Sets the virtual fields on this entity.
Returns an array with all the visible fields set in this entity.
Removes a field or list of fields from this entity
clean(): void
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
void
extract(array<string> $fields, bool $onlyDirty = false): array
Returns an array with the requested fields stored in this entity, indexed by field name
array<string>
$fields list of fields to be returned
bool
$onlyDirty optional Return the requested field only if it is dirty
array
extractOriginal(array<string> $fields): array
Returns an array with the requested original fields stored in this entity, indexed by field name.
array<string>
$fields List of fields to be returned
array
extractOriginalChanged(array<string> $fields): array
Returns an array with only the original fields stored in this entity, indexed by field name.
array<string>
$fields List of fields to be returned
array
get(string $field): mixed
Returns the value of a field by name
string
$field the name of the field to retrieve
mixed
getAccessible(): bool[]
Accessible configuration for this entity.
bool[]
getDirty(): array<string>
Gets the dirty fields.
array<string>
getError(string $field): array
Returns validation errors of a field
string
$field Field name to get the errors from
array
getErrors(): array
Returns all validation errors.
array
getHidden(): array<string>
Gets the hidden fields.
array<string>
getOriginal(string $field): mixed
Returns the original value of a field.
string
$field The name of the field.
mixed
getOriginalValues(): array
Gets all original values of the entity.
array
getSource(): string
Returns the alias of the repository from which this entity came from.
string
getVirtual(): array<string>
Gets the virtual fields on this entity.
array<string>
getVisible(): array<string>
Get the list of visible fields.
array<string>
has(array<string>|string $field): bool
Returns whether this entity contains a field named $field and is not set to null.
array<string>|string
$field The field to check.
bool
hasErrors(bool $includeNested = true): bool
Returns whether this entity has errors.
bool
$includeNested optional true will check nested entities for hasErrors()
bool
isAccessible(string $field): bool
Checks if a field is accessible
string
$field Field name to check
bool
isDirty(string|null $field = null): bool
Checks if the entity is dirty or if a single field of it is dirty.
string|null
$field optional The field to check the status for. Null for the whole entity.
bool
isNew(): bool
Returns whether this entity has already been persisted.
bool
set(array<string, mixed>|string $field, mixed $value = null, array<string, mixed> $options = []): $this
Sets one or multiple fields to the specified value
array<string, mixed>|string
$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<string, mixed>
$options optional Options to be used for setting the field. Allowed option keys are setter
and guard
$this
setAccess(array<string>|string $field, bool $set): $this
Stores whether a field value can be changed or set in this entity.
array<string>|string
$field single or list of fields to change its accessibility
bool
$set true marks the field as accessible, false will mark it as protected.
$this
setDirty(string $field, bool $isDirty = true): $this
Sets the dirty status of a single field.
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.
$this
setError(string $field, array|string $errors, bool $overwrite = false): $this
Sets errors for a single field
string
$field The field to get errors for, or the array of errors to set.
array|string
$errors The errors to be set for $field
bool
$overwrite optional Whether to overwrite pre-existing errors for $field
$this
setErrors(array $errors, bool $overwrite = false): $this
Sets error messages to the entity
array
$errors The array of errors to set.
bool
$overwrite optional Whether to overwrite pre-existing errors for $fields
$this
setHidden(array<string> $fields, bool $merge = false): $this
Sets hidden fields.
array<string>
$fields An array of fields to hide from array exports.
bool
$merge optional Merge the new fields with the existing. By default false.
$this
setNew(bool $new): $this
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.
bool
$new Indicate whether this entity has been persisted.
$this
setSource(string $alias): $this
Sets the source alias
string
$alias the alias of the repository
$this
setVirtual(array<string> $fields, bool $merge = false): $this
Sets the virtual fields on this entity.
array<string>
$fields An array of fields to treat as virtual.
bool
$merge optional Merge the new fields with the existing. By default false.
$this
toArray(): array
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().
array
unset(array<string>|string $field): $this
Removes a field or list of fields from this entity
array<string>|string
$field The field to unset.
$this
Alias for commonly used primary key.
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.4/interface-Cake.Datasource.EntityInterface.html