35 lines
753 B
PHP
35 lines
753 B
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 = [];
|
||
|
|
|
||
|
|
public static function add(callable $registrar): void
|
||
|
|
{
|
||
|
|
self::$callbacks[] = $registrar;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function clear(): void
|
||
|
|
{
|
||
|
|
self::$callbacks = [];
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function apply(RouteCollector $collector, Router $router): void
|
||
|
|
{
|
||
|
|
foreach (self::$callbacks as $cb) {
|
||
|
|
$cb($collector, $router);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|