Ejemplo n.º 1
0
 public function __construct($data)
 {
     if (is_array($data)) {
         parent::__construct($data);
     } else {
         if ($data instanceof User) {
             parent::__construct($data->toArray());
         } else {
             throw new InvalidArgumentException("argument should be array or User");
         }
     }
     if (!isset($this->roles)) {
         $this->roles = UserRole::where('user_id', '=', $this->getKey())->get(['role_id'])->lists('role_id');
         $this->user_types = AclFacade::getRoles($this->roles)->lists('type');
     }
     if (!isset($this->user_types)) {
         $this->user_types = count($this->roles) ? AclFacade::getRoles($this->roles)->lists('type') : [];
     }
 }
Ejemplo n.º 2
0
 public function __construct($resource, $values = [], $allowed = null)
 {
     $data = [];
     $default_permission = Config::get("acl::config.default_permission");
     if (is_array($resource)) {
         $resource = (object) $resource;
     }
     if (is_object($resource)) {
         /* @var $resource AclPermission */
         if (!(isset($resource->resource) || isset($resource->permission_id))) {
             throw new InvalidArgumentException('permission must include resource');
         }
         if (!isset($resource->resource)) {
             $group_resources = GroupResources::getGroupResources();
             if (!isset($group_resources[$resource->permission_id])) {
                 throw new InvalidArgumentException('permission id do not have resource: ' . $resource->permission_id);
             }
             $data['resource'] = $group_resources[$resource->permission_id];
         } else {
             $data['resource'] = $resource->resource;
         }
         if (isset($resource->values)) {
             if (is_array($resource->values)) {
                 $data['values'] = $resource->values;
             } else {
                 if (is_string($resource->values)) {
                     $data['values'] = json_decode($resource->values);
                 }
             }
         }
         $data['allowed'] = !isset($resource->allowed) || is_null($resource->allowed) ? $default_permission : (bool) $resource->allowed;
     } else {
         $data['resource'] = $resource;
         $data['values'] = $values;
         $data['allowed'] = is_null($allowed) || !is_bool($allowed) ? $default_permission : $allowed;
     }
     parent::__construct($data);
 }
Ejemplo n.º 3
0
 public function offsetUnset($offset)
 {
     if (in_array($offset, ['role_id', 'name', 'type', 'default', 'permissions', 'users'])) {
         throw new NoPermissionsException("No permission to unset: " . $offset);
     }
     parent::offsetUnset($offset);
 }