Index

Entity

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

class

Entity

Entity.php:17

The framework's standard, storable entity: an id, a label/title, and creation/modification timestamps on top of aEntity's schema/property/change-tracking machinery, plus the repository-facing bookkeeping (which Collection it belongs to, reference tracking for safe deletion) that a raw aEntity doesn't provide on its own.

class MMO\core\entities\Entity extends MMO\core\classes\aEntity
Namespace
MMO\core\entities
Extends
aEntity

Index

collection
ctime
ididentifier in collection
labelshort name
mtime
titlelong name
Copy($entity, $properties) staticBuild a new entity from $entity's own stored data (a duplicate, minus its id -- so saving it creates a genuinely new record -- in the same collection).
getCollection()
getCtime()
getId()
getLabel()
getMtime()
getRepository()
getTitle()
ignore()Ignore everything about this entity: discard its pending changes and flag it so it's skipped by future commits (aRepository::onCommit).
isArrayPropertySet($key, $store)Same as aEntity::isArrayPropertySet, but 'ctime'/'mtime' are never reported as "set" (they're always present, so listing them adds no information), and neither is 'id' once the entity is alrea…
isIgnored()
isSimilar($value)
loadArray($data, $coerceOptions, $fromStore)Same as aEntity::loadArray, but 'ctime'/'mtime' are never taken from $data: they belong to the server (set when the entity is created, bumped by markChanged), and a client sending back th…
loadFromStore($data)Restore from stored data, setting 'ctime'/'mtime' directly (bypassing their normal setters -- see setCtime/setMtime, which are read-only via #[ArrayProperty]).
localName()
loopReferences()Yield all the entities in the repository that have a reference on this one.
markChanged($keys)Same as aEntity::markChanged, also bumping $mtime to now -- unless the change itself was to 'ctime'/'mtime' (avoiding infinite recursion via setMtime's own markChanged call).
reload()Reload entity from its repository
removePermanently($force)Remove entity from database
replaceBy($replace, $mergeData)Replace this entity by another one, trying to change all references to this entity to the new one.
setCollection($collection, $removeFromCollection)Move this entity to (or out of, if null) a collection.
setCtime($date, $force)Set creation time
setId($id)Set the id, re-registering this entity in its $collection under the new id (Collection's entities are keyed by id).
setMtime($date, $force)Set modification time
uid()
__construct($data, $collection)

Properties6

collection

#[MMO\core\attributes\NoDump()] protected ?MMO\core\interfaces\iCollection $collection = null
Type
null | iCollection

ctime

#[MMO\core\attributes\ArrayProperty(setter: false, store: true)] protected DateTime $ctime
Type
DateTime

id

identifier in collection

#[MMO\core\attributes\ArrayProperty(setter: false, store: true)] protected mixed $id = null
Type
mixed

label

short name

#[MMO\core\attributes\ArrayProperty()] protected ?string $label = null
Type
null | string

mtime

#[MMO\core\attributes\ArrayProperty(setter: false, store: true)] protected DateTime $mtime
Type
DateTime

title

long name

#[MMO\core\attributes\ArrayProperty()] protected ?string $title = null
Type
null | string

Methods26

Copy($entity, $properties)

staticEntity.php:103

Build a new entity from $entity's own stored data (a duplicate, minus its id -- so saving it creates a genuinely new record -- in the same collection).

static function Copy(self $entity, ?array $properties = null): static
$entityself
$properties = nullnull | arrayif given, only copy these properties.
returnsstatic

getCollection()

Entity.php:182
function getCollection(): ?MMO\core\interfaces\iCollection
returnsnull | iCollectionthe collection this entity belongs to, if any.

getId()

Entity.php:143
function getId(): mixed
returnsmixedthis entity's id, or null if it hasn't been assigned one yet (a new, unsaved entity).

isArrayPropertySet($key, $store)

Entity.php:257

Same as aEntity::isArrayPropertySet, but 'ctime'/'mtime' are never reported as "set" (they're always present, so listing them adds no information), and neither is 'id' once the entity is already created (it's immutable metadata by then, not meaningful "changed data").

function isArrayPropertySet(string $key, bool $store = false): bool
$keystring
$store = falsebool
returnsbool

loadArray($data, $coerceOptions, $fromStore)

Entity.php:91

Same as aEntity::loadArray, but 'ctime'/'mtime' are never taken from $data: they belong to the server (set when the entity is created, bumped by markChanged), and a client sending back the values it read would otherwise keep the old modification time. A stored record restores them through loadFromStore.

function loadArray(array $data, array $coerceOptions = [], bool $fromStore = false): static
$dataarray
$coerceOptions = []array
$fromStore = falsebool
returnsstatic
$entity->loadArray(['title' => 'x', 'mtime' => '2020-01-01']); //title set, mtime = now

loadFromStore($data)

Entity.php:76

Restore from stored data, setting 'ctime'/'mtime' directly (bypassing their normal setters -- see setCtime/setMtime, which are read-only via #[ArrayProperty]).

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

localName()

Entity.php:162
function localName(): string
returnsstringa human-friendlier reference: the collection's name, '/', and this entity's id.

loopReferences()

Entity.php:294

Yield all the entities in the repository that have a reference on this one.

function loopReferences(): GeneratorNOTE: the final re-check used to be `($entity[$key]??null) === $this` unconditionally -- correct for a plain (scalar) reference property, but for a list/object property (checked via the exact same `$prop->schema->isList()/isObject()` condition already used just above to pick the `$has` filter operator) `$entity[$key]` is a whole ARRAY, which a strict `===` against the single entity `$this` can never match. Verified concretely: a `[Node] $children` list property correctly matched via the `$has` filter, yet this re-check always silently rejected it -- meaning loopReferences() (and everything relying on it, e.g.
See
removePermanently's "don't delete a still-referenced entity" safety check, and replaceBy) never actually found/updated any reference held in a list/object property. Fixed to check for membership (in_array($this, $value, true)) instead of identity for those properties.
returnsGeneratorkey => entity

removePermanently($force)

Entity.php:270

Remove entity from database

function removePermanently(bool $force = false): void
$force = falseboolif true, will clean the reference to this entity, by setting null if used
returnsvoid

replaceBy($replace, $mergeData)

Entity.php:324

Replace this entity by another one, trying to change all references to this entity to the new one.

function replaceBy(MMO\core\entities\Entity $replace, bool $mergeData = false): voidWARNING: the looping of references is not totally safe, so some references inside deep embedded entities might not be replaced.
$replaceEntity
$mergeData = falsebool
returnsvoid
throws

setCollection($collection, $removeFromCollection)

Entity.php:172

Move this entity to (or out of, if null) a collection.

function setCollection( ?MMO\core\interfaces\iCollection $collection, bool $removeFromCollection = true ): bool
$collectionnull | iCollection
$removeFromCollection = trueboolif true (default), also remove it from its current collection first.
returnsboolfalse if $collection is unchanged.

setCtime($date, $force)

Entity.php:217

Set creation time

function setCtime(DateTimeInterface|string|int $date, bool $force = true): bool
$dateDateTimeInterface | string | int
$force = trueboolif false only set time if it is anterior to the current set time (used for unserialization)
returnsbool

setId($id)

Entity.php:148

Set the id, re-registering this entity in its $collection under the new id (Collection's entities are keyed by id). @return bool false if $id is unchanged.

function setId(mixed $id): bool
$idmixed
returnsbool

setMtime($date, $force)

Entity.php:239

Set modification time

function setMtime(DateTimeInterface|string|int $date, bool $force = true): bool
$dateDateTimeInterface | string | int
$force = trueboolif false only set time if it is anterior to the current set time (used for unserialization)
returnsbool

uid()

Entity.php:157
function uid(): string
returnsstringa globally-unique reference: the collection's own uid, '#', and this entity's id.

__construct($data, $collection)

Entity.php:61
function __construct(array $data = [], ?MMO\core\interfaces\iCollection $collection = null)
$data = []arrayinitial property values (see aEntity::loadArray). 'ctime'/'mtime' default to 'now' if not given.
$collection = nullnull | iCollectionadded to it before $data is loaded, so cross-referencing children can find it.
Inherited members (79)
ConstantsDeclared byDescription
FLAG_CHANGEDiEntity
FLAG_CREATEDiEntity
FLAG_IGNORE_CHANGEiEntity
FLAG_IGNORE_ENTITYiEntity
FLAG_OPACIFYiEntity
FLAG_REMOVEDiEntity
PropertiesDeclared byDescription
ArrayPropertiesaEntity
changesaEntity
errorsaEntity
flagsaEntity
linksaEntity
SearchPropertiesaEntity
statusaEntity
MethodsDeclared byDescription
addFlags($flags)aEntity
addLink($link)aEntityAppend a link.
archive()aEntityThis function is called to 'delete' the entity.
ArrayProperties()aEntityBuild (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)aEntity
CheckData($data, $errors)aEntityCheck data before it touches any entity: would an entity made from $data be valid?
clearChanges()aEntityReset change tracking: clears iEntity::FLAG_CHANGED and forgets every recorded change.
compareTo($value)aEntityCompare value
conversionError($key, $e)aEntityThe 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()aEntity
get($path, $default)aEntityRead a (possibly nested) value by json-path, e.g.
getArrayProperty($key, $isRef, $store)aEntityRead a single array property's current value, through its getter (a direct property, a path alias, or a method).
getChanges($asArray, $store)aEntity
getErrors()aEntity
getFlags()aEntity
getLinks()aEntity
getLinksByRel($rels, $all)aEntityGet a list of Reference that have a specific relationship.
getMetadata()aEntity
getStatus()aEntity
getView()aEntity
hasChanged($keys)aEntity
hasFlags($flags, $strict)aEntity
hasStatusChanged()aEntity
HiddenPath($path)aEntityThe 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)aEntityTemporarily suppress markChanged (used e.g.
isActive()aEntity
isArchive()aEntity
isChanged()aEntity
isCreated()aEntity
isDraft()aEntity
isEmpty()aEntity
isFinal()aEntity
isHiddenPath($path)aEntity
isOpacified()aEntity
isPending()aEntity
isRemoved()aEntity
isUnique()aEntityTells if an entity has enough information to be unique (at least one unique group has no null)
isValid()aEntity
isValidated()aEntity
ListClassReferences($onlyStorable)aEntityGet a list of all the classes and their properties that are using references to this class.
mutate($type, $path, $value, $oldValue)aEntity\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)aEntity\ArrayAccess::offsetExists -- tells whether $key is a *declared* #[ArrayProperty], not whether it currently holds a non-default value (use isArrayPropertySet for that).
offsetGet($key)aEntity\ArrayAccess::offsetGet
offsetSet($key, $value)aEntity\ArrayAccess::offsetSet
offsetUnset($key)aEntity\ArrayAccess::offsetUnset -- equivalent to setting the property to null (its coerced value depends on the property's schema: e.g.
opacify($value)aEntityHide 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)aEntityAppend a value to a (possibly nested) list property by json-path.
removeFlags($flags)aEntity
removeLink($link)aEntityRemove a link (by identity).
Schema()aEntityThe JSON-Schema describing every #[ArrayProperty] of this class (built once and cached by ArrayProperties).
SearchProperty($name)aEntity
set($path, $value)aEntityWrite a (possibly nested) value by json-path, creating intermediate structure as needed.
setArrayProperty($key, $value, $coerceOptions, $ignoreReadonly)aEntitySame 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)aEntitySame 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)aEntityReplace every link with $links.
setStatus($status)aEntity
store()aEntityExport all array properties with store set to true.
test($filter)aEntity
toArray($fields, $flatten, $recursive)aEntitySame as tArrayProperties::toArray, except an isOpacified entity always exports only its 'uid' and 'metadata' (its other properties are hidden from output).
toLink($attributes)aEntity
traitMutate($type, $path, $value, $oldValue)aEntity\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)aEntitySet array property
traitSetArrayPropertyOffset($key, $offset, $value, $coerceOptions)aEntitySet/push a value into an array property
traitToArray($fields, $flatten, $recursive)aEntityExport fields to an array.
validate($errors)aEntityValidate 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()aEntity