/** * 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]; }
/** * Move entity hierarchy to new parent or root * * @param ConfigEntity $config config object * @param string|null $to parent name * @return ConfigEntity * @throws InvalidArgumentException * @throws NoParentException */ public function move(ConfigEntity $config, $to = null) { if ($to !== null && $this->repo->find($config->siteKey, $to) === null) { throw new InvalidArgumentException(['arg' => $to]); } $parent = $config->getParent(); if ($parent === null) { if ($config->getDepth() !== 1) { throw new NoParentException(); } $this->repo->affiliate($config, $to); } else { $this->repo->foster($config, $to); } $arrName = explode('.', $config->name); $key = array_pop($arrName); if ($to !== null) { $key = $to . '.' . $key; } return $this->get($key, false, $config->siteKey); }