Methods19
Add 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).
function addEntity(MMO\core\interfaces\iEntity $entity): MMO\core\interfaces\iEntity$basket->addEntity($product); // indexed under $product->getId()
Merge $opts into the existing options (through merge), rather than replacing them wholesale like setOptions.
function addOptions(array $opts, bool $appendList = false): void| $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 | |
$t->setOptions(['a' => 1, 'tags' => ['x']]);
$t->addOptions(['b' => 2, 'tags' => ['y']]);
$t->getOptions(); // ['a' => 1, 'tags' => ['y'], 'b' => 2] -- 'tags' is replaced, not appended ($appendList=false)
Empty the options bag.
function clearOptions(): void$t->clearOptions(); // getOptions() === []
\Countable::count -- number of entities in this commit
function count(): intfunction getEntities(): array| returns | array | every entity currently in the collection, keyed by id (or numeric index -- see addEntity) |
function getEntitiesWithFlags(int $flags): array| $flags | int | a bitmask of iEntity::FLAG_* constants |
| returns | array | only the entities whose getFlags() has EVERY bit of $flags set |
$basket->getEntitiesWithFlags(iEntity::FLAG_CREATED); // entities created during this request
function getEntity(string|int $id): ?MMO\core\interfaces\iEntity$basket->getEntity('p1');
function getOption(string $key, mixed $default = null): mixed$t->getOption('a', 'fallback'); // the current value of 'a', or 'fallback' if not set
function getOptions(): array| returns | array | every option currently set |
$t->getOptions(); // ['a' => 1, 'tags' => ['x']]
function hasEntity(MMO\core\interfaces\iEntity|string|int $entity): bool| $entity | iEntity | string | int | either an entity instance (checked by identity) or an id (checked by key) |
| returns | bool | |
$basket->hasEntity($product); // by instance$basket->hasEntity($product->getId()); // by id
function isDryRun(): bool| returns | bool | true if the 'dryRun' option is set: repositories should validate but not actually persist |
function isPropagationStopped(): boolRemove entity by instance or uid
function removeEntity(MMO\core\interfaces\iEntity|string|int $entity): ?MMO\core\interfaces\iEntity$basket->removeEntity($product); // by instance: removes every key it was indexed under$basket->removeEntity('p1'); // by id
Set (or, with a null $value, remove) a single option.
function setOption(string $key, mixed $value): void| $key | string | |
| $value | mixed | if null, the option is unset entirely rather than being set to null |
| returns | void | |
$t->setOption('a', 1);$t->setOption('a', null); // removes 'a' from getOptions()
Replace the whole options bag.
function setOptions(array $opts): void$t->setOptions(['a' => 1]);
Sort entities so entity without id are stored before any others.
function sortEntities()NOTE: among two entities that both lack an id, this was meant to further order them so that one referenced
by the other commits first (avoiding a dangling reference) -- but the method it called for that,
iEntity::hasReference(), does not exist anywhere in the codebase, so this always crashed with "Call to
undefined method" as soon as a commit actually contained two new (unsaved) entities. Since correctly
detecting one entity's outbound reference to another isn't something this trait can safely reconstruct,
the tie-break degrades to "equal" (0) instead of crashing -- the primary id-based ordering still works.Prevent any remaining listener in the current dispatch chain from being called.
function stopPropagation()A cloned event starts fresh: propagation is never considered stopped on the clone, even if it was on the original instance.
function __clone()function __construct(object|string $origin, array $options = [])