Index

tWithEntities

MMO\core\classes · 1 symbol · generated 5 Oct 2026

trait

tWithEntities

tWithEntities.php:18

Gives a class its own local collection of iEntity instances, indexed by iEntity::getId when available (falling back to a plain numeric index for entities without an id, or when two different entity instances collide on the same id).

trait MMO\core\classes\tWithEntities
Namespace
MMO\core\classes
NOTE: [`getEntitiesWithFlags`](https://mcp.mmoframework.fr/documentation/mmo.core/php/classes/tWithEntities.md#twithentities-getentitieswithflags) calls `$entity->getFlags()`, which is not part of the iEntity interface itself but is provided by concrete entities built on [`aEntity`](https://mcp.mmoframework.fr/documentation/mmo.core/php/classes/aEntity.md#aentity) (e.g. [`Entity`](https://mcp.mmoframework.fr/documentation/mmo.core/php/entities/Entity.md#entity)).
class Basket {use tWithEntities;} $basket = new Basket(); $basket->addEntity($product); // indexed under $product->getId() $basket->getEntity($product->getId()) === $product; // true

Properties1

entities

protected $entities = []

Methods6

addEntity($entity)

tWithEntities.php:70

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
$entityiEntity
returnsiEntity$entity, for chaining
$basket->addEntity($product); // indexed under $product->getId()

getEntitiesWithFlags($flags)

tWithEntities.php:34
function getEntitiesWithFlags(int $flags): array
$flagsinta bitmask of iEntity::FLAG_* constants
returnsarrayonly the entities whose getFlags() has EVERY bit of $flags set
$basket->getEntitiesWithFlags(iEntity::FLAG_CREATED); // entities created during this request

hasEntity($entity)

tWithEntities.php:48
function hasEntity(MMO\core\interfaces\iEntity|string|int $entity): bool
$entityiEntity | string | inteither an entity instance (checked by identity) or an id (checked by key)
returnsbool
$basket->hasEntity($product); // by instance$basket->hasEntity($product->getId()); // by id

removeEntity($entity)

tWithEntities.php:87

Remove entity by instance or uid

function removeEntity(MMO\core\interfaces\iEntity|string|int $entity): ?MMO\core\interfaces\iEntity
$entityiEntity | string | intthe entity to remove or its id
returnsnull | iEntitynull if it was not found in the collection
$basket->removeEntity($product); // by instance: removes every key it was indexed under$basket->removeEntity('p1'); // by id