Pagekit\User\Model\User::hasAccess PHP Метод

hasAccess() публичный Метод

Expression forms: - a single permission string starting with a letter and consisting of letters, numbers and characters .:-_ and whitespace - a boolean expression with multiple permissions and operators like &&, || and (...) parenthesis Examples: - a single permission string can be "create_posts", "create posts", "posts:create" etc. - a boolean expression with multiple permissions boolean expression can be "create_posts && delete_posts", "(create posts && delete posts) || manage posts" etc.
public hasAccess ( string $expression ) : boolean
$expression string
Результат boolean
    public function hasAccess($expression)
    {
        $user = $this;
        if ($this->isAdministrator() || empty($expression)) {
            return true;
        }
        if (!preg_match('/[&\\(\\)\\|\\!]/', $expression)) {
            return $this->hasPermission($expression);
        }
        $exp = preg_replace('/[^01&\\(\\)\\|!]/', '', preg_replace_callback('/[a-z_][a-z-_\\.:\\d\\s]*/i', function ($permission) use($user) {
            return (int) $user->hasPermission(trim($permission[0]));
        }, $expression));
        if (!($fn = @create_function("", "return {$exp};"))) {
            throw new \InvalidArgumentException(sprintf('Unable to parse the given access string "%s"', $expression));
        }
        return (bool) $fn();
    }

Usage Example

Пример #1
0
 /**
  * Proxy permissioncheck
  * @param $permission
  * @return bool
  */
 public function hasAccess($permission)
 {
     return $this->user->hasAccess($permission);
 }
All Usage Examples Of Pagekit\User\Model\User::hasAccess