Example #1
0
 /**
  * Maps an array of permission data to Permission objects
  *
  * @param array $permissions
  * @return \BeatSwitch\Lock\Permissions\Permission[]
  */
 public static function createFromData($permissions)
 {
     return array_map(function ($permission) {
         if (is_array($permission)) {
             return PermissionFactory::createFromArray($permission);
         } else {
             return PermissionFactory::createFromObject($permission);
         }
     }, $permissions);
 }
 /**
  * Returns all the permissions for a role
  *
  * @param \BeatSwitch\Lock\Roles\Role $role
  * @return \BeatSwitch\Lock\Permissions\Permission[]
  */
 public function getRolePermissions(Role $role)
 {
     $key = $this->getRoleKey($role);
     // If we've saved the caller permissions we don't need to fetch them again.
     if (array_key_exists($key, $this->_rolePermissions)) {
         return $this->_rolePermissions[$key];
     }
     $results = $this->getTable('Roles')->find()->where(['role' => $role->getRoleName()])->toArray();
     return $this->_rolePermissions[$key] = PermissionFactory::createFromData($results);
 }