Fr3nch13/CakePHP Utilities

EntityInterface extends ArrayAccess, JsonSerializable

Describes the methods that any class representing a data storage should comply with.

Table of Contents

Methods

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
extract()  : array<string|int, mixed>
Returns an array with the requested fields stored in this entity, indexed by field name
extractOriginal()  : array<string|int, mixed>
Returns an array with the requested original fields stored in this entity, indexed by field name.
extractOriginalChanged()  : array<string|int, mixed>
Returns an array with only the original fields stored in this entity, indexed by field name.
get()  : mixed
Returns the value of a field by name
getDirty()  : array<string|int, string>
Gets the dirty fields.
getError()  : array<string|int, mixed>
Returns validation errors of a field
getErrors()  : array<string|int, mixed>
Returns all validation errors.
getHidden()  : array<string|int, string>
Gets the hidden fields.
getOriginal()  : mixed
Returns the original value of a field.
getOriginalValues()  : array<string|int, mixed>
Gets all original values of the entity.
getSource()  : string
Returns the alias of the repository from which this entity came from.
getVirtual()  : array<string|int, string>
Gets the virtual fields on this entity.
getVisible()  : array<string|int, string>
Get the list of visible fields.
has()  : bool
Returns whether this entity contains a field named $field and is not set to null.
hasErrors()  : bool
Returns whether this entity has errors.
isAccessible()  : bool
Checks if a field is accessible
isDirty()  : bool
Checks if the entity is dirty or if a single field of it is dirty.
isNew()  : bool
Returns whether this entity has already been persisted.
set()  : $this
Sets one or multiple fields to the specified value
setAccess()  : $this
Stores whether a field value can be changed or set in this entity.
setDirty()  : $this
Sets the dirty status of a single field.
setError()  : $this
Sets errors for a single field
setErrors()  : $this
Sets error messages to the entity
setHidden()  : $this
Sets hidden fields.
setNew()  : $this
Set the status of this entity.
setSource()  : $this
Sets the source alias
setVirtual()  : $this
Sets the virtual fields on this entity.
toArray()  : array<string|int, mixed>
Returns an array with all the visible fields set in this entity.
unset()  : $this
Removes a field or list of fields from this entity

Methods

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

public clean() : void

extract()

Returns an array with the requested fields stored in this entity, indexed by field name

public extract(array<string|int, string> $fields[, bool $onlyDirty = false ]) : array<string|int, mixed>
Parameters
$fields : array<string|int, string>

list of fields to be returned

$onlyDirty : bool = false

Return the requested field only if it is dirty

Return values
array<string|int, mixed>

extractOriginal()

Returns an array with the requested original fields stored in this entity, indexed by field name.

public extractOriginal(array<string|int, string> $fields) : array<string|int, mixed>
Parameters
$fields : array<string|int, string>

List of fields to be returned

Return values
array<string|int, mixed>

extractOriginalChanged()

Returns an array with only the original fields stored in this entity, indexed by field name.

public extractOriginalChanged(array<string|int, string> $fields) : array<string|int, mixed>
Parameters
$fields : array<string|int, string>

List of fields to be returned

Return values
array<string|int, mixed>

get()

Returns the value of a field by name

public & get(string $field) : mixed
Parameters
$field : string

the name of the field to retrieve

getDirty()

Gets the dirty fields.

public getDirty() : array<string|int, string>
Return values
array<string|int, string>

getError()

Returns validation errors of a field

public getError(string $field) : array<string|int, mixed>
Parameters
$field : string

Field name to get the errors from

Return values
array<string|int, mixed>

getErrors()

Returns all validation errors.

public getErrors() : array<string|int, mixed>
Return values
array<string|int, mixed>

getHidden()

Gets the hidden fields.

public getHidden() : array<string|int, string>
Return values
array<string|int, string>

getOriginal()

Returns the original value of a field.

public getOriginal(string $field) : mixed
Parameters
$field : string

The name of the field.

getOriginalValues()

Gets all original values of the entity.

public getOriginalValues() : array<string|int, mixed>
Return values
array<string|int, mixed>

getSource()

Returns the alias of the repository from which this entity came from.

public getSource() : string
Return values
string

getVirtual()

