You are here

public function BanMiddleware::handle in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/ban/src/BanMiddleware.php \Drupal\ban\BanMiddleware::handle()

Handles a Request to convert it to a Response.

When $catch is true, the implementation must catch all exceptions and do its best to convert them to a Response instance.

Parameters

Request $request A Request instance:

int $type The type of the request: (one of HttpKernelInterface::MASTER_REQUEST or HttpKernelInterface::SUB_REQUEST)

bool $catch Whether to catch exceptions or not:

Return value

Response A Response instance

Throws

\Exception When an Exception occurs during processing

Overrides HttpKernelInterface::handle

File

core/modules/ban/src/BanMiddleware.php, line 50
Contains \Drupal\ban\BanMiddleware.

Class

BanMiddleware
Provides a HTTP middleware to implement IP based banning.

Namespace

Drupal\ban

Code

public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE) {
  $ip = $request
    ->getClientIp();
  if ($this->banIpManager
    ->isBanned($ip)) {
    return new Response(SafeMarkup::format('@ip has been banned', [
      '@ip' => $ip,
    ]), 403);
  }
  return $this->httpKernel
    ->handle($request, $type, $catch);
}