Interface EntityInterface
Describes the methods that any class representing a data storage should comply with.
Property Summary
- 
        $id public @propertymixedAlias for commonly used primary key. 
Method Summary
- 
          clean() publicSets 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() publicReturns an array with the requested fields stored in this entity, indexed by field name 
- 
          extractOriginal() publicReturns an array with the requested original fields stored in this entity, indexed by field name. 
- 
          extractOriginalChanged() publicReturns an array with only the original fields stored in this entity, indexed by field name. 
- 
          get() publicReturns the value of a field by name 
- 
          getAccessible() publicAccessible configuration for this entity. 
- 
          getDirty() publicGets the dirty fields. 
- 
          getError() publicReturns validation errors of a field 
- 
          getErrors() publicReturns all validation errors. 
- 
          getHidden() publicGets the hidden fields. 
- 
          getOriginal() publicReturns the original value of a field. 
- 
          getOriginalFields() publicReturns an array of original fields. Original fields are those that an entity was initialized with. 
- 
          getOriginalValues() publicGets all original values of the entity. 
- 
          getSource() publicReturns the alias of the repository from which this entity came from. 
- 
          getVirtual() publicGets the virtual fields on this entity. 
- 
          getVisible() publicGet the list of visible fields. 
- 
          has() publicReturns whether this entity contains a field named $field. 
- 
          hasErrors() publicReturns whether this entity has errors. 
- 
          hasOriginal() publicReturns whether a field has an original value 
- 
          hasValue() public @method
- 
          isAccessible() publicChecks if a field is accessible 
- 
          isDirty() publicChecks if the entity is dirty or if a single field of it is dirty. 
- 
          isNew() publicReturns whether this entity has already been persisted. 
- 
          isOriginalField() publicReturns whether a field is an original one. Original fields are those that an entity was instantiated with. 
- 
          requireFieldPresence() publicEnable/disable field presence check when accessing a property. 
- 
          set() publicSets one or multiple fields to the specified value 
- 
          setAccess() publicStores whether a field value can be changed or set in this entity. 
- 
          setDirty() publicSets the dirty status of a single field. 
- 
          setError() publicSets errors for a single field 
- 
          setErrors() publicSets error messages to the entity 
- 
          setHidden() publicSets hidden fields. 
- 
          setNew() publicSet the status of this entity. 
- 
          setSource() publicSets the source alias 
- 
          setVirtual() publicSets the virtual fields on this entity. 
- 
          toArray() publicReturns an array with all the visible fields set in this entity. 
- 
          unset() publicRemoves a field or list of fields from this entity 
Method Detail
clean() ¶ public
clean(): voidSets 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
voidextract() ¶ public
extract(list<string> $fields, bool $onlyDirty = false): array<string, mixed>Returns an array with the requested fields stored in this entity, indexed by field name
Parameters
- 
                list<string>$fields
- list of fields to be returned 
- 
                bool$onlyDirty optional
- Return the requested field only if it is dirty 
Returns
array<string, mixed>extractOriginal() ¶ public
extractOriginal(list<string> $fields): array<string, mixed>Returns an array with the requested original fields stored in this entity, indexed by field name.
Parameters
- 
                list<string>$fields
- List of fields to be returned 
Returns
array<string, mixed>extractOriginalChanged() ¶ public
extractOriginalChanged(list<string> $fields): array<string, mixed>Returns an array with only the original fields stored in this entity, indexed by field name.
Parameters
- 
                list<string>$fields
- List of fields to be returned 
Returns
array<string, mixed>get() ¶ public
get(string $field): mixedReturns the value of a field by name
Parameters
- 
                string$field
- the name of the field to retrieve 
Returns
mixedgetAccessible() ¶ public
getAccessible(): array<bool>Accessible configuration for this entity.
Returns
array<bool>getError() ¶ public
getError(string $field): arrayReturns validation errors of a field
Parameters
- 
                string$field
- Field name to get the errors from 
Returns
arraygetOriginal() ¶ public
getOriginal(string $field, bool $allowFallback = true): mixedReturns the original value of a field.
Parameters
- 
                string$field
