Index

PDOEntity

MMO\pdo\helpers · 1 symbol · generated 5 Oct 2026

class

PDOEntity

PDOEntity.php:21

Base class for an entity backed by a SQL row -- used by Table to generate one class per table from its columns (Table::toPHP), and usable directly as the parent of a hand-written table entity.

class MMO\pdo\helpers\PDOEntity extends MMO\core\classes\aEntity
Namespace
MMO\pdo\helpers
Extends
aEntity
See
ID_PROP: whichever column(s) actually form the primary key., ID_PROP for how a composite primary key is handled.
It extends [`aEntity`](https://mcp.mmoframework.fr/documentation/mmo.core/php/classes/aEntity.md#aentity) rather than [`Entity`](https://mcp.mmoframework.fr/documentation/mmo.core/php/entities/Entity.md#entity) on purpose: `Entity` declares `id`, `label`, `title`, `ctime` and `mtime` as real properties with fixed types, and an arbitrary SQL table has no reason to carry any of them -- a table with a `title INT` column, say, cannot extend it at all (redeclaring an inherited property with an incompatible type is a fatal error). What a `Table` entity gets instead is

Index

ID_PROPThe property (or, for a composite primary key, the list of properties) holding the id.
ID_SEPARATORSeparator folding a composite primary key into the single string the framework indexes entities by.
collection
debugId()
debugName()
getCollection()
getId()
getIdParts()
getRepository()
idValue($key)Read one id column.
ignore()Discard this entity's pending changes and flag it so future commits skip it.
isIgnored()
localName()
ParseId($id) staticSplit a composite id string back into its individual values.
setCollection($collection, $removeFromCollection)
setId($id)Set the id, re-filing this entity in its collection under the new key.
uid()
__construct($data, $collection)

Constants2

ID_PROP

The property (or, for a composite primary key, the list of properties) holding the id.

const ID_PROP = 'id'Generated subclasses override this; null means the table has no primary key at all, so its rows have no id and cannot be looked up by one.

ID_SEPARATOR

Separator folding a composite primary key into the single string the framework indexes entities by.

const ID_SEPARATOR = ''The framework keys a [`iCollection`](https://mcp.mmoframework.fr/documentation/mmo.core/php/interfaces/iCollection.md#icollection) by `(string)$entity->getId()` and looks entities up through `getById(string $id)`, so a composite id MUST still be one string. ASCII 0x1D (GROUP SEPARATOR) is used because it cannot collide with the `/` and `#` that structure a uid, and does not occur in real data.
See
getIdParts / ParseId to go back to the individual values.

Properties1

collection

protected ?MMO\core\interfaces\iCollection $collection = null
Type
null | iCollection

Methods15

debugId()

PDOEntity.php:157
function debugId(): string
returnsstringthe id in a form that is readable in a log: [a,b] for a composite key.

getId()

PDOEntity.php:86
function getId(): mixed
returnsmixedthe entity's id -- for a composite primary key, its parts joined by ID_SEPARATOR. Empty when the table has no primary key, or when a key column has no value yet (a row not yet inserted).

getIdParts()

PDOEntity.php:103
function getIdParts(): array
returnsarraythe id as column => value, which is what a WHERE clause needs. Empty when the table has no primary key.

idValue($key)

PDOEntity.php:78

Read one id column.

protected function idValue(string $key): mixed
$keystring
returnsmixednull when the column holds no value yet, or when ID_PROP names a property this class does not actually declare -- a misdeclared subclass should behave as "no id", not explode inside the collection's indexing.

ignore()

PDOEntity.php:193

Discard this entity's pending changes and flag it so future commits skip it.

function ignore(): void
See
Entity declares this too, but aEntity (this class's parent) does not -- and a repository needs it to skip an entity it must not write, e.g. one in a read-only collection.
returnsvoid

ParseId($id)

staticPDOEntity.php:67

Split a composite id string back into its individual values.

static function ParseId(string $id): array
$idstring
returnsarrayone item per ID_PROP key (a single-column id yields a one-item list)

setCollection($collection, $removeFromCollection)

PDOEntity.php:165
function setCollection( ?MMO\core\interfaces\iCollection $collection, bool $removeFromCollection = true ): bool
$collectionnull | iCollection
$removeFromCollection = truebool
returnsbool

setId($id)

PDOEntity.php:121

Set the id, re-filing this entity in its collection under the new key.

function setId(mixed $id): bool
$idmixedeither the column => value map / ordered list of a composite key, or a single scalar for a single-column key. A composite key may also be passed as a string previously produced by getId.
returnsboolfalse if the id did not actually change
throwsif a composite key is incomplete

__construct($data, $collection)

PDOEntity.php:44
function __construct(array $data = [], ?MMO\core\interfaces\iCollection $collection = null)
$data = []array
$collection = nullnull | iCollection
Inherited members (86)
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.
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
getLabel()aEntity
getLinks()aEntity
getLinksByRel($rels, $all)aEntityGet a list of Reference that have a specific relationship.
getMetadata()aEntity
getStatus()aEntity
getTitle()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
isArrayPropertySet($key, $store)aEntity
isChanged()aEntity
isCreated()aEntity
isDraft()aEntity
isEmpty()aEntity
isFinal()aEntity
isHiddenPath($path)aEntity
isOpacified()aEntity
isPending()aEntity
isRemoved()aEntity
isSimilar($value)aEntityCompare entities using unique fields (@unique), to find if they represent the same entity
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.
loadArray($data, $coerceOptions, $fromStore)aEntitySet every entry of $data as an array property, through setArrayProperty (so each value is coerced by its property's schema).
loadFromStore($data)aEntityLoad $data as this entity's initial state (e.g.
markChanged($keys)aEntityMark one or multiple key as changed
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).
removePermanently()aEntityRemove this entity from the repository once MMO\commit() is called WARNING: This will permanently remove the entity.
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