mirror of
https://github.com/shlinkio/shlink.git
synced 2026-02-28 12:13:13 +08:00
35 lines
944 B
PHP
35 lines
944 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Shlinkio\Shlink\Common\Middleware;
|
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use Psr\Http\Message\ResponseInterface;
|
|
use Psr\Http\Message\ServerRequestInterface;
|
|
use Psr\Http\Server\MiddlewareInterface;
|
|
use Psr\Http\Server\RequestHandlerInterface;
|
|
|
|
class CloseDbConnectionMiddleware implements MiddlewareInterface
|
|
{
|
|
/** @var EntityManagerInterface */
|
|
private $em;
|
|
|
|
public function __construct(EntityManagerInterface $em)
|
|
{
|
|
$this->em = $em;
|
|
}
|
|
|
|
/**
|
|
* Process an incoming server request and return a response, optionally delegating
|
|
* response creation to a handler.
|
|
*/
|
|
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
|
{
|
|
$handledRequest = $handler->handle($request);
|
|
$this->em->getConnection()->close();
|
|
$this->em->clear();
|
|
|
|
return $handledRequest;
|
|
}
|
|
}
|