JsonRepository
MMO\core\entities · 1 symbol · generated 5 Oct 2026
JsonRepository
JsonRepository.php:24Collections container.
- Namespace
MMO\core\entities- Extends
- Repository
Index
| LAST_ID | the key under which a file keeps the highest id it gave, when its entities no longer tell it (onCommit) | |
| cachedUid | ||
| filenames | ||
| lastIds | ||
| collectionOf($url) | ||
| debugName() | ||
| dropCollection($collection) | Delete a collection's underlying JSON file entirely. | |
| generateId($collection) | Same as Repository::generateId, above every id the collection's file ever gave: an id is never given twice. | |
| getFilename($collection) | ||
| LastId($file) static | ||
| loadCollections() | Load every collection's data from its JSON file (a no-op collection stays empty if its file doesn't exist yet). | |
| onCommit($commit) | Persist every changed entity from this commit: grouped by their collection's file, merged into that file's existing (re-read) content, new ids assigned above the highest id the file ever gave (@see… | |
| onFetch($event) | Same as aRepository::onFetch, for the uid of one of its entities (file://3f2a9c1b/users.json#2) and for a reference as the files hold it (file://users.json#2, Refere… | |
| Reference($entity) static | How the files name an entity they hold: by its file's name and its id (<file://users.json#2>;label="Ada"), relative to the repository reading them (onFetch) -- as they always did. | |
| setCollections($cols) | Same as aRepository::setCollections, also loading each collection's data (loadCollections) once reference-resolution (the Fetch listener) is ready -- deferred to @s… | |
| uid() | file:// and a tag of the folders its files are in: its entities' uids (file://3f2a9c1b/users.json#2) are its own, and the same in every request. | |
| __construct($filenames, $collections) | ||
| __wakeup() | Same as aRepository::__wakeup, also (re)loading every collection's data from its file (loadCollections). |
Constants1
LAST_ID
the key under which a file keeps the highest id it gave, when its entities no longer tell it (onCommit)
Properties3
cachedUid
filenames
- Type
- array
lastIds
- Type
- array
Methods14
collectionOf($url)
JsonRepository.php:200| $url | string | an entity's uid, or a reference as the files hold it |
| returns | null | iCollection | the collection of this repository it names: with its uid (file://3f2a9c1b/users.json#2), or with its file's name alone (file://users.json#2) |
debugName()
JsonRepository.php:54| returns | string |
dropCollection($collection)
JsonRepository.php:233Delete a collection's underlying JSON file entirely.
| $collection | iCollection | string | |
| returns | bool |
generateId($collection)
JsonRepository.php:165Same as Repository::generateId, above every id the collection's file ever gave: an id is never given twice.
| $collection | iCollection | |
| returns | int |
getFilename($collection)
JsonRepository.php:86| $collection | iCollection | string | |
| returns | string | the resolved (absolute) JSON filename for a collection or its name. |
| throws | if unknown. |
LastId($file)
staticJsonRepository.php:151loadCollections()
JsonRepository.php:108Load every collection's data from its JSON file (a no-op collection stays empty if its file doesn't exist yet). Entities are built in two passes: first an empty, id-only instance for every record (so records can reference each other by entity, not just by id), then each one's real data is loaded in (re-invoking its own constructor) -- resolving those cross-references correctly regardless of file order.
| returns | void |
onCommit($commit)
JsonRepository.php:257Persist every changed entity from this commit: grouped by their collection's file, merged into that file's existing (re-read) content, new ids assigned above the highest id the file ever gave (generateId), then the whole file re-written (only if it actually changed) via JsonPrinter::EncodeFile (pretty-printed in dev mode).
onFetch($event)
JsonRepository.php:181Same as aRepository::onFetch, for the uid of one of its entities (file://3f2a9c1b/users.json#2) and for a reference as the files hold it (file://users.json#2, Reference).
Reference($entity)
staticJsonRepository.php:224How the files name an entity they hold: by its file's name and its id (<file://users.json#2>;label="Ada"), relative to the repository reading them (onFetch) -- as they always did. Its uid would tie them to their folder (uid), which could then no longer move. An entity of another kind of repository is named by its uid.
| $entity | Entity | |
| returns | string | its link (Entity::toLink), named that way |
setCollections($cols)
JsonRepository.php:94Same as aRepository::setCollections, also loading each collection's data (loadCollections) once reference-resolution (the Fetch listener) is ready -- deferred to __wakeup otherwise.
uid()
JsonRepository.php:67file:// and a tag of the folders its files are in: its entities' uids (file://3f2a9c1b/users.json#2) are its own, and the same in every request. The tag does not tell the folders: an entity's uid is in every API response.
| returns | string |
__construct($filenames, $collections)
JsonRepository.php:43| $filenames | array | collection name => JSON filename (resolved via filename). |
| $collections = [] | array | see aRepository::setCollections. |
__wakeup()
JsonRepository.php:49Same as aRepository::__wakeup, also (re)loading every collection's data from its file (loadCollections).
| returns | void |
Inherited members (25)
| Properties | Declared by | Description | |
|---|---|---|---|
collections | aRepository |
| Methods | Declared by | Description | |
|---|---|---|---|
addCollection($name, $collection) | aRepository | Add collection | |
createCollection($name, $entityClass, $collectionId) | aRepository | Create and register a plain Collection for entities of $entityClass. | |
createEntity($class, $data, $collection) | Repository | Same as aRepository::createEntity, auto-assigning the next id (generateId) if $data has none. | |
createLog($type, $origin, $collection, $data, $filters, $sorts, $limit, $offset) | aRepository | Build (but not dispatch) a LogQuery entity describing a data-mutating operation, stored in the repository's LogQuery collection (if one is registered). | |
executeQuery($query, $opts) | Repository | Find entities by content (delegates to the collection's own in-memory filtering -- see Collection::executeQuery). | |
forceCommit($origin, $entities) | aRepository | ||
getCollection($name) | aRepository | ||
getCollectionByClass($entityClass, $allowChildClass) | aRepository | Find the collection whose entities are (an exact match, or optionally a subclass of) $entityClass. | |
getCollectionName($collection) | aRepository | ||
getCollections() | aRepository | ||
getDistinct($collection, $key) | aRepository | Every value one property takes across a collection, once each, in ascending order. | |
getEntities() | aRepository | ||
getIterator() | aRepository | \IteratorAggregate::getIterator -- iterates name => iCollection | |
hasCollection($collection) | aRepository | ||
hideLogData($collection, $data) | aRepository | 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) | aRepository | Log and dispatch a DELETE operation. | |
logInsert($origin, $collection, $data, $filters, $sorts, $limit, $offset) | aRepository | Log and dispatch an INSERT operation. | |
logStatus($origin, $collection, $data, $filters, $sorts, $limit, $offset) | aRepository | Log and dispatch a STATUS-change operation. | |
logUpdate($origin, $collection, $data, $filters, $sorts, $limit, $offset) | aRepository | Log and dispatch an UPDATE operation. | |
offsetExists($key) | aRepository | \ArrayAccess::offsetExists | |
offsetGet($key) | aRepository | \ArrayAccess::offsetGet | |
offsetSet($key, $value) | aRepository | \ArrayAccess::offsetSet -- equivalent to addCollection | |
offsetUnset($key) | aRepository | \ArrayAccess::offsetUnset | |
searchText($query, $text) | aRepository | Full-text search. Not implemented at this level -- a concrete repository backed by a search-capable store should override this. |