move code to repository root
This commit is contained in:
parent
47e227257c
commit
9ce2c0ae4c
35 changed files with 2025 additions and 0 deletions
44
src/Infrastructure/WebApp/Route/CachedRouteCollector.php
Normal file
44
src/Infrastructure/WebApp/Route/CachedRouteCollector.php
Normal file
|
@ -0,0 +1,44 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Lubian\AttributeMagic\Infrastructure\WebApp\Route;
|
||||
|
||||
use Lubian\AttributeMagic\Infrastructure\Event\AsListener;
|
||||
|
||||
use function file_exists;
|
||||
use function file_get_contents;
|
||||
use function file_put_contents;
|
||||
use function serialize;
|
||||
use function unserialize;
|
||||
|
||||
final class CachedRouteCollector
|
||||
{
|
||||
public const ROUTES_DIR = __DIR__ . '/../../../../var/routesCache';
|
||||
|
||||
#[AsListener(CollectRoutes::class, -10)]
|
||||
public function getCached(CollectRoutes $event): void
|
||||
{
|
||||
if ($event->cached === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! file_exists(self::ROUTES_DIR)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$event->routes = unserialize(file_get_contents(self::ROUTES_DIR)); //@phpstan-ignore-line
|
||||
$event->stopped = true;
|
||||
}
|
||||
|
||||
#[AsListener(CollectRoutes::class, 10)]
|
||||
public function setCached(CollectRoutes $event): void
|
||||
{
|
||||
if ($event->cached === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
file_put_contents(
|
||||
self::ROUTES_DIR,
|
||||
serialize($event->routes),
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue