Index

aEntity

MMO\core\classes · 1 symbol · generated 5 Oct 2026

class

aEntity

aEntity.php:43

Base implementation of iEntity: a tArrayProperties-backed record with a lifecycle status (cStatus), change tracking, links, and repository integration. Every concrete entity (e.g.

#[MMO\core\attributes\ArrayProperty(name: 'uid', getter: 'uid', schema: […3 items])] #[MMO\core\attributes\ArrayProperty(name: 'metadata', getter: 'getMetadata', schema: […4 items])] abstract class MMO\core\classes\aEntity implements MMO\core\interfaces\iEntity use MMO\core\classes\tArrayProperties
Namespace
MMO\core\classes
Implements
iEntity
Uses traits
tArrayProperties
See
Entity) is built on this. Two read-only #[ArrayProperty]s are added at the class level (not tied to a real PHP property): 'uid' (from iIdentifiable::uid) and 'metadata' (from getMetadata) -- so every entity's toArray/store output includes them.
class Person extends Entity { #[ArrayProperty] protected string $name = ''; } $p = new Person(['name' => 'Marc']); $p->isCreated(); // true $p['name'] = 'Updated'; $p->isChanged(); // true $p->getChanges(); // ['name' => 'Updated']

Index

ArrayProperties static
changes
errors
flags
links
SearchProperties static
status
addFlags($flags)
addLink($link)Append a link.
archive()This function is called to 'delete' the entity.
ArrayProperties() staticBuild (once per class, then cached in the static $ArrayProperties array) the list of every #[ArrayProperty] declared on this class, its parent classes, and the traits they use -- by reflection…
ArrayProperty($name) static
CheckData($data, $errors) staticCheck data before it touches any entity: would an entity made from $data be valid?
clearChanges()Reset change tracking: clears iEntity::FLAG_CHANGED and forgets every recorded change.
compareTo($value)Compare value
conversionError($key, $e)The error recorded for a value that could not be set at all (usually: it could not be converted to its property's type), in the same form as a validation error.
debugName()
get($path, $default)Read a (possibly nested) value by json-path, e.g.
getArrayProperty($key, $isRef, $store)Read a single array property's current value, through its getter (a direct property, a path alias, or a method).
getChanges($asArray, $store)
getErrors()
getFlags()
getLabel()
getLinks()
getLinksByRel($rels, $all)Get a list of Reference that have a specific relationship.
getMetadata()
getStatus()
getTitle()
getView()
hasChanged($keys)
hasFlags($flags, $strict)
hasStatusChanged()
HiddenPath($path) staticThe hidden property (ArrayProperty::isHidden) a json-path goes through, known from the declared types alone: of this class, or of a class a property on the way may hold -- every class of its t…
ignoreChanges($value)Temporarily suppress markChanged (used e.g.
isActive()
isArchive()
isArrayPropertySet($key, $store)
isChanged()
isCreated()
isDraft()
isEmpty()
isFinal()
isHiddenPath($path)
isOpacified()
isPending()
isRemoved()
isSimilar($value)Compare entities using unique fields (@unique), to find if they represent the same entity
isUnique()Tells if an entity has enough information to be unique (at least one unique group has no null)
isValid()
isValidated()
ListClassReferences($onlyStorable) staticGet a list of all the classes and their properties that are using references to this class.
loadArray($data, $coerceOptions, $fromStore)Set every entry of $data as an array property, through setArrayProperty (so each value is coerced by its property's schema).
loadFromStore($data)Load $data as this entity's initial state (e.g.
markChanged($keys)Mark one or multiple key as changed
mutate($type, $path, $value, $oldValue)\MMO\core\interfaces\iMutationObserver::mutate -- besides the normal tArrayProperties::mutate behavior, walks up $path to find the nearest enclosing aEntity (the mutation may have happened dee…
offsetExists($key)\ArrayAccess::offsetExists -- tells whether $key is a *declared* #[ArrayProperty], not whether it currently holds a non-default value (use isArrayPropertySet for that).
offsetGet($key)\ArrayAccess::offsetGet
offsetSet($key, $value)\ArrayAccess::offsetSet
offsetUnset($key)\ArrayAccess::offsetUnset -- equivalent to setting the property to null (its coerced value depends on the property's schema: e.g.
opacify($value)Hide this entity's properties from toArray output (typically used to redact an entity the current viewer isn't allowed to see the details of, while still letting it be referenced by uid/metadata).
push($path, $value)Append a value to a (possibly nested) list property by json-path.
removeFlags($flags)
removeLink($link)Remove a link (by identity).
removePermanently()Remove this entity from the repository once MMO\commit() is called WARNING: This will permanently remove the entity.
Schema() staticThe JSON-Schema describing every #[ArrayProperty] of this class (built once and cached by ArrayProperties).
SearchProperty($name) static
set($path, $value)Write a (possibly nested) value by json-path, creating intermediate structure as needed.
setArrayProperty($key, $value, $coerceOptions, $ignoreReadonly)Same as tArrayProperties::setArrayProperty, plus: any coercion/validation failure is caught and recorded in getErrors (making the entity isValid()-false) instead of propagating as an…
setArrayPropertyOffset($key, $offset, $value, $coerceOptions)Same as tArrayProperties::setArrayPropertyOffset, plus: when pushing (offset === null) a new entity onto a list property, if an existing item is isSimilar to the new value, that item's of…
setLinks($links)Replace every link with $links.
setStatus($status)
store()Export all array properties with store set to true.
test($filter)
toArray($fields, $flatten, $recursive)Same as tArrayProperties::toArray, except an isOpacified entity always exports only its 'uid' and 'metadata' (its other properties are hidden from output).
toLink($attributes)
traitMutate($type, $path, $value, $oldValue)\MMO\core\interfaces\iMutationObserver::mutate -- reacts to a mutation that happened deep inside one of this object's array properties (e.g.
traitSetArrayProperty($key, $value, $coerceOptions, $fromStore)Set array property
traitSetArrayPropertyOffset($key, $offset, $value, $coerceOptions)Set/push a value into an array property
traitToArray($fields, $flatten, $recursive)Export fields to an array.
validate($errors)Validate this entity: its current values against its own tArrayProperties::Schema, plus every value that could not even be set -- one that could not be converted to its property's type never r…
View() static
__construct($data)

Properties7

ArrayProperties

static
#[MMO\core\attributes\Serialize(false)] static array $ArrayProperties = []
Type
array

changes

#[MMO\core\attributes\Serialize(false)] protected ?array $changes = null
Type
null | array

errors

#[MMO\core\attributes\Serialize(false)] protected array $errors = []
Type
array

flags

#[MMO\core\attributes\Serialize(false)] protected int $flags = 0
Type
int

SearchProperties

static
static array $SearchProperties = []
Type
array

status

#[MMO\core\attributes\ArrayProperty(setter: false, store: true)] protected MMO\core\entities\cStatus $status = MMO\core\entities\cStatus::ACTIVE
Type
cStatus

Methods75

addFlags($flags)

aEntity.php:688
function addFlags(int $flags): bool
$flagsinta bitmask of iEntity::FLAG_* to set
returnsbooltrue if any of $flags was not already set

archive()

aEntity.php:393

This function is called to 'delete' the entity.

function archive(): boolWE DON'T DELETE really the entity to prevent unresolvable reference. Repository controller SHOULD NEVER delete the entity but instead "archive" it.
returnsbooltrue if status became ARCHIVE

ArrayProperties()

statictArrayProperties.php:85

Build (once per class, then cached in the static $ArrayProperties array) the list of every #[ArrayProperty] declared on this class, its parent classes, and the traits they use -- by reflection over class- and property-level attributes. Also builds this class's Schema as a side effect. Called automatically by every other method in this trait: rarely called directly.

static function ArrayProperties(): array
returnsarray\MMO\core\attributes\ArrayProperty} name => ArrayProperty, in schema-sort order
throws
Person::ArrayProperties(); // ['name' => ArrayProperty(name: 'name', ...), 'age' => ArrayProperty(...)]

ArrayProperty($name)

statictArrayProperties.php:243
static function ArrayProperty(string $name): MMO\core\attributes\ArrayProperty
$namestring
returnsArrayPropertythe property's metadata (schema, getter, setter, ...)
throwsif $name is not a declared #[ArrayProperty]
Person::ArrayProperty('name')->schema['type']; // ['string']

CheckData($data, $errors)

staticaEntity.php:170

Check data before it touches any entity: would an entity made from $data be valid? Nothing is created, changed or saved: the data is loaded into a throwaway instance, which is then validate()d.

static function CheckData(array $data, ?array &$errors = null): boolA key that is none of the entity's properties is an error too (`unknown property. did you mean [name]?`): loaded, it would be ignored, and its value lost. To check a change to an existing entity, pass its current values with the change on top.
$dataarray
$errors = nullnull | array
returnsbool
if (!Person::CheckData($input, $errors)) {return ['errors' => array_map(fn($e) => $e->message, $errors)];} $people->createEntity($input);Person::CheckData([...$person->toArray(), ...$input], $errors); // a change to $person

compareTo($value)

aEntity.php:266

Compare value

function compareTo(mixed $value): int|bool
$valuemixed
returnsint | bool
$person->compareTo($otherPerson); // via \MMO\core\objects\compare on both entities' toArray()

conversionError($key, $e)

aEntity.php:239

The error recorded for a value that could not be set at all (usually: it could not be converted to its property's type), in the same form as a validation error.

protected function conversionError(string $key, Throwable $e): MMO\core\schemas\ValidatorError
$keystringthe property
$eThrowablewhy it could not
returnsValidatorErrornot a valid [null|integer]. when the property's type is known

get($path, $default)

aEntity.php:192

Read a (possibly nested) value by json-path, e.g. 'address/city'. Unlike a plain get call, a path through a genuinely UNDECLARED array property still throws (it is a programming error, not a "missing value"); $default only kicks in for a structurally valid path with nothing at the end (e.g. a missing list index).

function get(string $path, mixed $default = null): mixed
$pathstring
$default = nullmixed
returnsmixed
$person->get('address/city', 'unknown');

getArrayProperty($key, $isRef, $store)

tArrayProperties.php:426

Read a single array property's current value, through its getter (a direct property, a path alias, or a method).

function getArrayProperty(string $key, &$isRef = null, bool $store = false): mixed
$keystringthe array property's name
$isRef = null
$store = falseboolif true, use the property's store getter instead of its normal getter
returnsmixeda reference to the value (a typed property that was never assigned returns null rather than throwing PHP's usual "must not be accessed before initialization" error)
$person->getArrayProperty('name'); // 'Marc'

getChanges($asArray, $store)

aEntity.php:534
function getChanges(bool $asArray = false, bool $store = true): array
See
tArrayProperties::getArrayProperty) instead of its normal getter
$asArray = falseboolif true, a changed property that is itself an entity is recursively expanded to a plain array (via toArray(null, true, true)) instead of staying an object
$store = trueboolif true, read each changed value through its store getter (see
returnsarrayproperty name => its current value, for every property marked changed since the last clearChanges
$person->getChanges(); // e.g. ['name' => 'Updated']

getFlags()

aEntity.php:680
function getFlags(): int
returnsintthe raw bitmask of iEntity::FLAG_* currently set

getLabel()

aEntity.php:341
function getLabel(): string
returnsstringthe entity's short name, per the schema's @label template (or its default label rule)

getLinksByRel($rels, $all)

aEntity.php:486

Get a list of Reference that have a specific relationship.

function getLinksByRel(array|string $rels, bool $all = true): array
$relsarray | stringone or multiple rels seperated by space
$all = trueboolif true get only the References with all the relationship. Else any Reference with at least one of the relationship.
returnsarray
$entity->getLinksByRel('self');$entity->getLinksByRel(['edit', 'delete'], false); // any link tagged 'edit' OR 'delete'

getMetadata()

aEntity.php:222
function getMetadata(): array
returnsarrayassembled from title/label/links/errors (only the non-empty ones), plus 'opacified' => true when isOpacified

getTitle()

aEntity.php:334
function getTitle(): string
returnsstringthe entity's long name, per the schema's @title template (e.g. @title {lastname} {name}), falling back to getLabel if there is no @title or it renders empty

getView()

aEntity.php:356
function getView(): MMO\core\helpers\Uri|string|null
returnsUri | string | nullView, rendered with this entity's own values if it's a path template (starts with '/') -- turned into an absolute Uri via \MMO\url(); returned as-is otherwise

hasChanged($keys)

aEntity.php:548
function hasChanged(string ...$keys): bool
...$keysstring
returnsbooltrue if any of $keys is currently marked changed

hasFlags($flags, $strict)

aEntity.php:714
function hasFlags(int $flags, bool $strict = false): bool
$flagsinta bitmask of iEntity::FLAG_* to test
$strict = falseboolif false (the default), true if AT LEAST ONE of $flags is set; if true, true only if EVERY one of $flags is set
returnsbool
$entity->hasFlags(iEntity::FLAG_CREATED | iEntity::FLAG_CHANGED); // true if created OR changed$entity->hasFlags(iEntity::FLAG_CREATED | iEntity::FLAG_CHANGED, true); // true only if BOTH

HiddenPath($path)

statictArrayProperties.php:261

The hidden property (ArrayProperty::isHidden) a json-path goes through, known from the declared types alone: of this class, or of a class a property on the way may hold -- every class of its type (owner/passhash when owner is an iClient, and User is one). A query tells the values it filters or sorts on through what it returns: an API query cannot use it (Route::extractQuery). What a property of no class holds (a plain array, mixed) is not looked into.

static function HiddenPath(array|string $path): ?string
$patharray | string
returnsnull | stringthe path to the hidden property (owner/passhash), or null if $path goes through none
User::HiddenPath('passhash'); // 'passhash'File::HiddenPath('owner/passhash'); // 'owner/passhash': its owner may be a UserUser::HiddenPath('roles/0/label'); // null

ignoreChanges($value)

aEntity.php:507

Temporarily suppress markChanged (used e.g. by loadFromStore, so hydrating an entity from storage doesn't get recorded as an edit).

function ignoreChanges(bool $value = true): bool
$value = truebooltrue to start ignoring changes, false to resume tracking them
returnsboolsee addFlags / removeFlags

isArrayPropertySet($key, $store)

tArrayProperties.php:491
function isArrayPropertySet(string $key, bool $store = false): bool
See
iArrayProperties value is considered set if it is itself non-isEmpty)
$keystringthe array property's name
$store = falseboolif true, read through the store getter instead of the normal getter
returnsbooltrue if the property's current value differs from its schema default (a nested
(new Person())->isArrayPropertySet('name') === false // default value ('') is still in place

isCreated()

aEntity.php:724
function isCreated(): bool
returnsbooltrue if this entity was just constructed (set in the constructor, never cleared automatically)

isEmpty()

tArrayProperties.php:477
function isEmpty(): bool
returnsbooltrue if every storable property still holds its schema default value (i.e. nothing meaningful has been set on this instance yet)
(new Person())->isEmpty() === true(new Person())->loadArray(['name' => 'Marc'])->isEmpty() === false

isHiddenPath($path)

tArrayProperties.php:352
function isHiddenPath(string $path): bool
$pathstringa property's name, or a json-path through the values of this object (owner/passhash)
returnsbooltrue if $path goes through a hidden property (ArrayProperty::isHidden), of this object or of one met on the way: what it holds is never exported (toArray)
$user->isHiddenPath('passhash'); // true: `@hidden`$file->isHiddenPath('owner/passhash'); // true when its owner is a User$file->isHiddenPath('owner/username'); // false

isOpacified()

aEntity.php:734
function isOpacified(): bool
returnsbooltrue if opacify(true) was called: toArray then exposes only 'uid'/'metadata'

isSimilar($value)

aEntity.php:283

Compare entities using unique fields (@unique), to find if they represent the same entity

function isSimilar(self|array $value): bool
$valueself | arrayanother entity, or a raw array of property values
returnsbooltrue if $value matches this entity on every key of at least one of the schema's @unique property groups (see Schema::getUniquePropertyGroups) NOTE: Entity::isSimilar (the base every concrete entity normally extends) layers an additional shortcut on top of this: two entities with the same non-null 'id' are ALWAYS similar, even with no @unique group defined at all, or one that doesn't match.
// class UniqueEntity extends Entity {...} with docblock `@unique email` (new UniqueEntity(['email' => 'a@x.com']))->isSimilar(['email' => 'a@x.com']); // true: matches on 'email' (new UniqueEntity(['email' => 'a@x.com']))->isSimilar(['email' => 'b@x.com']); // false: no unique group matches

isUnique()

aEntity.php:311

Tells if an entity has enough information to be unique (at least one unique group has no null)

function isUnique(): bool
returnsbooltrue if every key of at least one @unique property group is currently non-null. NOTE: the check is a strict === null, so a non-nullable property (e.g. string $email = '') already counts as "set" at its schema default -- this only catches a genuinely nullable, still-unset field.
(new UniqueEntity(['email' => 'a@x.com']))->isUnique(); // true(new UniqueEntity())->isUnique(); // true too: $email's default is '', not null

isValid()

aEntity.php:256
function isValid(): bool
returnsbooltrue if no property currently has a recorded error

ListClassReferences($onlyStorable)

statictArrayProperties.php:61

Get a list of all the classes and their properties that are using references to this class.

static function ListClassReferences(bool $onlyStorable = false): array
$onlyStorable = falseboolif true, will only list properties that are storable. This is useful for getting all the entities that might make a reference in the repository to this class
returnsarray(classname => [name => ArrayProperty])
// if PersonWithFriend has: #[ArrayProperty] protected ?Person $friend; Person::ListClassReferences(); // [PersonWithFriend::class => ['friend' => ArrayProperty(...)]]

loadArray($data, $coerceOptions, $fromStore)

tArrayProperties.php:391

Set every entry of $data as an array property, through setArrayProperty (so each value is coerced by its property's schema). Unknown keys are dropped with a logged \MMO\error() rather than throwing.

function loadArray(array $data, array $coerceOptions = [], bool $fromStore = false): static
$dataarraykey => value, as produced by toArray / store
$coerceOptions = []arrayoptions forwarded to the schema coercer
$fromStore = falseboolif true, readonly properties can still be set (needed to reload a stored/persisted record, whose readonly properties were legitimately set once at store time)
returnsstatic$this, for chaining
$person = (new Person())->loadArray(['name' => 'Marc', 'age' => 42]);

loadFromStore($data)

aEntity.php:84

Load $data as this entity's initial state (e.g. when hydrating from a repository), WITHOUT marking any of it as a "change" (ignoreChanges): this is the entity's starting point, not an edit.

function loadFromStore(array $data): void
$dataarray
returnsvoid

markChanged($keys)

aEntity.php:517

Mark one or multiple key as changed

function markChanged(string ...$keys): bool
...$keysstring
returnsboolfalse if currently ignoreChanges (nothing recorded); true otherwise

mutate($type, $path, $value, $oldValue)

aEntity.php:574

\MMO\core\interfaces\iMutationObserver::mutate -- besides the normal tArrayProperties::mutate behavior, walks up $path to find the nearest enclosing aEntity (the mutation may have happened deep inside a nested array/object property) and marks ITS top-level property changed, not just $this's.

function mutate(string $type, array $path, mixed $value, mixed $oldValue): bool
$typestring
$patharray
$valuemixed
$oldValuemixed
returnsbool

offsetExists($key)

tArrayProperties.php:665

\ArrayAccess::offsetExists -- tells whether $key is a *declared* #[ArrayProperty], not whether it currently holds a non-default value (use isArrayPropertySet for that).

function offsetExists(mixed $key): bool
$keymixed
returnsbool
isset($person['name']) === trueisset($person['does-not-exist']) === false

offsetUnset($key)

tArrayProperties.php:636

\ArrayAccess::offsetUnset -- equivalent to setting the property to null (its coerced value depends on the property's schema: e.g. a non-nullable string ends up as '', not literally null -- see setArrayProperty)

function offsetUnset(mixed $key): void
$keymixed
returnsvoid
unset($person['name']); // $person['name'] becomes '' (the schema's coerced form of null)

opacify($value)

aEntity.php:745

Hide this entity's properties from toArray output (typically used to redact an entity the current viewer isn't allowed to see the details of, while still letting it be referenced by uid/metadata).

function opacify(bool $value = true): void
$value = truebool
returnsvoid
$entity->opacify(); $entity->toArray(); // ['uid' => ..., 'metadata' => [...]] only

push($path, $value)

aEntity.php:214

Append a value to a (possibly nested) list property by json-path.

function push(string $path, mixed $value): void
$pathstring
$valuemixed
returnsvoid
$person->push('tags', 'vip');

removeFlags($flags)

aEntity.php:698
function removeFlags(int $flags): bool
$flagsinta bitmask of iEntity::FLAG_* to clear
returnsbooltrue if any of $flags was actually set (and is now cleared)

removePermanently()

aEntity.php:433

Remove this entity from the repository once MMO\commit() is called WARNING: This will permanently remove the entity.

function removePermanently(): void
returnsvoid

Schema()

statictArrayProperties.php:45

The JSON-Schema describing every #[ArrayProperty] of this class (built once and cached by ArrayProperties).

static function Schema(): MMO\core\schemas\Schema
returnsSchema
Person::Schema(); // a Schema instance with 'name' (string) and 'age' (integer) properties

SearchProperty($name)

statictArrayProperties.php:291
static function SearchProperty(string $name): MMO\core\attributes\SearchProperty
$namestring
returnsSearchProperty
throwsif $name is not a declared #[SearchProperty] (every class always has at least 'label', added automatically by ArrayProperties)
Person::SearchProperty('label')->name === 'label'

set($path, $value)

aEntity.php:203

Write a (possibly nested) value by json-path, creating intermediate structure as needed.

function set(string $path, mixed $value): void
$pathstring
$valuemixed
returnsvoid
$person->set('address/city', 'Paris');

setArrayProperty($key, $value, $coerceOptions, $ignoreReadonly)

aEntity.php:602

Same as tArrayProperties::setArrayProperty, plus: any coercion/validation failure is caught and recorded in getErrors (making the entity isValid()-false) instead of propagating as an exception, and a successful set through a direct property getter/setter is automatically markChanged.

function setArrayProperty( mixed $key, mixed $value, array $coerceOptions = [], bool $ignoreReadonly = false ): bool
$keymixed
$valuemixed
$coerceOptions = []array
$ignoreReadonly = falsebool
returnsboolfalse if the value was rejected (an error was recorded) or nothing changed
throwsthis one is NOT caught -- it means the property itself is misconfigured, a bug to fix rather than a bad input value to report
$entity->setArrayProperty('name', ['not', 'a', 'string']); // false, and getErrors()['name'] is set

setArrayPropertyOffset($key, $offset, $value, $coerceOptions)

aEntity.php:651

Same as tArrayProperties::setArrayPropertyOffset, plus: when pushing (offset === null) a new entity onto a list property, if an existing item is isSimilar to the new value, that item's offset is reused instead of appending a duplicate -- so pushing "the same" entity twice updates it in place.

function setArrayPropertyOffset( string $key, string|int|null $offset, mixed $value, array $coerceOptions = [] ): bool
$keystring
$offsetstring | int | null
$valuemixed
$coerceOptions = []array
returnsbool
throwsif $offset is null and $key is not a list property

setStatus($status)

aEntity.php:375
function setStatus(MMO\core\entities\cStatus $status): bool
$statuscStatus
returnsbooltrue if the status actually changed (also markChanged('status'))

store()

tArrayProperties.php:373

Export all array properties with store set to true.

function store(): arrayUsed to store the entity in a database
returnsarray
throws
$person->store(); // ['name' => 'Marc', 'age' => 42] -- every property here is storable by default

test($filter)

aEntity.php:326
function test(MMO\core\interfaces\iFilter $filter): bool
$filteriFilter
returnsbooltrue if this entity matches $filter

toArray($fields, $flatten, $recursive)

aEntity.php:119

Same as tArrayProperties::toArray, except an isOpacified entity always exports only its 'uid' and 'metadata' (its other properties are hidden from output).

function toArray(?array $fields = null, bool $flatten = false, bool $recursive = false): array
$fields = nullnull | array
$flatten = falsebool
$recursive = falsebool
returnsarray

traitMutate($type, $path, $value, $oldValue)

tArrayProperties.php:619

\MMO\core\interfaces\iMutationObserver::mutate -- reacts to a mutation that happened deep inside one of this object's array properties (e.g. an item of a nested array/object was changed through its own reference) by re-running that top-level property's setter, so any custom coercion/validation logic still applies.

function traitMutate(string $type, array $path, mixed $value, mixed $oldValue): bool
$typestringthe kind of mutation ('+', '-', '=', ...)
$patharraythe property path that changed, e.g. ['tags', 0]
$valuemixedthe new value
$oldValuemixedthe previous value
returnsbooltrue (this trait never rejects a mutation)

traitSetArrayProperty($key, $value, $coerceOptions, $fromStore)

tArrayProperties.php:510

Set array property

function traitSetArrayProperty( string $key, mixed $value, array $coerceOptions = [], bool $fromStore = false ): bool
$keystringthe array property's name
$valuemixedthe value to set
$coerceOptions = []arrayoptions to pass to the schema's coercer
$fromStore = falseboolif true, won't throw an exception for readonly properties if it is an actual storable property
returnsbooltrue if the value actually changed (a set to an equal value returns false and does nothing)
throwswhen a readonly properties is set.
$person->setArrayProperty('age', 43); // true: value changed$person->setArrayProperty('age', 43); // false the second time: already 43, no-op

traitSetArrayPropertyOffset($key, $offset, $value, $coerceOptions)

tArrayProperties.php:571

Set/push a value into an array property

function traitSetArrayPropertyOffset( string $key, string|int|null $offset, mixed $value, array $coerceOptions = [] ): bool
$keystringthe array property's name
$offsetstring | int | nullthe offset at wich to set the value
$valuemixedif null (and $offset is not null), unset the offset instead of setting it
$coerceOptions = []arraythe coerce options
returnsbooltrue if the value has changed
$person->setArrayPropertyOffset('tags', null, 'x'); // pushes 'x' onto the end of the list$person->setArrayPropertyOffset('tags', 0, 'z'); // sets index 0 to 'z'$person->setArrayPropertyOffset('tags', 0, null); // unsets index 0

traitToArray($fields, $flatten, $recursive)

tArrayProperties.php:317

Export fields to an array.

function traitToArray(?array $fields = null, bool $flatten = false, bool $recursive = false): arrayPath in fields are allowed, so field 'a/b/c' will look for value at $this['a']['b']['c'] A hidden property ([`ArrayProperty::isHidden`](https://mcp.mmoframework.fr/documentation/mmo.core/php/attributes/ArrayProperty.md#arrayproperty-ishidden)) is never exported: not even named in $fields, nor further along a path (`owner/passhash`).
$fields = nullnull | arrayif null, export all non-hidden array properties.
$flatten = falseboolif true and a field is a path, the structure is not created to set the value
$recursive = falseboolif true, any nested iArrayProperties value is itself recursively converted with toArray(null, true, true); if false (the default), a nested value is left as-is (e.g. still an object, not a plain array)
returnsarray
throws
$person->toArray(); // ['name' => 'Marc', 'age' => 42]$personWithFriend->toArray(); // ['name' => 'Marc', 'friend' => Person{...}, 'tags' => [...]] -- $friend stays an object$personWithFriend->toArray(null, false, true); // same, but 'friend' => ['name' => ..., 'age' => ...] (recursively expanded)$personWithFriend->toArray(['friend/name']); // ['friend' => ['name' => 'Alice']] -- path fields rebuild the nesting$personWithFriend->toArray(['friend/name'], true); // ['friend/name' => 'Alice'] -- $flatten=true keeps the path as a single key$user->toArray(['username', 'passhash']); // ['username' => 'marc'] -- passhash is `@hidden`

validate($errors)

aEntity.php:141

Validate this entity: its current values against its own tArrayProperties::Schema, plus every value that could not even be set -- one that could not be converted to its property's type never reaches the property, which keeps its previous value, so the schema alone would find nothing wrong. Runs in every mode, unlike the check made as each value is set (setArrayProperty), which only runs in dev mode.

function validate(?array &$errors = null): bool
$errors = nullnull | array
returnsbool
$person->set('age', 'abc'); $person->validate($errors); // false: $errors['age']->message is 'not a valid [null|integer].'

View()

staticaEntity.php:348
static function View(): ?string
returnsnull | stringthis class's declared front-end view ($view in its schema, e.g. @view /users/{id}), if any
Inherited members (11)
ConstantsDeclared byDescription
FLAG_CHANGEDiEntity
FLAG_CREATEDiEntity
FLAG_IGNORE_CHANGEiEntity
FLAG_IGNORE_ENTITYiEntity
FLAG_OPACIFYiEntity
FLAG_REMOVEDiEntity
MethodsDeclared byDescription
getCollection()iEntity
getId()iEntity
getRepository()iEntity
localName()iEntityGet the local name (collection name and this id) in the current repository
uid()iIdentifiableGet the unique identifier