affiliate() public method

affiliated to another registered
public affiliate ( Permission $item, string $to ) : void
$item Permission permission instance
$to string parent name
return void
Example #1
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);
     }
 }
Example #2
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);
     }
 }
Example #4
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');
 }
 /**
  * affiliated to another registered
  *
  * @param Permission $item permission instance
  * @param string     $to   parent name
  * @return void
  */
 public function affiliate(Permission $item, $to)
 {
     $this->erase($item->siteKey, $item->name);
     $this->erase($item->siteKey, $to);
     $this->repo->affiliate($item, $to);
 }