'RecordTree', ]; private $serviceFactory; private $metadata; public function __construct(ServiceFactory $serviceFactory, Metadata $metadata) { $this->serviceFactory = $serviceFactory; $this->metadata = $metadata; } public function get(string $entityType): Record { if (!array_key_exists($entityType, $this->data)) { $this->load($entityType); } return $this->data[$entityType]; } private function load(string $entityType): void { if (!$this->metadata->get(['scopes', $entityType, 'entity'])) { throw new Error("Can't create record service {$entityType}, there's no such entity type."); } if ($this->serviceFactory->checkExists($entityType)) { $this->data[$entityType] = $this->serviceFactory->create($entityType); return; } $default = 'Record'; $type = $this->metadata->get(['scopes', $entityType, 'type']); if ($type) { $default = $this->defaultTypeMap[$type] ?? $default; } $obj = $this->serviceFactory->create($default); $obj->setEntityType($entityType); $this->data[$entityType] = $obj; } }