class EntityLookupService (View source)

Service for looking up entities by ID with lazy indexing and caching.

Extracted from AbstractClassCheck to enable reuse without inheritance.

The index is cached per storage object, shared across every instance of this service. That matters because ValidatorTestBase constructs a fresh check — and therefore a fresh service — for every data-provider row, so an instance-level index was rebuilt and thrown away once per test case: a full linear scan of the storage (thousands of entities) per lookup. Sharing is safe because the index is a pure function of the storage contents.

A WeakMap keyed on the storage object is used rather than spl_object_id(): object ids are reused once an object is freed, so an id-keyed cache could hand back the index of an unrelated storage that happened to reuse the id. WeakMap entries also disappear with the storage, so nothing is retained after a test's mock storage goes out of scope.

Caveat: the index snapshots the storage the first time a kind is queried. Storages are read-only during validation, so this holds; a caller that mutates a storage after a lookup must call clearIndexCache().

Methods

static void
clearIndexCache()

Discards every cached index. Only needed when a storage is mutated after being queried, or to guarantee isolation between tests that reuse a storage instance.

PHPClass|null
findClassById(StubDataQueryInterface $storage, string $entityId)

No description

PHPEnum|null
findEnumById(StubDataQueryInterface $storage, string $entityId)

No description

findInterfaceById(StubDataQueryInterface $storage, string $entityId)

No description

findFunctionById(StubDataQueryInterface $storage, string $entityId)

No description

findConstantById(StubDataQueryInterface $storage, string $entityId)

No description

array|null
findAnyEntityById(StubDataQueryInterface $storage, string $entityId)

Find an entity by ID across all entity collections (class, interface, enum, function).

Details

static void clearIndexCache()

Discards every cached index. Only needed when a storage is mutated after being queried, or to guarantee isolation between tests that reuse a storage instance.

Return Value

void

PHPClass|null findClassById(StubDataQueryInterface $storage, string $entityId)

No description

Parameters

StubDataQueryInterface $storage
string $entityId

Return Value

PHPClass|null

PHPEnum|null findEnumById(StubDataQueryInterface $storage, string $entityId)

No description

Parameters

StubDataQueryInterface $storage
string $entityId

Return Value

PHPEnum|null

PHPInterface|null findInterfaceById(StubDataQueryInterface $storage, string $entityId)

No description

Parameters

StubDataQueryInterface $storage
string $entityId

Return Value

PHPInterface|null

PHPFunction|null findFunctionById(StubDataQueryInterface $storage, string $entityId)

No description

Parameters

StubDataQueryInterface $storage
string $entityId

Return Value

PHPFunction|null

PHPConstant|null findConstantById(StubDataQueryInterface $storage, string $entityId)

No description

Parameters

StubDataQueryInterface $storage
string $entityId

Return Value

PHPConstant|null

array|null findAnyEntityById(StubDataQueryInterface $storage, string $entityId)

Find an entity by ID across all entity collections (class, interface, enum, function).

Parameters

StubDataQueryInterface $storage
string $entityId

Return Value

array|null

Pair [entity, entityType], or null if not found