- Tmp code allowing to override routes

This commit is contained in:
Dave M. 2024-10-09 14:34:54 -04:00
parent 959a182d16
commit 1f828eb022
1 changed files with 12 additions and 2 deletions

View File

@ -17,6 +17,8 @@ class Routing {
public ResponseInterface $response;
protected array $registeredRoutes;
public function __construct(
public Router $router,
public RouteFetcher $fetcher,
@ -24,12 +26,20 @@ class Routing {
) { }
public function registerRoute(ContainerInterface $container, string $urlBase) {
$this->router->group(rtrim($urlBase, "/"), function (RouteGroup $route) use ($container) {
foreach($this->fetcher->compile() as $attribute) {
$this->registeredRoutes[$urlBase] ??= [];
$this->router->group(rtrim($urlBase, "/"), function (RouteGroup $route) use ($container, $urlBase) {
foreach(array_reverse($this->fetcher->compile()) as $attribute) {
$this->eventManager->execute(Event\RoutingCompileRoutes::class, $this, $attribute);
# Mapping every URLs from attributes in searched folders (Api, Controller, etc...)
foreach((array) $attribute->method as $method) {
if (! empty($this->registeredRoutes[$urlBase][$attribute->getRoute().$method])) {
continue;
}
$this->registeredRoutes[$urlBase][$attribute->getRoute().$method] = true;
$route->map(strtoupper($method), $attribute->getRoute(), function (ServerRequestInterface $request, array $arguments) use (
$container, $route, $attribute
) : ResponseInterface {