*/ class Loader implements LoaderInterface { /** @var array */ private array $fieldListCacheMap = []; public function __construct(private OrmDefs $ormDefs) {} public function process(Entity $entity, Params $params): void { if (!$entity instanceof CoreEntity) { return; } foreach ($this->getFieldList($entity->getEntityType()) as $field) { $entity->loadParentNameField($field); } } /** * @return string[] */ private function getFieldList(string $entityType): array { if (array_key_exists($entityType, $this->fieldListCacheMap)) { return $this->fieldListCacheMap[$entityType]; } $list = []; $entityDefs = $this->ormDefs->getEntity($entityType); foreach ($entityDefs->getFieldList() as $fieldDefs) { if ($fieldDefs->getType() !== 'linkParent') { continue; } $name = $fieldDefs->getName(); if (!$entityDefs->hasRelation($fieldDefs->getName())) { // Otherwise, loadParentNameField produces an error. // @todo Revise. continue; } $list[] = $name; } $this->fieldListCacheMap[$entityType] = $list; return $list; } }