tArrayProperties
MMO\core\classes · 1 symbol · generated 30 Sep 2026
tArrayProperties
tArrayProperties.php:35Trait implementing iArrayProperties: turns a class's PHP properties (and/or methods) annotated with the #[ArrayProperty] attribute into a declarative, schema-backed "array" of named values, with array-access ($obj['key']), coercion, JSON-Schema generation, storage export, and change tracking built in.
- Namespace
MMO\core\classes- See
iMutationObservercontract) --setArrayPropertyOffsetcalls it directly. It is not provided by the trait itself, since concrete change-tracking (e.g.Entity) is left to the consuming class.
Index
| ArrayProperties static | ||
| SearchProperties static | ||
| ArrayProperties() static | 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… | |
| ArrayProperty($name) static | ||
| getArrayProperty($key, $isRef, $store) | Read a single array property's current value, through its getter (a direct property, a path alias, or a method). | |
| HiddenPath($path) static | 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 t… | |
| isArrayPropertySet($key, $store) | ||
| isEmpty() | ||
| isHiddenPath($path) | ||
| ListClassReferences($onlyStorable) static | Get 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). | |
| mutate($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. | |
| 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. | |
| Schema() static | The JSON-Schema describing every #[ArrayProperty] of this class (built once and cached by ArrayProperties). | |
| SearchProperty($name) static | ||
| setArrayProperty($key, $value, $coerceOptions, $fromStore) | Set array property | |
| setArrayPropertyOffset($key, $offset, $value, $coerceOptions) | Set/push a value into an array property | |
| store() | Export all array properties with store set to true. | |
| toArray($fields, $flatten, $recursive) | Export fields to an array. |
Properties2
ArrayProperties
static- Type
- array
SearchProperties
static- Type
- array
Methods20
ArrayProperties()
statictArrayProperties.php:85Build (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.
| returns | array | \MMO\core\attributes\ArrayProperty} name => ArrayProperty, in schema-sort order |
| throws |
ArrayProperty($name)
statictArrayProperties.php:243| $name | string | |
| returns | ArrayProperty | the property's metadata (schema, getter, setter, ...) |
| throws | if $name is not a declared #[ArrayProperty] |
getArrayProperty($key, $isRef, $store)
tArrayProperties.php:426Read a single array property's current value, through its getter (a direct property, a path alias, or a method).
| $key | string | the array property's name |
| $isRef = null | ||
| $store = false | bool | if true, use the property's store getter instead of its normal getter |
| returns | mixed | a 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) |
isArrayPropertySet($key, $store)
tArrayProperties.php:491- See
iArrayPropertiesvalue is considered set if it is itself non-isEmpty)
| $key | string | the array property's name |
| $store = false | bool | if true, read through the store getter instead of the normal getter |
| returns | bool | true if the property's current value differs from its schema default (a nested |
isEmpty()
tArrayProperties.php:477| returns | bool | true if every storable property still holds its schema default value (i.e. nothing meaningful has been set on this instance yet) |
ListClassReferences($onlyStorable)
statictArrayProperties.php:61Get a list of all the classes and their properties that are using references to this class.
| $onlyStorable = false | bool | if 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 |
| returns | array | (classname => [name => ArrayProperty]) |
loadArray($data, $coerceOptions, $fromStore)
tArrayProperties.php:391Set 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.
| $data | array | key => value, as produced by toArray / store |
| $coerceOptions = [] | array | options forwarded to the schema coercer |
| $fromStore = false | bool | if true, readonly properties can still be set (needed to reload a stored/persisted record, whose readonly properties were legitimately set once at store time) |
| returns | static | $this, for chaining |
mutate($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.
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).
offsetGet($key)
tArrayProperties.php:645\ArrayAccess::offsetGet
offsetSet($key, $value)
tArrayProperties.php:654\ArrayAccess::offsetSet
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)
Schema()
statictArrayProperties.php:45The JSON-Schema describing every #[ArrayProperty] of this class (built once and cached by ArrayProperties).
| returns | Schema |
SearchProperty($name)
statictArrayProperties.php:291| $name | string | |
| returns | SearchProperty | |
| throws | if $name is not a declared #[SearchProperty] (every class always has at least 'label', added automatically by ArrayProperties) |
setArrayProperty($key, $value, $coerceOptions, $fromStore)
tArrayProperties.php:510Set array property
| $key | string | the array property's name |
| $value | mixed | the value to set |
| $coerceOptions = [] | array | options to pass to the schema's coercer |
| $fromStore = false | bool | if true, won't throw an exception for readonly properties if it is an actual storable property |
| returns | bool | true if the value actually changed (a set to an equal value returns false and does nothing) |
| throws | when a readonly properties is set. |
setArrayPropertyOffset($key, $offset, $value, $coerceOptions)
tArrayProperties.php:571Set/push a value into an array property
| $key | string | the array property's name |
| $offset | string | int | null | the offset at wich to set the value |
| $value | mixed | if null (and $offset is not null), unset the offset instead of setting it |
| $coerceOptions = [] | array | the coerce options |
| returns | bool | true if the value has changed |
store()
tArrayProperties.php:373Export all array properties with store set to true.
| returns | array | |
| throws |
toArray($fields, $flatten, $recursive)
tArrayProperties.php:317Export fields to an array.
| $fields = null | null | array | if null, export all non-hidden array properties. |
| $flatten = false | bool | if true and a field is a path, the structure is not created to set the value |
| $recursive = false | bool | if 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) |
| returns | array | |
| throws |