Gets the virtual fields on this entity.

public getVirtual() : array<string|int, string>
Return values
array<string|int, string>

getVisible()

Get the list of visible fields.

public getVisible() : array<string|int, string>
Return values
array<string|int, string>

A list of fields that are 'visible' in all representations.

has()

Returns whether this entity contains a field named $field and is not set to null.

public has(array<string|int, string>|string $field) : bool
Parameters
$field : array<string|int, string>|string

The field to check.

Return values
bool

hasErrors()

Returns whether this entity has errors.

public hasErrors([bool $includeNested = true ]) : bool
Parameters
$includeNested : bool = true

true will check nested entities for hasErrors()

Return values
bool

isAccessible()

Checks if a field is accessible

public isAccessible(string $field) : bool
Parameters
$field : string

Field name to check

Return values
bool

isDirty()

Checks if the entity is dirty or if a single field of it is dirty.

public isDirty([string|null $field = null ]) : bool
Parameters
$field : string|null = null

The field to check the status for. Null for the whole entity.

Return values
bool

Whether the field was changed or not

isNew()

Returns whether this entity has already been persisted.

public isNew() : bool
Return values
bool

Whether the entity has been persisted.

set()

Sets one or multiple fields to the specified value

public set(array<string, mixed>|string $field[, mixed $value = null ][, array<string, mixed> $options = [] ]) : $this
Parameters
$field : array<string, mixed>|string

the name of field to set or a list of fields with their respective values

$value : mixed = null

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

$options : array<string, mixed> = []

Options to be used for setting the field. Allowed option keys are setter and guard

Return values
$this

setAccess()

Stores whether a field value can be changed or set in this entity.

public setAccess(array<string|int, string>|string $field, bool $set) : $this
Parameters
$field : array<string|int, string>|string

single or list of fields to change its accessibility

$set : bool

true marks the field as accessible, false will mark it as protected.

Return values
$this

setDirty()

Sets the dirty status of a single field.

public setDirty(string $field[, bool $isDirty = true ]) : $this
Parameters
$field : string

the field to set or check status for

$isDirty : bool = true

true means the field was changed, false means it was not changed. Default true.

Return values
$this

setError()

Sets errors for a single field

public setError(string $field, array<string|int, mixed>|string $errors[, bool $overwrite = false ]) : $this
Parameters
$field : string

The field to get errors for, or the array of errors to set.

$errors : array<string|int, mixed>|string

The errors to be set for $field

$overwrite : bool = false

Whether to overwrite pre-existing errors for $field

Return values
$this

setErrors()

Sets error messages to the entity

public setErrors(array<string|int, mixed> $errors[, bool $overwrite = false ]) : $this
Parameters
$errors : array<string|int, mixed>

The array of errors to set.

$overwrite : bool = false

Whether to overwrite pre-existing errors for $fields

Return values
$this

setHidden()

Sets hidden fields.

public setHidden(array<string|int, string> $fields[, bool $merge = false ]) : $this
Parameters
$fields : array<string|int, string>

An array of fields to hide from array exports.

$merge : bool = false

Merge the new fields with the existing. By default false.

Return values
$this

setNew()

Set the status of this entity.

public setNew(bool $new) : $this

Using true means that the entity has not been persisted in the database, false indicates that the entity has been persisted.

Parameters
$new : bool

Indicate whether this entity has been persisted.

Return values
$this

setSource()

Sets the source alias

public setSource(string $alias) : $this
Parameters
$alias : string

the alias of the repository

Return values
$this

setVirtual()

Sets the virtual fields on this entity.

public setVirtual(array<string|int, string> $fields[, bool $merge = false ]) : $this
Parameters
$fields : array<string|int, string>

An array of fields to treat as virtual.

$merge : bool = false

Merge the new fields with the existing. By default false.

Return values
$this

toArray()

Returns an array with all the visible fields set in this entity.

public toArray() : array<string|int, mixed>

Note hidden fields are not visible, and will not be output by toArray().

Return values
array<string|int, mixed>

unset()

Removes a field or list of fields from this entity

public unset(array<string|int, string>|string $field) : $this
Parameters
$field : array<string|int, string>|string

The field to unset.

Return values
$this

        
On this page

Search results