class BanMiddleware in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/ban/src/BanMiddleware.php \Drupal\ban\BanMiddleware
Provides a HTTP middleware to implement IP based banning.
Hierarchy
- class \Drupal\ban\BanMiddleware implements HttpKernelInterface
Expanded class hierarchy of BanMiddleware
1 file declares its use of BanMiddleware
- BanMiddlewareTest.php in core/
modules/ ban/ tests/ src/ Unit/ BanMiddlewareTest.php - Contains \Drupal\Tests\ban\Unit\BanMiddlewareTest.
1 string reference to 'BanMiddleware'
- ban.services.yml in core/
modules/ ban/ ban.services.yml - core/modules/ban/ban.services.yml
1 service uses BanMiddleware
- ban.middleware in core/
modules/ ban/ ban.services.yml - Drupal\ban\BanMiddleware
File
- core/
modules/ ban/ src/ BanMiddleware.php, line 18 - Contains \Drupal\ban\BanMiddleware.
Namespace
Drupal\banView source
class BanMiddleware implements HttpKernelInterface {
/**
* The decorated kernel.
*
* @var \Symfony\Component\HttpKernel\HttpKernelInterface
*/
protected $httpKernel;
/**
* The ban IP manager.
*
* @var \Drupal\ban\BanIpManagerInterface
*/
protected $banIpManager;
/**
* Constructs a BanMiddleware object.
*
* @param \Symfony\Component\HttpKernel\HttpKernelInterface $http_kernel
* The decorated kernel.
* @param \Drupal\ban\BanIpManagerInterface $manager
* The ban IP manager.
*/
public function __construct(HttpKernelInterface $http_kernel, BanIpManagerInterface $manager) {
$this->httpKernel = $http_kernel;
$this->banIpManager = $manager;
}
/**
* {@inheritdoc}
*/
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);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BanMiddleware:: |
protected | property | The ban IP manager. | |
BanMiddleware:: |
protected | property | The decorated kernel. | |
BanMiddleware:: |
public | function |
Handles a Request to convert it to a Response. Overrides HttpKernelInterface:: |
|
BanMiddleware:: |
public | function | Constructs a BanMiddleware object. | |
HttpKernelInterface:: |
constant | |||
HttpKernelInterface:: |
constant |