Index

aRepository

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

class

aRepository

aRepository.php:22

Collections container.

abstract class MMO\core\classes\aRepository implements MMO\core\interfaces\iRepository, ArrayAccess, IteratorAggregate
Namespace
MMO\core\classes
Implements
iRepository, ArrayAccess, IteratorAggregate
You can use class override for entities and collection : use the entity's classname and the collection's name To declare a collection as readonly, add a '!' at the begining of the name of the colleciton
$repo = new Repository(['people' => Person::class, '!archive' => ArchivedPerson::class]); $person = $repo->createEntity(Person::class, ['name' => 'Doe']); $repo['people'] === $repo->getCollection('people'); // true

Index

collections
addCollection($name, $collection)Add collection
createCollection($name, $entityClass, $collectionId)Create and register a plain Collection for entities of $entityClass.
createEntity($class, $data, $collection)Create an entity from data using its array properties
createLog($type, $origin, $collection, $data, $filters, $sorts, $limit, $offset)Build (but not dispatch) a LogQuery entity describing a data-mutating operation, stored in the repository's LogQuery collection (if one is registered).
debugName()
forceCommit($origin, $entities)
getCollection($name)
getCollectionByClass($entityClass, $allowChildClass)Find the collection whose entities are (an exact match, or optionally a subclass of) $entityClass.
getCollectionName($collection)
getCollections()
getDistinct($collection, $key)Every value one property takes across a collection, once each, in ascending order.
getEntities()
getIterator()\IteratorAggregate::getIterator -- iterates name => iCollection
hasCollection($collection)
hideLogData($collection, $data)What a repository logs is what it wrote (mmo.pdo's row, mmo.mongodb's document or its changes), hidden properties (ArrayProperty::isHidden) included, and a log is exported…
logDelete($origin, $collection, $data, $filters, $sorts, $limit, $offset)Log and dispatch a DELETE operation.
logInsert($origin, $collection, $data, $filters, $sorts, $limit, $offset)Log and dispatch an INSERT operation.
logStatus($origin, $collection, $data, $filters, $sorts, $limit, $offset)Log and dispatch a STATUS-change operation.
logUpdate($origin, $collection, $data, $filters, $sorts, $limit, $offset)Log and dispatch an UPDATE operation.
offsetExists($key)\ArrayAccess::offsetExists
offsetGet($key)\ArrayAccess::offsetGet
offsetSet($key, $value)\ArrayAccess::offsetSet -- equivalent to addCollection
offsetUnset($key)\ArrayAccess::offsetUnset
onCommit($commit) abstractPersist a batch of entity changes.
onFetch($event)Listener for Fetch: resolves a repository-uid/collection-id#id (or repository-uid/collection-id#id/nested/path for an embedded value) URL, what Ent…
searchText($query, $text)Full-text search. Not implemented at this level -- a concrete repository backed by a search-capable store should override this.
setCollections($cols)Register a batch of collections at once, e.g.
__construct($collections)
__wakeup()Register this repository's onCommit / onFetch as listeners on the global

Properties1

collections

#[MMO\core\attributes\Serialize(unserialize: 'setCollections', order: 100)] protected array $collections = []
Type
array

Methods29

addCollection($name, $collection)

aRepository.php:158

Add collection

function addCollection(string $name, MMO\core\interfaces\iCollection $collection): MMO\core\interfaces\iCollection
$namestringthe collection's name
$collectioniCollection
returnsiCollection

createCollection($name, $entityClass, $collectionId)

aRepository.php:220

Create and register a plain Collection for entities of $entityClass.

function createCollection(string $name, string $entityClass, ?string $collectionId = null): MMO\core\interfaces\iCollection
$namestring
$entityClassstring
$collectionId = nullnull | stringthe collection's own id (defaults to $name)
returnsiCollection

createEntity($class, $data, $collection)

aRepository.php:379

Create an entity from data using its array properties

function createEntity( string $class, array $data = [], ?MMO\core\interfaces\iCollection $collection = null ): MMO\core\interfaces\iEntity
$classstring
$data = []array
$collection = nullnull | iCollection
returnsiEntity
throwsif $collection is null and no registered collection matches $class
throwsif $collection is given but doesn't belong to this repository
$repo->createEntity(Person::class, ['name' => 'Doe']);

createLog($type, $origin, $collection, $data, $filters, $sorts, $limit, $offset)

aRepository.php:278

Build (but not dispatch) a LogQuery entity describing a data-mutating operation, stored in the repository's LogQuery collection (if one is registered). logUpdate / logInsert / logDelete /

