示例#1
0
 public function testRoleContextBucket()
 {
     $acl = $this->getAcl();
     $rb = new RoleBucket($acl);
     $rb->add('guest');
     $rb->add('super_administrator');
     $acl->switchRoleContext($rb);
     $context = $acl->getContext();
     $this->assertEquals($context->getRoles()->toArray(), ['guest', 'super_administrator']);
 }
示例#2
0
 /**
  * @inheritdoc
  */
 public function getRoles()
 {
     if (!isset($this->roles)) {
         $this->roles = parent::getRoles();
         $roles = $this->getRoleQuery()->pluck('role_id');
         foreach ($roles as $role) {
             if ($role = app(RoleProvider::class)->getRoleById($role)) {
                 $this->roles->add($role['system_id']);
             }
         }
     }
     return clone $this->roles;
 }
示例#3
0
文件: Acl.php 项目: psesd/chms-common
 /**
  * Switch to a explicit role (used in testing)
  *
  * @param  array|string|RoleBucket $roles
  * @return AclContextContract
  */
 public function switchRoleContext($roles)
 {
     if (is_string($roles)) {
         $roles = [$roles];
     }
     if (is_array($roles)) {
         $roleBucket = new RoleBucket($this);
         foreach ($roles as $role) {
             $roleBucket->add($role);
         }
     } else {
         $roleBucket = $roles;
     }
     $context = new RoleSetContext($roleBucket);
     $this->registerContext($context);
     $this->currentContext = $context->getId();
     return $context;
 }
示例#4
0
 /**
  * @inheritdoc
  */
 protected function id()
 {
     return sha1(implode($this->roles->toArray()));
 }
示例#5
0
 private function discoverSelf(RoleBucket $roleBucket)
 {
     if ($this->isSelf()) {
         $roleBucket->add('self');
     }
 }