Phred/src/Http/Routing/RouteRegistry.php
Funky Waddle 54303282d7
Some checks failed
CI / PHP ${{ matrix.php }} (8.1) (push) Has been cancelled
CI / PHP ${{ matrix.php }} (8.2) (push) Has been cancelled
CI / PHP ${{ matrix.php }} (8.3) (push) Has been cancelled
Too many things
2026-01-06 11:02:05 -06:00

49 lines
1.1 KiB
PHP

<?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 = [];
/** @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 = [];
self::$loadedFiles = [];
}
public static function apply(RouteCollector $collector, Router $router): void
{
foreach (self::$callbacks as $cb) {
$cb($collector, $router);
}
}
}