WIP on liteing the framework

This commit is contained in:
mcndave committed 2023-11-17 22:05:05 -05:00
1 parent bc55a2ab89
commit 9b795b857a
7 files changed
+36 -67

No files matched your search

+10 -34
View File
@@ -2,9 +2,6 @@
namespace Lean;
use Notes\Annotation;
use Taxus\Taxus;
use League\Route\RouteGroup,
League\Route\Router;
@@ -14,54 +11,33 @@ use Psr\Http\Message\ServerRequestInterface,
use Notes\Route\RouteFetcher;
use Notes\Security\SecurityHandler;
use Notes\Tell\LanguageHandler;
use Picea\Picea,
Picea\Extension\UrlExtension;
use Storage\Cookie,
Storage\Session;
use Mcnd\Event\EventManager;
use function DI\autowire, DI\create;
class Routing {
public Annotation $selectedRoute;
public ResponseInterface $response;
public function __construct(
public Session $session,
public Cookie $cookie,
public UrlExtension $extension,
public Router $router,
public RouteFetcher $fetcher,
public SecurityHandler $security,
public Taxus $taxus,
public EventManager $eventManager,
) { }
public function registerRoute(ContainerInterface $container, string $urlBase) {
$this->router->group(rtrim($urlBase, "/"), function (RouteGroup $route) use ($container) {
foreach($this->fetcher->compile() as $annotation) {
$this->eventManager->execute(Event\RoutingCompileRoutes::class, $this, $annotation);
foreach($this->fetcher->compile() as $attribute) {
$this->eventManager->execute(Event\RoutingCompileRoutes::class, $this, $attribute);
/* @deprecated annotation->method will become standard when using native attributes */
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;
# Mapping every URLs from attributes in searched folders (Api, Controller, etc...)
foreach((array) $attribute->method as $method) {
$route->map(strtoupper($method), $attribute->getRoute(), function (ServerRequestInterface $request, array $arguments) use (
$container, $route, $attribute
) : ResponseInterface {
$class = $attribute->class;
$method = $attribute->classMethod;
$object = $container->get($class);
$this->eventManager->execute(Event\RoutingMapRoutes::class, $this, $container, $request, $annotation);
$this->eventManager->execute(Event\RoutingMapRoutes::class, $this, $container, $request, $attribute);
$container->set(ServerRequestInterface::class, $request);