ZfcRbac\Service\AuthorizationService::getIdentity PHP Method

getIdentity() public method

Get the current identity from the role service
public getIdentity ( ) : ZfcRbac\Identity\IdentityInterface | null
return ZfcRbac\Identity\IdentityInterface | null
    public function getIdentity()
    {
        return $this->roleService->getIdentity();
    }

Usage Example

Beispiel #1
0
 /**
  * Return an array of roles which may be granted the permission based on
  * the options.
  *
  * @param mixed $options Options provided from configuration.
  *
  * @return array
  */
 public function getPermissions($options)
 {
     // If no user is logged in, or the user doesn't match the passed-in
     // whitelist, we can't grant the permission to any roles.
     if (!($user = $this->auth->getIdentity())) {
         return [];
     }
     // which user attribute has to match which pattern to get permissions?
     $criteria = [];
     foreach ((array) $options as $option) {
         $parts = explode(' ', $option, 2);
         if (count($parts) < 2) {
             $this->logError("configuration option '{$option}' invalid");
             return [];
         } else {
             list($attribute, $pattern) = $parts;
             // check user attribute values against the pattern
             if (!preg_match('/^\\/.*\\/$/', $pattern)) {
                 $pattern = '/' . $pattern . '/';
             }
             if (preg_match($pattern, $user[$attribute])) {
                 return ['loggedin'];
             }
         }
     }
     //no matches found, so the user don't get any permissions
     return [];
 }
All Usage Examples Of ZfcRbac\Service\AuthorizationService::getIdentity