- Tmp code allowing to override routes
This commit is contained in:
parent
959a182d16
commit
1f828eb022
|
@ -17,6 +17,8 @@ class Routing {
|
||||||
|
|
||||||
public ResponseInterface $response;
|
public ResponseInterface $response;
|
||||||
|
|
||||||
|
protected array $registeredRoutes;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public Router $router,
|
public Router $router,
|
||||||
public RouteFetcher $fetcher,
|
public RouteFetcher $fetcher,
|
||||||
|
@ -24,12 +26,20 @@ class Routing {
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
public function registerRoute(ContainerInterface $container, string $urlBase) {
|
public function registerRoute(ContainerInterface $container, string $urlBase) {
|
||||||
$this->router->group(rtrim($urlBase, "/"), function (RouteGroup $route) use ($container) {
|
$this->registeredRoutes[$urlBase] ??= [];
|
||||||
foreach($this->fetcher->compile() as $attribute) {
|
|
||||||
|
$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);
|
$this->eventManager->execute(Event\RoutingCompileRoutes::class, $this, $attribute);
|
||||||
|
|
||||||
# Mapping every URLs from attributes in searched folders (Api, Controller, etc...)
|
# Mapping every URLs from attributes in searched folders (Api, Controller, etc...)
|
||||||
foreach((array) $attribute->method as $method) {
|
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 (
|
$route->map(strtoupper($method), $attribute->getRoute(), function (ServerRequestInterface $request, array $arguments) use (
|
||||||
$container, $route, $attribute
|
$container, $route, $attribute
|
||||||
) : ResponseInterface {
|
) : ResponseInterface {
|
||||||
|
|
Loading…
Reference in New Issue