Phred/src/Http/Routing/RouteRegistry.php

49 lines
1.1 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
namespace Phred\Http\Routing;
use FastRoute\RouteCollector;
use Phred\Http\Router;
/**
* Allows providers to register route callbacks that will be applied
* when the FastRoute dispatcher is built.
*/
final class RouteRegistry
{
/** @var list<callable(RouteCollector, Router):void> */
private static array $callbacks = [];
2026-01-06 17:02:05 +00:00
/** @var array<string,bool> */
private static array $loadedFiles = [];
public static function markAsLoaded(string $filePath): void
{
self::$loadedFiles[realpath($filePath) ?: $filePath] = true;
}
public static function isLoaded(string $filePath): bool
{
return isset(self::$loadedFiles[realpath($filePath) ?: $filePath]);
}
public static function add(callable $registrar): void
{
self::$callbacks[] = $registrar;
}
public static function clear(): void
{
self::$callbacks = [];
2026-01-06 17:02:05 +00:00
self::$loadedFiles = [];
}
public static function apply(RouteCollector $collector, Router $router): void
{
foreach (self::$callbacks as $cb) {
$cb($collector, $router);
}
}
}