useCache = $config->get('useCache'); } /** * @return AclDependencyItem[] */ public function get(): array { if ($this->data === null) { $this->data = $this->loadData(); } return $this->data; } /** * @return AclDependencyItem[] */ private function loadData(): array { if ($this->useCache && $this->dataCache->has(self::CACHE_KEY)) { /** @var array[] $raw */ $raw = $this->dataCache->get(self::CACHE_KEY); return $this->buildFromRaw($raw); } return $this->buildData(); } /** * @return AclDependencyItem[] */ private function buildData(): array { $data = []; foreach (($this->metadata->get(['app', 'language', 'aclDependencies']) ?? []) as $target => $item) { $anyScopeList = $item['anyScopeList'] ?? null; $scope = $item['scope'] ?? null; $field = $item['field'] ?? null; $data[] = [ 'target' => $target, 'anyScopeList' => $anyScopeList, 'scope' => $scope, 'field' => $field, ]; } foreach ($this->ormDefs->getEntityList() as $entityDefs) { if (!$this->metadata->get(['scopes', $entityDefs->getName(), 'object'])) { continue; } foreach ($entityDefs->getFieldList() as $fieldDefs) { if (!in_array($fieldDefs->getType(), $this->enumFieldTypeList)) { continue; } $optionsReference = $fieldDefs->getParam('optionsReference'); if (!$optionsReference || !str_contains($optionsReference, '.')) { continue; } [$refEntityType, $refField] = explode('.', $optionsReference); $target = "{$refEntityType}.options.{$refField}"; $data[] = [ 'target' => $target, 'anyScopeList' => null, 'scope' => $entityDefs->getName(), 'field' => $fieldDefs->getName(), ]; } } if ($this->useCache) { $this->dataCache->store(self::CACHE_KEY, $data); } return $this->buildFromRaw($data); } /** * @param array[] $raw * @return AclDependencyItem[] */ private function buildFromRaw(array $raw): array { $list = []; foreach ($raw as $rawItem) { $target = $rawItem['target'] ?? null; $anyScopeList = $rawItem['anyScopeList'] ?? null; $scope = $rawItem['scope'] ?? null; $field = $rawItem['field'] ?? null; $list[] = new AclDependencyItem($target, $anyScopeList, $scope, $field); } return $list; } }