Exemple #1
0
 public function __construct($userId, IFactory $factory, IStorage $storage)
 {
     parent::__construct($storage);
     $userRole = $this->storage->getUserRole($userId);
     if ($userRole) {
         //先撈有哪些角色
         foreach ($userRole as $value) {
             try {
                 $roleProxy = $factory->getRoleProxy($value['name'], $this->storage);
                 $roleResource = $this->storage->getRoleResource($roleProxy->getId());
                 if ($roleResource) {
                     //從角色找尋有哪些resource
                     foreach ($roleResource as $resourceValue) {
                         try {
                             $resource = $factory->getResourceProxy($resourceValue['name'], $resourceValue['resource'], $this->storage);
                             //從db assign 值給物件
                             $resource->setAction(explode("|", $resourceValue['action']));
                             //resource 推入
                             $roleProxy->addResource($resource);
                         } catch (ResourceProxyException $e) {
                             throw new RoleProxyException("NO ResourceData");
                         }
                     }
                 }
                 $this->roles[] = $roleProxy;
             } catch (RoleProxyException $e) {
                 throw new RbacException("NO RoleProxyData");
             }
         }
     }
     $this->userId = $userId;
 }
 public function __construct(IResource $resource, IStorage $storage)
 {
     parent::__construct($storage);
     $rs = $this->storage->getResource(array('name' => $resource->getName(), 'resource' => $resource->getResource()));
     if (!$rs) {
         throw new ResourceProxyException("NO ResourceData");
     }
     $this->id = $rs['id'];
     $this->realResource = $resource;
 }
Exemple #3
0
 public function __construct(IRole $realRole, IStorage $storage)
 {
     parent::__construct($storage);
     //撈角色資料
     $role = $this->storage->getRole(array('name' => $realRole->getName()));
     //沒有資料 新建一筆
     if (!$role) {
         throw new RoleProxyException("NO RoleData");
     }
     $this->id = $role['id'];
     //角色實體指定
     $this->realRole = $realRole;
 }
Exemple #4
0
 public function __construct(IFactory $factory, IStorage $storage)
 {
     parent::__construct($storage);
     $this->factory = $factory;
 }
Exemple #5
0
 public function __construct(IStorage $storage)
 {
     parent::__construct($storage);
     $this->storage = $storage;
 }