<?php
use Psr\Http\Server\{MiddlewareInterface, RequestHandlerInterface};
use Psr\Http\Message\{ServerRequestInterface, ResponseInterface};
class Middleware implements MiddlewareInterface
{
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
// do stuff to the request
$response = $handler->handle($request);
// do stuff to the response
return $response;
}
}
<?php
use Symfony\Component\HttpFoundation\{Request, Response};
use Symfony\Component\HttpKernel\HttpKernelInterface;
class Middleware implements HttpKernelInterface
{
private $kernel;
public function __construct(HttpKernelInterface $kernel)
{
$this->kernel = $kernel;
}
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
{
// do stuff to the request
$response = $this->kernel->handle($request, $type, $catch);
// do stuff to the response
return $response;
}
}