- The name of the field. 
- 
                bool$allowFallback optional
- whether to allow falling back to the current field value if no original exists 
Returns
mixedgetOriginalFields() ¶ public
getOriginalFields(): array<string>Returns an array of original fields. Original fields are those that an entity was initialized with.
Returns
array<string>getOriginalValues() ¶ public
getOriginalValues(): arrayGets all original values of the entity.
Returns
arraygetSource() ¶ public
getSource(): stringReturns the alias of the repository from which this entity came from.
Returns
stringgetVirtual() ¶ public
getVirtual(): array<string>Gets the virtual fields on this entity.
Returns
array<string>getVisible() ¶ public
getVisible(): array<string>Get the list of visible fields.
Returns
array<string>A list of fields that are 'visible' in all representations.
has() ¶ public
has(array<string>|string $field): boolReturns whether this entity contains a field named $field.
The method will return true even when the field is set to null.
Parameters
- 
                array<string>|string$field
- The field to check. 
Returns
boolhasErrors() ¶ public
hasErrors(bool $includeNested = true): boolReturns whether this entity has errors.
Parameters
- 
                bool$includeNested optional
- true will check nested entities for hasErrors() 
Returns
boolhasOriginal() ¶ public
hasOriginal(string $field): boolReturns whether a field has an original value
Parameters
- 
                string$field
Returns
boolisAccessible() ¶ public
isAccessible(string $field): boolChecks if a field is accessible
Parameters
- 
                string$field
- Field name to check 
Returns
boolisDirty() ¶ public
isDirty(string|null $field = null): boolChecks 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
boolWhether the field was changed or not
isNew() ¶ public
isNew(): boolReturns whether this entity has already been persisted.
Returns
boolWhether the entity has been persisted.
isOriginalField() ¶ public
isOriginalField(string $name): boolReturns whether a field is an original one. Original fields are those that an entity was instantiated with.
Parameters
- 
                string$name
Returns
boolrequireFieldPresence() ¶ public
requireFieldPresence(bool $value = true): voidEnable/disable field presence check when accessing a property.
If enabled an exception will be thrown when trying to access a non-existent property.
Parameters
- 
                bool$value optional
- trueto enable,- falseto disable.
Returns
voidset() ¶ public
set(array<string, mixed>|string $field, mixed $value = null, array<string, mixed> $options = []): $thisSets one or multiple fields to the specified value
Parameters
- 
                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 - setterand- guard
Returns
$thissetAccess() ¶ public
setAccess(array<string>|string $field, bool $set): $thisStores whether a field value can be changed or set in this entity.
Parameters
- 
                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. 
Returns
$thissetDirty() ¶ public
setDirty(string $field, bool $isDirty = true): $thisSets 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
$thissetError() ¶ public
setError(string $field, array|string $errors, bool $overwrite = false): $thisSets errors for a single field
Parameters
- 
                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 
Returns
$thissetErrors() ¶ public
setErrors(array $errors, bool $overwrite = false): $thisSets error messages to the entity
Parameters
- 
                array$errors
- The array of errors to set. 
- 
                bool$overwrite optional
- Whether to overwrite pre-existing errors for $fields 
Returns
$thissetHidden() ¶ public
setHidden(list<string> $fields, bool $merge = false): $thisSets hidden fields.
Parameters
- 
                list<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
$thissetNew() ¶ public
setNew(bool $new): $thisSet 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 this entity has been persisted. 
Returns
$thissetSource() ¶ public
setSource(string $alias): $thisSets the source alias
Parameters
- 
                string$alias
- the alias of the repository 
Returns
$thissetVirtual() ¶ public
setVirtual(list<string> $fields, bool $merge = false): $thisSets the virtual fields on this entity.
Parameters
- 
                list<string>$fields
- An array of fields to treat as virtual. 
- 
                bool$merge optional
- Merge the new fields with the existing. By default false. 
Returns
$thistoArray() ¶ public
toArray(): arrayReturns 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
arrayunset() ¶ public
unset(array<string>|string $field): $thisRemoves a field or list of fields from this entity
Parameters
- 
                array<string>|string$field
- The field to unset. 
Returns
$this