function createLog( MMO\core\entities\cLogQuery $type, object|string $origin, MMO\core\interfaces\iCollection|string $collection, array $data, MMO\core\entities\Entity|array $filters = [], string $sorts = '', ?int $limit = null, ?int $offset = null ): MMO\core\entities\LogQuery
See
logStatus are thin wrappers around this that also dispatch it.
$typecLogQuerythe kind of operation
$originobject | stringwho/what performed the operation
$collectioniCollection | stringthe affected collection (or its name)
$dataarraythe data written: a hidden property's value is logged as LogQuery::HIDDEN (hideLogData)
$filters = []Entity | arraythe filter/entity that scoped the operation
$sorts = ''string
$limit = nullnull | int
$offset = nullnull | int
returnsLogQuery
throwsif no LogQuery collection is registered on this repository

debugName()

aRepository.php:56
function debugName(): string
returnsstringe.g. 'MMO\core\entities\Repository:[MEMORY REPOSITORY]'

forceCommit($origin, $entities)

aRepository.php:70
function forceCommit(mixed $origin, MMO\core\interfaces\iEntity ...$entities): MMO\core\events\Commit
$originmixed
...$entitiesiEntity
returnsCommit
$repo->forceCommit($this, $entity1, $entity2);

getCollection($name)

aRepository.php:168
function getCollection(string $name): MMO\core\interfaces\iCollection
$namestring
returnsiCollection
throwsif no collection is registered under $name

getCollectionByClass($entityClass, $allowChildClass)

aRepository.php:185

Find the collection whose entities are (an exact match, or optionally a subclass of) $entityClass.

function getCollectionByClass(string $entityClass, bool $allowChildClass = true): ?MMO\core\interfaces\iCollection
$entityClassstring
$allowChildClass = trueboolif true (the default), also match a collection whose entity class is an ancestor of $entityClass (an exact match is always preferred)
returnsnull | iCollectionnull if no collection matches
$repo->getCollectionByClass(Person::class);

getCollectionName($collection)

aRepository.php:149
function getCollectionName(MMO\core\interfaces\iCollection $collection): ?string
$collectioniCollection
returnsnull | stringthe name $collection is registered under, or null if it isn't one of this repository's collections

getCollections()

aRepository.php:144
function getCollections(): array
returnsarrayevery registered collection, keyed by name

getDistinct($collection, $key)

aRepository.php:100

Every value one property takes across a collection, once each, in ascending order.

