Query
MMO\core\entities · 1 symbol · generated 5 Oct 2026
Query
Query.php:22Generic way to query a collection of entities.
- Namespace
MMO\core\entities- Implements
- IteratorAggregate, Stringable, iSignal
- Uses traits
- tEvent, tWithOptions
Index
| collection | ||
| customExecute | Custom function for execution function(Query $query, array $options) | |
| entities | ||
| fields | ||
| filters | Filter options A list of operators and/or array of json path/values. | |
| isList | ||
| limit | ||
| Listeners static | ||
| offset | Pagination | |
| opts | ||
| sorts | ||
| total | ||
| AddListener($handler, $order) static | Register a listener directly (as opposed to ConnectListeners's attribute-based discovery). | |
| addOptions($opts, $appendList) | Merge $opts into the existing options (through merge), rather than replacing them wholesale like setOptions. | |
| and($args) | Add one or more AND-combined filter conditions. | |
| applySort() | Re-sort the already-run results in memory by $sorts (defaulting to id descending if none set) -- useful when the entities' order needs to reflect a change made after the query ran (e.g. | |
| clear($clearSorts) | Reset the query to a blank slate: no results, filters, fields, offset, or limit. | |
| clearEntities() | Discard any already-run results (and the cached $total), so the next execute/getReturn re-runs the query. | |
| clearOptions() | Empty the options bag. | |
| ConnectListeners($obj) static | Scan $obj's methods for #[Listen(EventClass::class)] attributes and register each one as a listener on the matching event class. | |
| debugName() | ||
| DisconnectListeners($obj) static | Undo a previous ConnectListeners: removes every listener that connect had registered for $obj on this event class. | |
| dispatch() | Invoke every GetListeners listener with $this. | |
| execute($opts) | Execute a query | |
| field($path, $visible) | ||
| filter($filter) | Add a filter condition to this query's root filter group ($filters, an AND group by default). | |
| getEntities() | ||
| getFields() | ||
| getIterator() | \IteratorAggregate::getIterator -- the query's results (running it first if needed -- see getReturn), as a \Traversable either way. | |
| GetListeners() static | Collect every listener for this class, including those registered on its parent classes (so a subclass event is also caught by listeners of its parent event), sorted by ascending $order (ties keep … | |
| getOption($key, $default) | ||
| getOptions() | ||
| getOrigin() | ||
| getReturn() | ||
| getSorts() | ||
| getVisibleFields() | Resolve getFields into the actual list of field names that should be shown: with no explicit selection, every schema-declared visible property; with an explicit selection that only HIDES field… | |
| hasFilters() | ||
| HasListener($handler) static | ||
| isListOnly() | ||
| isRaw() | Tells if query's entities will be returned as an array (raw) instead of Entity | |
| listOnly() | Only list entities (return entity's id and properties needed in title and label) | |
| listRequiredCollections($filter) | List all the other required collections needed for the query | |
| loopRequiredCollection($repository, $schema, $path, $_recusivePath) | Recursion helper for listRequiredCollections: walks a single filter path's schema, yielding the collection behind each instance-typed segment it crosses -- including, for a computed 'label'/'t… | |
| nor($args) | Add one or more NOR-combined filter conditions. | |
| or($args) | Add one or more OR-combined filter conditions. | |
| pagination($limit, $offset) | ||
| RemoveListener($handler) static | Remove the last added handler from the listeners. | |
| Send($args) static | Construct a new instance of this class with $args, then dispatch it to every listener. | |
| setFields($value) | NOTE: same bug (and fix) as setSorts -- used to check $value[0] instead of $field[0], so a --prefixed field (meant to hide it) was only ever recognized when it was the very first field i… | |
| SetListenerOrder($handler, $order) static | Change the order of an already-registered listener, whether added directly via AddListener or indirectly via ConnectListeners (which also stores its [$obj, $methodName] callables here). | |
| setListOnly($value) | ||
| setOption($key, $value) | Set (or, with a null $value, remove) a single option. | |
| setOptions($opts) | Replace the whole options bag. | |
| setRaw($raw) | ||
| setReturn($entities) | ||
| setRootOperator($operator) | Change the root filter group's combining operator, wrapping the existing filters in a new group under $operator if it differs from the current one. | |
| setSorts($value) | NOTE: this used to check $value[0] === '-' (the LIST's own first element) inside the foreach ($value as $field) loop, instead of $field[0] (the CURRENT field being examined) -- so, except for… | |
| sort($path, $asc) | NOTE: $asc used to be typed bool (non-nullable), so the $asc === null check below could never be true -- PHP rejects passing null for a non-nullable parameter with a TypeError before the me… | |
| __clone() | Deep-clones $filters (so mutating the clone's filters doesn't affect the original) and discards any already-run results (clearEntities). | |
| __construct($collection, $filter, $fields, $sort, $limit, $offset, $options) | ||
| __toString() |
Properties12
collection
- Type
- iCollection
customExecute
Custom function for execution function(Query $query, array $options)
entities
fields
- Type
- array
filters
Filter options A list of operators and/or array of json path/values.
- Type
- FilterGroup
isList
- Type
- bool
limit
Listeners
static- Type
- array
offset
Pagination
opts
- Type
- array
sorts
- Type
- array
total
Methods49
AddListener($handler, $order)
statictEvent.php:62Register a listener directly (as opposed to ConnectListeners's attribute-based discovery).
| $handler | callable | called as $handler($eventInstance) when this event class is Send / dispatch-ed |
| $order = 0 | int | listeners run in ascending order (lower first); listeners with an equal order run in the order they were added |
| returns | void |
addOptions($opts, $appendList)
tWithOptions.php:65Merge $opts into the existing options (through merge), rather than replacing them wholesale like setOptions.
| $opts | array | the options to merge in |
| $appendList = false | bool | if true, a list-valued option is appended to (rather than replaced by) the corresponding list in $opts -- see \MMO\core\arrays\merge for the exact semantics |
| returns | void |
and($args)
Query.php:445Add one or more AND-combined filter conditions. FilterGroup::and
applySort()
Query.php:299Re-sort the already-run results in memory by $sorts (defaulting to id descending if none set) -- useful when the entities' order needs to reflect a change made after the query ran (e.g. a listener mutated some values), since the repository-side sort can't see that.
| returns | void |
clear($clearSorts)
Query.php:166Reset the query to a blank slate: no results, filters, fields, offset, or limit. @param bool $clearSorts if true, also clear the sort order (kept by default).
clearEntities()
Query.php:160Discard any already-run results (and the cached $total), so the next execute/getReturn re-runs the query.
| returns | void |
clearOptions()
tWithOptions.php:39Empty the options bag.
| returns | void |
ConnectListeners($obj)
statictEvent.php:37Scan $obj's methods for #[Listen(EventClass::class)] attributes and register each one as a listener on the matching event class. connect does the actual reflection/registration.
debugName()
Query.php:120| returns | string |
DisconnectListeners($obj)
statictEvent.php:49Undo a previous ConnectListeners: removes every listener that connect had registered for $obj on this event class.
dispatch()
tEvent.php:153Invoke every GetListeners listener with $this. If the class also implements PSR-14's StoppableEventInterface, dispatch stops early as soon as isPropagationStopped() becomes true.
| returns | static | $this, for chaining |
execute($opts)
Query.php:99Execute a query
field($path, $visible)
Query.php:370filter($filter)
Query.php:438Add a filter condition to this query's root filter group ($filters, an AND group by default). @return iFilter $filter itself, normalized.
getEntities()
Query.php:153| returns | array | the query's results (running it first if needed), materialized as a plain array (consuming/caching a lazy iterable's items). |
getFields()
Query.php:318getIterator()
Query.php:145\IteratorAggregate::getIterator -- the query's results (running it first if needed -- see getReturn), as a \Traversable either way.
| returns | Traversable | T> |
GetListeners()
statictEvent.php:123Collect every listener for this class, including those registered on its parent classes (so a subclass event is also caught by listeners of its parent event), sorted by ascending $order (ties keep insertion order).
| returns | array | [[callable $handler, int $order], ...] |
getOption($key, $default)
tWithOptions.php:49getOptions()
tWithOptions.php:20| returns | array | every option currently set |
getOrigin()
Query.php:90| returns | object | string | this query's $collection (an iSignal/tEvent origin). |
getReturn()
Query.php:111- See
iSignal::getReturn-- the query's results, running it first (execute) if it hasn't been already.
| returns | iterable |
getSorts()
Query.php:250| returns | array | the sort order, field => ascending. |
getVisibleFields()
Query.php:328Resolve getFields into the actual list of field names that should be shown: with no explicit selection, every schema-declared visible property; with an explicit selection that only HIDES fields (no explicit true entries), every visible property minus those; otherwise, just the explicitly true fields.
| returns | array |
hasFilters()
Query.php:136| returns | bool | whether any filter condition has been added. |
HasListener($handler)
statictEvent.php:109| $handler | callable | object | either the exact callable passed to AddListener, or (for a [$obj, $methodName] listener registered via ConnectListeners) just the object, to check whether any of its methods are currently listening |
| returns | bool |
isListOnly()
Query.php:422isRaw()
Query.php:411Tells if query's entities will be returned as an array (raw) instead of Entity
| returns | bool |
listOnly()
Query.php:380Only list entities (return entity's id and properties needed in title and label)
| returns | self |
listRequiredCollections($filter)
Query.php:223List all the other required collections needed for the query
loopRequiredCollection($repository, $schema, $path, $_recusivePath)
Query.php:186Recursion helper for listRequiredCollections: walks a single filter path's schema, yielding the collection behind each instance-typed segment it crosses -- including, for a computed 'label'/'title' segment (or when already recursing through one), the collections behind whatever properties that label/title template itself references.
nor($args)
Query.php:453Add one or more NOR-combined filter conditions. FilterGroup::nor
or($args)
Query.php:449Add one or more OR-combined filter conditions. FilterGroup::or
pagination($limit, $offset)
Query.php:431RemoveListener($handler)
statictEvent.php:91Remove the last added handler from the listeners.
Send($args)
statictEvent.php:143Construct a new instance of this class with $args, then dispatch it to every listener.
setFields($value)
Query.php:353NOTE: same bug (and fix) as setSorts -- used to check $value[0] instead of $field[0], so a --prefixed field (meant to hide it) was only ever recognized when it was the very first field in the list; every other -field kept its literal - as part of the (wrong) key and was always marked visible.
SetListenerOrder($handler, $order)
statictEvent.php:75Change the order of an already-registered listener, whether added directly via AddListener or indirectly via ConnectListeners (which also stores its [$obj, $methodName] callables here).
setListOnly($value)
Query.php:402| $value | bool | |
| returns | self | set isListOnly directly, without listOnly's other side effects (field/filter/sort setup). |
setOption($key, $value)
tWithOptions.php:77Set (or, with a null $value, remove) a single option.
setOptions($opts)
tWithOptions.php:30Replace the whole options bag.
setRaw($raw)
Query.php:416setReturn($entities)
Query.php:116- See
iSignal::setReturn-- e.g. for a listener to override the query's results.
setRootOperator($operator)
Query.php:458Change the root filter group's combining operator, wrapping the existing filters in a new group under $operator if it differs from the current one.
| $operator | GroupOperator | string | |
| returns | self |
setSorts($value)
Query.php:265NOTE: this used to check $value[0] === '-' (the LIST's own first element) inside the foreach ($value as $field) loop, instead of $field[0] (the CURRENT field being examined) -- so, except for the first field in the list, a --prefixed field (meant to sort that field descending) was never recognized as such: the leading - stayed part of the (wrong) sort key, and every field got true (ascending) regardless.
sort($path, $asc)
Query.php:287NOTE: $asc used to be typed bool (non-nullable), so the $asc === null check below could never be true -- PHP rejects passing null for a non-nullable parameter with a TypeError before the method body ever runs -- making "remove this sort" (the clear intent, matching the identical, correctly ?bool-typed pattern in the sibling field method) completely unreachable. Fixed to ?bool.
__clone()
Query.php:125Deep-clones $filters (so mutating the clone's filters doesn't affect the original) and discards any already-run results (clearEntities).
| returns | void |