Index

FilterGroup

MMO\core\helpers · 1 symbol · generated 30 Sep 2026

class

FilterGroup

Filter.php:325

A group of filters (or nested groups) combined with GroupOperator (AND/OR/NOR).

class MMO\core\helpers\FilterGroup implements MMO\core\interfaces\iFilter use MMO\core\classes\tArray
Namespace
MMO\core\helpers
Implements
iFilter
Uses traits
tArray
$g = new FilterGroup(GroupOperator::Or, ['name' => 'Marc'], ['name' => 'Bob']); $g->test(['name' => 'Bob']); // true

Index

content
operator
add($asserts)Append member filters/groups.
and($args)Add $args, combined with AND.
clear()
count()
getContent()
getIterator()\IteratorAggregate::getIterator
has($path)
isEmpty()
jsonSerialize()
keys()
loadArray($data)Load every entry of a plain array into the content, through offsetSet (so any offsetSet() override defined by the class using this trait, e.g.
loopByPath($path)Recursively find every member Filter (at any nesting depth) that has a condition on $path.
nor($args)Same as and, but combining with NOR (none of $args may match).
offsetExists($key)\ArrayAccess::offsetExists
offsetGet($key)\ArrayAccess::offsetGet
offsetSet($key, $value)\ArrayAccess::offsetSet -- a null $key appends ($bag[] = $value), like a plain PHP array.
offsetUnset($key)\ArrayAccess::offsetUnset -- on a list (sequential integer keys, as produced by $bag[] = ...), the element is spliced out (closing the gap and reindexing), matching \unset() semantics on a plain …
or($args)Same as and, but combining with OR.
simplify()Recursively simplify: merges sibling AND-combined single-Filter members that don't share any path into one Filter (fewer, more compact conditions with identical semantics), and collapses a group do…
test($data, $schema)
toArray()
toClosure($data, $schema)
__clone()
__construct($operator, $args)
__toString()

Properties2

content

protected $content = []

operator

MMO\core\helpers\GroupOperator $operator
Type
GroupOperator

Methods25

add($asserts)

Filter.php:440

Append member filters/groups. An empty array is silently skipped.

function add(MMO\core\interfaces\iFilter|array ...$asserts): self
...$assertsiFilter | array
returnsself$this, for chaining

and($args)

Filter.php:381

Add $args, combined with AND. If this group is already an AND group, they're added directly to it (returning $this); otherwise a new nested AND subgroup is created and added instead (returning the subgroup).

function and(MMO\core\interfaces\iFilter|array ...$args): self
...$argsiFilter | array
returnsself

count()

Filter.php:427
function count(): int
returnsinttotal number of leaf conditions, recursively (a nested group's own count is added, not counted as 1)

getContent()

Filter.php:351
function getContent(): array
returnsarrayraw list of member filters/groups

has($path)

Filter.php:368
function has(string $path): bool
$pathstring
returnsbooltrue if any member (recursively) has a condition on $path

isEmpty()

tArray.php:33
function isEmpty()
returnstrue if the underlying content has no elements
$bag->isEmpty(); // true right after clear(), false as soon as an item is set

jsonSerialize()

Filter.php:467
function jsonSerialize(): array
returnsarraysame as toArray, but without recursively expanding nested filters (left as objects, json_encode handles them)

keys()

tArray.php:82
function keys(): array
returnsarraythe list of keys currently set
$bag->keys(); // e.g. ['x', 0]

loadArray($data)

tArray.php:71

Load every entry of a plain array into the content, through offsetSet (so any offsetSet() override defined by the class using this trait, e.g. for validation or type coercion, is honored for every entry).

function loadArray(array $data): static
$dataarray
returnsstatic$this, for chaining
$bag->loadArray(['x' => 1, 'y' => 2]); // equivalent to $bag['x'] = 1; $bag['y'] = 2;

loopByPath($path)

Filter.php:360

Recursively find every member Filter (at any nesting depth) that has a condition on $path.

function loopByPath(string $path): Generator
$pathstring
returnsGenerator

nor($args)

Filter.php:405

Same as and, but combining with NOR (none of $args may match).

function nor(MMO\core\interfaces\iFilter|array ...$args): self
...$argsiFilter | array
returnsself

offsetExists($key)

tArray.php:130

\ArrayAccess::offsetExists

function offsetExists(mixed $key): bool
$keymixed
returnsbool

offsetSet($key, $value)

tArray.php:122

\ArrayAccess::offsetSet -- a null $key appends ($bag[] = $value), like a plain PHP array.

function offsetSet(mixed $key, mixed $value): void
$keymixed
$valuemixed
returnsvoid

offsetUnset($key)

tArray.php:107

\ArrayAccess::offsetUnset -- on a list (sequential integer keys, as produced by $bag[] = ...), the element is spliced out (closing the gap and reindexing), matching \unset() semantics on a plain PHP list; on an associative array, the key is simply removed.

function offsetUnset(mixed $key): void
$keymixed
returnsvoid
unset($bag[0]); // on a list: every following index shifts down by one, like array_splice()

simplify()

Filter.php:478

Recursively simplify: merges sibling AND-combined single-Filter members that don't share any path into one Filter (fewer, more compact conditions with identical semantics), and collapses a group down to its sole member if it ends up with just one (except a NOR group, which must keep its own negation).

function simplify(): MMO\core\interfaces\iFilter
returnsiFilterpossibly $this's simplified equivalent, or a single member Filter/FilterGroup if it collapsed to one
(new FilterGroup(GroupOperator::And, ['a' => 1], ['b' => 2]))->simplify(); // a single Filter {a:1, b:2}

toArray()

Filter.php:449
function toArray(): array
returnsarrayMongoDB-style, e.g. ['$or' => [['name' => 'Marc'], ['name' => 'Bob']]]

toClosure($data, $schema)

Filter.php:413
function toClosure(ArrayAccess|array $data, ?MMO\core\schemas\Schema $schema = null): Closure
$dataArrayAccess | array
$schema = nullnull | Schema
returnsClosurea zero-arg closure that calls test($data, $schema) when invoked

__toString()

Filter.php:458
function __toString(): string
returnsstringe.g. '((name = "Marc") | (name = "Bob"))', or '!(...)' for a NOR group