/** * Returns descendant of item * * @param Permission $item permission instance * @return array */ public function fetchDescendant(Permission $item) { $key = $this->getCacheKey($item->siteKey, $item->name, 'descendant'); if (!($descendants = $this->cache->get($key))) { $descendants = $this->repo->fetchDescendant($item); if (!empty($descendants)) { $this->cache->put($key, $descendants); } } return $descendants; }
/** * 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 (!($item = $this->repo->findByName($siteKey, $head))) { return []; } $descendant = $this->repo->fetchDescendant($siteKey, $head); $data = array_merge([$item], $descendant); $this->cache->put($cacheKey, $data); } $this->bag[$key] = $data; } return $this->bag[$key]; }
/** * Returns descendant of item * * @param Permission $item permission instance * @return array */ public function fetchDescendant(Permission $item) { return $this->repo->fetchDescendant($item); }