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