AdvbanMiddleware.php in Advanced ban 8
File
src/AdvbanMiddleware.php
View source
<?php
namespace Drupal\advban;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpKernelInterface;
class AdvbanMiddleware implements HttpKernelInterface {
protected $httpKernel;
protected $banIpManager;
public function __construct(HttpKernelInterface $http_kernel, AdvbanIpManagerInterface $manager) {
$this->httpKernel = $http_kernel;
$this->banIpManager = $manager;
}
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);
}
}