Collection
MMO\core\entities · 1 symbol · generated 5 Oct 2026
Collection
Collection.php:29Entity container.
- Namespace
MMO\core\entities- Implements
- iCollection
- Uses traits
- tWithEntities
Index
| entities | ||
| entityClass | ||
| id | ||
| readonly | ||
| repository | ||
| schema | ||
| add($entities) | Load one or more entities into this collection (tWithEntities::addEntity). | |
| addEntity($entity) | Add an entity, indexed under its own iEntity::getId(). | |
| clear() | Detach every loaded entity from this collection and forget them (doesn't delete anything from the repository). | |
| count() | ||
| createEntity($data) | ||
| debugName() | ||
| drop($clear) | Delete this whole collection from its repository. | |
| executeFilter($filter, $sorts, $limit, $offset) | Execute the filter locally (ONLY on the entity loaded in the collection). | |
| executeQuery($query, $opts) | Execute the query locally (ONLY on the entity loaded in the collection). | |
| find($filter, $fields, $sort, $limit, $offset, $options) | Run a query (via the repository, if any -- see Repository::executeQuery) and return the matching entities, loading each into this collection (or reusing the already-loaded instance for a given… | |
| findOne($filter, $fields, $sort, $offset, $options) | Same as find, limited to (and returning) a single entity, or null if none match. | |
| getById($id, $find) | Get an entity by id | |
| getEntities() | ||
| getEntitiesWithFlags($flags) | ||
| getEntity($id) | ||
| getEntityClass() | ||
| getId() | ||
| getName() | Get the name of this collection in the repository. | |
| getOrCreateEntity($data, $local, $coerce) | Try to find a similar entity from data or create the entity | |
| getRepository() | ||
| getSchema() | ||
| getSearchProperty($name) | ||
| getSimilarEntity($data, $local, $coerce) | Find an entity using its unique properties (declared with @unique in the doc comment of the class) | |
| has($entity) | ||
| hasChanged($flags) | ||
| hasEntity($entity) | ||
| isRegisterCommit() | ||
| jsonSerialize($opts) | ||
| localFind($filter, $sorts, $limit, $offset) | Find locally (ONLY on the entity loaded in the collection). | |
| localFindOne($filter, $sorts, $offset) | Find locally (ONLY on the entity loaded in the collection). | |
| onCommit($request) | ||
| query($filter, $fields, $sort, $limit, $offset, $options) | Build a Query against this collection (not executed until iterated -- see find/findOne for that). | |
| registerCommit($register) | Start (or, with $register false, stop) listening for Commit events, so this collection's own changed entities get added to them automatically (onCommit). | |
| removeEntity($entity) | Remove entity by instance or uid | |
| setEntityClass($class) | ||
| setId($id) | ||
| setRepository($repo) | ||
| setSchema($schema) | Override the schema used for this collection's entities (getSchema normally derives it from getEntityClass instead). | |
| uid() | ||
| __construct($class, $repo, $id) |
Properties6
entities
entityClass
- Type
- string
id
readonly
- Type
- bool
repository
- Type
- null | iRepository
schema
Methods40
add($entities)
Collection.php:234Load one or more entities into this collection (tWithEntities::addEntity).
addEntity($entity)
tWithEntities.php:70Add an entity, indexed under its own iEntity::getId(). An entity with no id (getId() === '' once cast to string), or whose id already maps to a DIFFERENT entity instance, is appended under a plain numeric index instead -- re-adding the SAME instance under an id it already occupies simply overwrites it in place (no duplicate is created).
clear()
Collection.php:140Detach every loaded entity from this collection and forget them (doesn't delete anything from the repository).
| returns | void |
count()
Collection.php:55| returns | int | the number of entities currently loaded (NOT the total count in the underlying repository -- see Query::$total for that). |
createEntity($data)
Collection.php:176debugName()
Collection.php:84| returns | string |
drop($clear)
Collection.php:152Delete this whole collection from its repository.
executeFilter($filter, $sorts, $limit, $offset)
Collection.php:346Execute the filter locally (ONLY on the entity loaded in the collection).
executeQuery($query, $opts)
Collection.php:382Execute the query locally (ONLY on the entity loaded in the collection).
find($filter, $fields, $sort, $limit, $offset, $options)
Collection.php:288Run a query (via the repository, if any -- see Repository::executeQuery) and return the matching entities, loading each into this collection (or reusing the already-loaded instance for a given id).
findOne($filter, $fields, $sort, $offset, $options)
Collection.php:273Same as find, limited to (and returning) a single entity, or null if none match.
getById($id, $find)
Collection.php:246Get an entity by id
getEntities()
tWithEntities.php:25getEntitiesWithFlags($flags)
tWithEntities.php:34| $flags | int | a bitmask of iEntity::FLAG_* constants |
| returns | array | only the entities whose getFlags() has EVERY bit of $flags set |
getEntity($id)
tWithEntities.php:57getEntityClass()
Collection.php:106| returns | string | the entity class this collection holds. |
getId()
Collection.php:60getName()
Collection.php:70Get the name of this collection in the repository.
getOrCreateEntity($data, $local, $coerce)
Collection.php:229Try to find a similar entity from data or create the entity
getRepository()
Collection.php:89| returns | null | iRepository | the repository this collection belongs to. |
getSchema()
Collection.php:127getSearchProperty($name)
Collection.php:121| $name | string | |
| returns | SearchProperty | the entity class's declared search behavior for property $name. |
getSimilarEntity($data, $local, $coerce)
Collection.php:187Find an entity using its unique properties (declared with @unique in the doc comment of the class)
has($entity)
Collection.php:257hasChanged($flags)
Collection.php:164| $flags = 7 | int | which iEntity::FLAG_* flags count as "changed" (default: changed, removed, or created). |
| returns | bool | true if any loaded entity has one of them set. |
hasEntity($entity)
tWithEntities.php:48| $entity | iEntity | string | int | either an entity instance (checked by identity) or an id (checked by key) |
| returns | bool |
isRegisterCommit()
Collection.php:402| returns | bool | whether registerCommit's listener is currently active. |
jsonSerialize($opts)
Collection.php:135localFind($filter, $sorts, $limit, $offset)
Collection.php:308Find locally (ONLY on the entity loaded in the collection).
localFindOne($filter, $sorts, $offset)
Collection.php:327Find locally (ONLY on the entity loaded in the collection).
onCommit($request)
Collection.php:407- See
Commitlistener: add every changed/removed/created loaded entity to the commit.
query($filter, $fields, $sort, $limit, $offset, $options)
Collection.php:265Build a Query against this collection (not executed until iterated -- see find/findOne for that).
registerCommit($register)
Collection.php:393Start (or, with $register false, stop) listening for Commit events, so this collection's own changed entities get added to them automatically (onCommit). Called once by the constructor.
removeEntity($entity)
tWithEntities.php:87Remove entity by instance or uid
| $entity | iEntity | string | int | the entity to remove or its id |
| returns | null | iEntity | null if it was not found in the collection |
setEntityClass($class)
Collection.php:113setId($id)
Collection.php:75setRepository($repo)
Collection.php:94| $repo | null | iRepository | |
| returns | void |
setSchema($schema)
Collection.php:99Override the schema used for this collection's entities (getSchema normally derives it from getEntityClass instead). @param ?Schema $schema
uid()
Collection.php:80| returns | string | a globally-unique reference: the repository's own uid, '/', and this collection's id. |