/** * get cached data * * @param string $siteKey site key * @param string $head root name * @return array */ protected function getData($siteKey, $head) { $key = $this->makeKey($siteKey, $head); if (!isset($this->bag[$key])) { $cacheKey = $this->getCacheKey($key); if (!($data = $this->cache->get($cacheKey))) { if (!($config = $this->repo->find($siteKey, $head))) { return []; } $descendant = $this->repo->fetchDescendant($siteKey, $head); $data = array_merge([$config], $descendant); $this->cache->put($cacheKey, $data); } $this->bag[$key] = $data; } return $this->bag[$key]; }
/** * get next level configs * * @param ConfigEntity $config config instance * @return array */ public function children(ConfigEntity $config) { $descendants = $this->repo->fetchDescendant($config->siteKey, $config->name); $children = []; /** @var ConfigEntity $descendant */ foreach ($descendants as $descendant) { if ($descendant->getDepth() == $config->getDepth() + 1) { $children[] = $this->build($descendant); } } return $children; }