insert() public method

Insert register information
public insert ( Permission $item ) : Permission
$item Permission permission instance
return Permission
 public function testInsert()
 {
     list($conn, $query) = $this->getMocks();
     $mockRegistered = m::mock('Xpressengine\\Permission\\Registered');
     $mockRegistered->shouldReceive('getOriginal')->andReturn([]);
     $mockRegistered->shouldReceive('getAttributes')->andReturn(['type' => 'instance', 'name' => 'board.notice', 'grants' => '{"access":{"type":"power","value":"guest"},"create":{"type":"power","value":"member"}}']);
     $conn->shouldReceive('table')->andReturn($query);
     $query->shouldReceive('insertGetId')->once()->with(m::on(function ($array) {
         return $array['type'] === 'instance' && $array['name'] === 'board.notice' && $array['grants'] === '{"access":{"type":"power","value":"guest"},"create":{"type":"power","value":"member"}}';
     }))->andReturn(1);
     $instance = new PermissionRepository($conn);
     $registered = $instance->insert($mockRegistered);
     $this->assertEquals(1, $registered->id);
     $this->assertEquals(['type' => 'power', 'value' => 'guest'], $registered['access']);
     $this->assertEquals('board.notice', $registered->name);
     $this->assertEquals('instance', $registered->type);
 }
Esempio n. 2
0
 /**
  * Register grants information
  *
  * @param string $type    permission type
  * @param string $name    target name
  * @param Grant  $grant   grant instance
  * @param string $siteKey site key
  * @return Registered
  */
 public function register($type, $name, Grant $grant, $siteKey = 'default')
 {
     $registered = $this->findRegistered($type, $name, true, $siteKey);
     $registered->setGrant($grant);
     if (empty($registered->getOriginal()) === true) {
         $registered = $this->repo->insert($registered);
     } else {
         $registered = $this->repo->update($registered);
     }
     return $registered;
 }
Esempio n. 3
0
 /**
  * Insert register information
  *
  * @param Permission $item permission instance
  * @return Permission
  */
 public function insert(Permission $item)
 {
     $item = $this->repo->insert($item);
     $this->cache->put($this->getCacheKey($item->siteKey, $item->name), $item);
     return $item;
 }
Esempio n. 4
0
 /**
  * Register permission information
  *
  * @param string $name    permission name
  * @param Grant  $grant   grant instance
  * @param string $siteKey site key name
  * @return Permission
  */
 public function register($name, Grant $grant, $siteKey = 'default')
 {
     $permission = $this->getOrNew($name, $siteKey);
     $permission->setGrant($grant);
     if ($permission->exists !== true) {
         return $this->repo->insert($permission);
     }
     return $this->repo->update($permission);
 }
Esempio n. 5
0
 /**
  * Insert register information
  *
  * @param Permission $item permission instance
  * @return Permission
  */
 public function insert(Permission $item)
 {
     $item = $this->repo->insert($item);
     $this->bag[$this->getKey($item->siteKey, $item->name)] = $item;
     return $item;
 }
 /**
  * Register permission information
  *
  * @param string $name    permission name
  * @param Grant  $grant   grant instance
  * @param string $siteKey site key name
  * @return Permission
  */
 public function register($name, Grant $grant, $siteKey = 'default')
 {
     $permission = $this->getOrNew($name, $siteKey);
     if (strrpos($name, '.') !== false) {
         $pname = substr($name, 0, strrpos($name, '.'));
         if (!$this->repo->findByName($siteKey, $pname)) {
             throw new NoParentException(['name' => $name]);
         }
     }
     $permission->setGrant($grant);
     if ($permission->exists !== true) {
         return $this->repo->insert($permission);
     }
     return $this->repo->update($permission);
 }
 /**
  * Insert register information
  *
  * @param Permission $item permission instance
  * @return Permission
  */
 public function insert(Permission $item)
 {
     $this->erase($item->siteKey, $item->name);
     return $this->repo->insert($item);
 }