public function AccessManager::check

Checks a route against applicable access check services.

Determines whether the route is accessible or not.

Parameters

\Symfony\Component\Routing\Route $route: The route to check access to.

Throws

\Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException If any access check denies access or none explicitly approve.

File

drupal/core/lib/Drupal/Core/Access/AccessManager.php, line 113
Contains Drupal\Core\Access\AccessManager.

Class

AccessManager
Attaches access check services to routes and runs them on request.

Namespace

Drupal\Core\Access

Code

public function check(Route $route) {
  $access = FALSE;
  $checks = $route
    ->getOption('_access_checks') ?: array();

  // No checks == deny by default.
  foreach ($checks as $service_id) {
    if (empty($this->checks[$service_id])) {
      $this
        ->loadCheck($service_id);
    }
    $access = $this->checks[$service_id]
      ->access($route, $this->request);
    if ($access === FALSE) {

      // A check has denied access, no need to continue checking.
      break;
    }
  }

  // Access has been denied or not explicily approved.
  if (!$access) {
    throw new AccessDeniedHttpException();
  }
}