session = $session; $this->cookie = $cookie; $this->extension = $extension; $this->fetcher = $routeFetcher; $this->security = $security; $this->language = $language; $this->router = $router; $this->taxus = $taxus; } public function registerRoute(ContainerInterface $container, string $urlBase) { $this->router->group(rtrim($urlBase, "/"), function (RouteGroup $route) use ($container) { foreach($this->fetcher->compile() as $annotation) { # Register routes to the UrlExtension from picea (handling url, route and asset extensions) if ( null !== ( $name = $annotation->name ?? null ) ) { $this->extension->registerRoute($name, $annotation->getRoute(), $annotation->class, $annotation->classMethod, $annotation->methods ?? (array) $annotation->method); } foreach((array) ( $annotation->method ?? $annotation->methods ) as $method) { # Mapping every URLs from annotations in searched folders (Api, Controller, etc...) $route->map(strtoupper($method), $annotation->getRoute(), function (ServerRequestInterface $request, array $arguments) use ( $container, $route, $annotation ) : ResponseInterface { $class = $annotation->class; $method = $annotation->classMethod; # $container->set($class, autowire($class)->method($method, $request)); if ( null !== ( $languageAnnotation = $this->language->verify($class) ) ) { if ( $languageAnnotation->key ) { # TODO !!! $language } } $object = $container->get($class); # Checking if user needs to be logged if ( ( $redirect = $this->security->verify($class, $method) ) && ( empty($object->user) || ! $object->user->logged ) ) { $this->session->redirectedFrom = (string) $request->getUri(); return $redirect; } if ( $forbidden = $this->security->taxus($class, $method, $object->user ?? null) ) { return $forbidden; } # @TODO of course, this as to go ; moving to a simple callback method soon which can then be fed by Picea if ( $container->has(Picea::class) ) { $container->get(Picea::class)->globalVariables['route'] = $annotation; } return $object->$method($request->withAttribute('lean.route', $annotation), $arguments); }); } } }); } }