function getDistinct(string $collection, string $key): arrayThis version reads every entity of the collection, which works with any repository; one that can ask its storage directly overrides it ([`MongoRepository::getDistinct`](https://mcp.mmoframework.fr/documentation/mmo.mongodb/php/MongoRepository.md#mongorepository-getdistinct)). Dates are compared as dates, so are sorted chronologically; null is left out.
$collectionstringthe collection's name
$keystringthe property (a /-separated path for a nested one)
returnsarray
$repository->getDistinct('people', 'age'); // [36, 41, 85]

getEntities()

aRepository.php:362
function getEntities(): array
returnsarrayevery entity across every collection in this repository

hasCollection($collection)

aRepository.php:208
function hasCollection(MMO\core\interfaces\iCollection|string $collection): bool
$collectioniCollection | stringa name (checked by key) or an instance (checked by identity)
returnsbool

hideLogData($collection, $data)

aRepository.php:307

What a repository logs is what it wrote (mmo.pdo's row, mmo.mongodb's document or its changes), hidden properties (ArrayProperty::isHidden) included, and a log is exported like any entity: its data, a plain array, would tell what the entity itself never does -- a password's hash. Their values are replaced, not dropped: the log still tells they were written.

protected function hideLogData(MMO\core\interfaces\iCollection|string $collection, array $data): array
$collectioniCollection | stringthe collection written to, or its name
$dataarrayproperty => value
returnsarray$data, every hidden property's value replaced with LogQuery::HIDDEN. A collection this repository does not have is logged as it is: nothing tells what it hides, and failing would fail the commit that logs it.
$this->hideLogData('users', ['username' => 'ada', 'passhash' => '$2y$10$...']); // ['username' => 'ada', 'passhash' => '[hidden]']

logDelete($origin, $collection, $data, $filters, $sorts, $limit, $offset)

aRepository.php:341

Log and dispatch a DELETE operation. See createLog for the parameters.

function logDelete( object|string $origin, MMO\core\interfaces\iCollection|string $collection, array $data, MMO\core\entities\Entity|array $filters = [], string $sorts = '', ?int $limit = null, ?int $offset = null ): ?MMO\core\entities\LogQuery
$originobject | string
$collectioniCollection | string
$dataarray
$filters = []Entity | array
$sorts = ''string
$limit = nullnull | int
$offset = nullnull | int
returnsnull | LogQuerynull if a listener marked the log as ignored (LogQuery::isIgnored)

logInsert($origin, $collection, $data, $filters, $sorts, $limit, $offset)

aRepository.php:331

Log and dispatch an INSERT operation. See createLog for the parameters.

function logInsert( object|string $origin, MMO\core\interfaces\iCollection|string $collection, array $data, MMO\core\entities\Entity|array $filters = [], string $sorts = '', ?int $limit = null, ?int $offset = null ): ?MMO\core\entities\LogQuery
$originobject | string
$collectioniCollection | string
$dataarray
$filters = []Entity | array
$sorts = ''string
$limit = nullnull | int
$offset = nullnull | int
returnsnull | LogQuerynull if a listener marked the log as ignored (LogQuery::isIgnored)

logStatus($origin, $collection, $data, $filters, $sorts, $limit, $offset)

aRepository.php:351

Log and dispatch a STATUS-change operation. See createLog for the parameters.

function logStatus( object|string $origin, MMO\core\interfaces\iCollection|string $collection, array $data, MMO\core\entities\Entity|array $filters = [], string $sorts = '', ?int $limit = null, ?int $offset = null ): ?MMO\core\entities\LogQuery
$originobject | string
$collectioniCollection | string
$dataarray
$filters = []Entity | array
$sorts = ''string
$limit = nullnull | int
$offset = nullnull | int
returnsnull | LogQuerynull if a listener marked the log as ignored (LogQuery::isIgnored)

logUpdate($origin, $collection, $data, $filters, $sorts, $limit, $offset)

aRepository.php:321

Log and dispatch an UPDATE operation. See createLog for the parameters.

function logUpdate( object|string $origin, MMO\core\interfaces\iCollection|string $collection, array $data, MMO\core\entities\Entity|array $filters = [], string $sorts = '', ?int $limit = null, ?int $offset = null ): ?MMO\core\entities\LogQuery
$originobject | string
$collectioniCollection | string
$dataarray
$filters = []Entity | array
$sorts = ''string
$limit = nullnull | int
$offset = nullnull | int
returnsnull | LogQuerynull if a listener marked the log as ignored (LogQuery::isIgnored)

offsetExists($key)

aRepository.php:257

\ArrayAccess::offsetExists

function offsetExists(mixed $key): bool
$keymixed
returnsbool
isset($repo['people']);

offsetGet($key)

aRepository.php:241

\ArrayAccess::offsetGet

function offsetGet(mixed $key): MMO\core\interfaces\iCollection
$keymixed
returnsiCollection
$repo['people']; // the 'people' collection

offsetUnset($key)

aRepository.php:233

\ArrayAccess::offsetUnset

function offsetUnset(mixed $key): void
$keymixed
returnsvoid
unset($repo['people']);

onCommit($commit)

abstractaRepository.php:33

Persist a batch of entity changes. Called automatically for every Commit dispatched with \MMO\commit(), but only for entities belonging to one of this repository's collections.

abstract function onCommit(MMO\core\events\Commit $commit): void
$commitCommit
returnsvoid

onFetch($event)

aRepository.php:400

Listener for Fetch: resolves a repository-uid/collection-id#id (or repository-uid/collection-id#id/nested/path for an embedded value) URL, what Entity::uid gives, into the matching entity (or nested value), if it belongs to one of this repository's collections and no earlier listener already answered the fetch.

function onFetch(MMO\core\events\Fetch $event): voidNOTE: the collection is found by its id, not by its name. They differ in a JsonRepository, whose collection `labels` has the id `labels.json` (its file's name). Looked up by name (2026-04 to 2026-09), a reference a JsonRepository had stored was never read back: the property was left null, and a find-or-create on it created a duplicate each time.
$eventFetch
returnsvoid
\MMO\fetch($this, $label->uid()); // $label, e.g. from `file://3f2a9c1b/labels.json#2`

searchText($query, $text)

aRepository.php:85

Full-text search. Not implemented at this level -- a concrete repository backed by a search-capable store should override this.

function searchText( MMO\core\interfaces\iCollection|MMO\core\entities\Query|string $query, string $text ): array
$queryiCollection | Query | string
$textstring
returnsarray
throwsalways, unless overridden

setCollections($cols)

aRepository.php:123

Register a batch of collections at once, e.g. from the repository's own configuration.

function setCollections(array $cols): void
$colsarray
returnsvoid
$repo->setCollections(['people' => Person::class, '!archive' => ArchivedPerson::class]);
Inherited members (3)
MethodsDeclared byDescription
dropCollection($collection)iRepository
executeQuery($query)iRepository
uid()iIdentifiableGet the unique identifier