protected function matchRole(User $user, $role, $resource) {
    $isDynamicRole = isset($this->dynamicRoles[$role]);
    return (($isDynamicRole && $this->dynamicRoles[$role]->match($user, $resource) === true)
            || (!$isDynamicRole && $user->hasRole($role)));
  }