class AdvbanMiddleware in Advanced ban 8
Provides a HTTP middleware to implement IP based banning.
Hierarchy
- class \Drupal\advban\AdvbanMiddleware implements \Symfony\Component\HttpKernel\HttpKernelInterface
Expanded class hierarchy of AdvbanMiddleware
1 file declares its use of AdvbanMiddleware
- AdvbanMiddlewareTest.php in tests/
src/ Unit/ AdvbanMiddlewareTest.php
1 string reference to 'AdvbanMiddleware'
1 service uses AdvbanMiddleware
File
- src/
AdvbanMiddleware.php, line 12
Namespace
Drupal\advbanView source
class AdvbanMiddleware implements HttpKernelInterface {
/**
* The decorated kernel.
*
* @var \Symfony\Component\HttpKernel\HttpKernelInterface
*/
protected $httpKernel;
/**
* The ban IP manager.
*
* @var \Drupal\advban\AdvbanIpManagerInterface
*/
protected $banIpManager;
/**
* Constructs a AdvbanMiddleware object.
*
* @param \Symfony\Component\HttpKernel\HttpKernelInterface $http_kernel
* The decorated kernel.
* @param \Drupal\advban\AdvbanIpManagerInterface $manager
* The ban IP manager.
*/
public function __construct(HttpKernelInterface $http_kernel, AdvbanIpManagerInterface $manager) {
$this->httpKernel = $http_kernel;
$this->banIpManager = $manager;
}
/**
* {@inheritdoc}
*/
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE) {
$ip = $request
->getClientIp();
$ban_result = $this->banIpManager
->isBanned($ip, [
'expiry_check' => TRUE,
'info_output' => TRUE,
]);
if ($ban_result['is_banned']) {
$ban_text = $this->banIpManager
->banText([
'ip' => $ip,
'expiry_date' => $ban_result['expiry_date'],
]);
return new Response($ban_text, 403);
}
return $this->httpKernel
->handle($request, $type, $catch);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AdvbanMiddleware:: |
protected | property | The ban IP manager. | |
AdvbanMiddleware:: |
protected | property | The decorated kernel. | |
AdvbanMiddleware:: |
public | function | Handles a Request to convert it to a Response. | |
AdvbanMiddleware:: |
public | function | Constructs a AdvbanMiddleware object. |