update code, add psalm
This commit is contained in:
parent
427d474f7c
commit
224925e56b
8 changed files with 1909 additions and 7 deletions
|
@ -7,6 +7,8 @@ use Lubian\AttributeMagic\Infrastructure\WebApp\Request\RequestEvent;
|
|||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
use function apcu_add;
|
||||
use function apcu_fetch;
|
||||
use function is_string;
|
||||
use function md5;
|
||||
use function serialize;
|
||||
use function unserialize;
|
||||
|
@ -16,8 +18,17 @@ final class CachedResponse
|
|||
#[AsListener(RequestEvent::class, -99)]
|
||||
public function cachedResponse(RequestEvent $event): void
|
||||
{
|
||||
$response = new Response('lol');
|
||||
$serialized = serialize($response);
|
||||
if ($event->request->getMethod() !== 'GET') {
|
||||
return;
|
||||
}
|
||||
|
||||
$path = md5($event->request->getPathInfo());
|
||||
$serialized = apcu_fetch($path);
|
||||
|
||||
if (! is_string($serialized)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/** @var Response|null $response */
|
||||
$response = unserialize($serialized);
|
||||
$event->response = $response;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Lubian\AttributeMagic\Infrastructure\WebApp\Route;
|
||||
|
||||
use Lubian\AttributeMagic\Infrastructure\Event\AsListener;
|
||||
use Lubian\AttributeMagic\Infrastructure\Route\Handler;
|
||||
|
||||
use function file_exists;
|
||||
use function file_get_contents;
|
||||
|
@ -25,7 +26,10 @@ final class CachedRouteCollector
|
|||
return;
|
||||
}
|
||||
|
||||
$event->routes = unserialize(file_get_contents(self::ROUTES_DIR)); //@phpstan-ignore-line
|
||||
/** @var Handler[] $routes */
|
||||
$routes = unserialize(file_get_contents(self::ROUTES_DIR));
|
||||
$event->routes = $routes;
|
||||
|
||||
$event->stopped = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ final readonly class HandlerCaller
|
|||
}
|
||||
|
||||
ob_start();
|
||||
/** @var mixed $response */
|
||||
$response = $this->invoker->call(
|
||||
[$event->handler->handlerClass, $event->handler->handlerMethod],
|
||||
$event->request->attributes->all()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue