findByName() public method

Find a registered by type and name
public findByName ( string $siteKey, string $name ) : Permission
$siteKey string site key
$name string target name
return Permission
コード例 #1
0
 /**
  * Find a registered by type and name
  *
  * @param string $siteKey site key
  * @param string $name    target name
  * @return Permission
  */
 public function findByName($siteKey, $name)
 {
     $key = $this->getCacheKey($siteKey, $name);
     if (!($permission = $this->cache->get($key))) {
         if ($permission = $this->repo->findByName($siteKey, $name)) {
             $this->cache->put($key, $permission);
         }
     }
     return $permission;
 }
コード例 #2
0
 /**
  * Find a registered by type and name
  *
  * @param string $siteKey site key
  * @param string $name    target name
  * @return Permission
  */
 public function findByName($siteKey, $name)
 {
     $key = $this->getKey($siteKey, $name);
     if (!isset($this->bag[$key])) {
         if ($perm = $this->repo->findByName($siteKey, $name)) {
             $this->bag[$key] = $perm;
         } else {
             return null;
         }
     }
     return $this->bag[$key];
 }
コード例 #3
0
 /**
  * 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];
 }
コード例 #4
0
 /**
  * Move entity hierarchy to new parent or root
  *
  * @param Permission  $permission permission instance
  * @param string|null $to         to prefix
  * @return void
  * @throws InvalidArgumentException
  * @throws NoParentException
  */
 public function move(Permission $permission, $to = null)
 {
     $toParent = $to !== null ? $this->repo->findByName($permission->siteKey, $to) : null;
     if ($to !== null && $toParent === null || $toParent !== null && $permission->type != $toParent->type) {
         throw new InvalidArgumentException(['arg' => $to]);
     }
     $parent = $permission->getParent();
     if ($parent === null) {
         if ($permission->getDepth() !== 1) {
             throw new NoParentException();
         }
         $this->repo->affiliate($permission, $to);
     } else {
         $this->repo->foster($permission, $to);
     }
 }