You are here

public function AccessFilterMiddleware::handle in Access Filter 8

File

src/AccessFilterMiddleware.php, line 48

Class

AccessFilterMiddleware
Provides a HTTP middleware to implement access filtering.

Namespace

Drupal\access_filter

Code

public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE) {
  if (!Settings::get('access_filter_disabled')) {
    $this->moduleHandler
      ->loadAll();
    $filters = Filter::loadMultiple();
    foreach ($filters as $filter) {
      if ($filter
        ->status()) {
        $filter
          ->parse();
        if (!$filter
          ->isAllowed($request)) {
          $code = $filter
            ->get('parsedResponse')['code'];
          if (in_array($code, [
            301,
            302,
          ])) {
            return new RedirectResponse($filter
              ->get('parsedResponse')['redirect_url'], $code);
          }
          else {
            return new Response($filter
              ->get('parsedResponse')['body'], $code);
          }
        }
      }
    }
  }
  return $this->httpKernel
    ->handle($request, $type, $catch);
}