Author: XE Developers (developers@xpressengine.com)
 /**
  * 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];
 }
示例#2
0
 /**
  * Move entity hierarchy to new parent or root
  *
  * @param Registered  $registered registered object
  * @param string|null $to         to registered prefix
  *
  * @return void
  * @throws InvalidArgumentException
  */
 public function move(Registered $registered, $to = null)
 {
     $toParent = $to !== null ? $this->repo->findByTypeAndName($registered->siteKey, $registered->type, $to) : null;
     if ($to !== null && $toParent === null || $toParent !== null && $registered->type != $toParent->type) {
         throw new InvalidArgumentException();
     }
     $parent = $registered->getParent();
     if ($parent === null) {
         if ($registered->getDepth() !== 1) {
             throw new InvalidArgumentException();
         }
         $this->repo->affiliate($registered, $to);
     } else {
         $this->repo->foster($registered, $to);
     }
 }
示例#3
0
 /**
  * affiliated to another registered
  *
  * @param Permission $item permission instance
  * @param string     $to   parent name
  * @return void
  */
 public function affiliate(Permission $item, $to)
 {
     $this->forget($item);
     $this->repo->affiliate($item, $to);
 }
 /**
  * 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);
     }
 }
示例#5
0
 /**
  * affiliated to another registered
  *
  * @param Permission $item permission instance
  * @param string     $to   parent name
  * @return void
  */
 public function affiliate(Permission $item, $to)
 {
     unset($this->bag[$this->getKey($item->siteKey, $item->name)]);
     $this->repo->affiliate($item, $to);
 }
 public function testAffiliate()
 {
     list($conn, $query) = $this->getMocks();
     $instance = new PermissionRepository($conn);
     $mockRegistered = m::mock('Xpressengine\\Permission\\Registered');
     $mockRegistered->siteKey = 'default';
     $mockRegistered->type = 'instance';
     $mockRegistered->name = 'prev.from';
     $conn->shouldReceive('table')->andReturn($query);
     $query->shouldReceive('where')->once()->with('siteKey', 'default')->andReturnSelf();
     $query->shouldReceive('where')->once()->with('type', 'instance')->andReturnSelf();
     $query->shouldReceive('where')->once()->with(m::on(function ($closure) use($query) {
         $query->shouldReceive('where')->once()->with('name', 'prev.from')->andReturnSelf();
         $query->shouldReceive('orWhere')->once()->with('name', 'like', 'prev.from.%')->andReturnSelf();
         call_user_func($closure, $query);
         return true;
     }))->andReturnSelf();
     $conn->shouldReceive('raw')->once()->with("concat('valid.to', '.', `name`)")->andReturn('newName');
     $query->shouldReceive('update')->once();
     $instance->affiliate($mockRegistered, 'valid.to');
 }