Go to file
Tim 96e833fb4b Move route config to app
diff --git a/app/Kernel.php b/app/Kernel.php
index 0e8e047..4425355 100644
--- a/app/Kernel.php
+++ b/app/Kernel.php
@@ -2,8 +2,16 @@

 namespace App;

+use App\Controller\BaseController;
+use Ardent\Undercurrent\Container\ContainerInterface;
 use Ardent\Undercurrent\Kernel\BaseKernel;

 class Kernel extends BaseKernel
 {
+    protected function dependencies(ContainerInterface $container): void
+    {
+        $this->addRoutes($container, [
+            BaseController::class,
+        ]);
+    }
 }
\ No newline at end of file
diff --git a/src/Http/RouterConfig.php b/src/Http/RouterConfig.php
index ad856d6..60e5af7 100644
--- a/src/Http/RouterConfig.php
+++ b/src/Http/RouterConfig.php
@@ -4,7 +4,6 @@ namespace Ardent\Undercurrent\Http;

 class RouterConfig
 {
-
     public function __construct(
         private readonly array $controllers = [],
     )
diff --git a/src/Kernel/BaseKernel.php b/src/Kernel/BaseKernel.php
index a6732f4..149aa8b 100644
--- a/src/Kernel/BaseKernel.php
+++ b/src/Kernel/BaseKernel.php
@@ -2,7 +2,6 @@

 namespace Ardent\Undercurrent\Kernel;

-use App\Controller\BaseController;
 use Ardent\Undercurrent\Container\ContainerInterface;
 use Ardent\Undercurrent\Container\GenericContainer;
 use Ardent\Undercurrent\Http\GenericRequest;
@@ -20,12 +19,9 @@ class BaseKernel
             ->alias(RouterInterface::class, GenericRouter::class)
             ->alias(ContainerInterface::class, GenericContainer::class)
             ->add(GenericContainer::class, fn($container) => $container)
-            ->add(GenericRouter::class)
-            ->add(BaseController::class);
+            ->add(GenericRouter::class);

-        $container->add(RouterConfig::class, fn() => new RouterConfig([
-            BaseController::class,
-        ]));
+        $this->dependencies($container);

         $this->render($container);
     }
@@ -41,4 +37,17 @@ class BaseKernel
         $router = $container->get(RouterInterface::class);
         echo $router->dispatch($request)->getBody();
     }
+
+    protected function addRoutes(ContainerInterface $container, array $routes): void
+    {
+        foreach ($routes as $route) {
+            $container->add($route);
+        }
+
+        $container->add(RouterConfig::class, fn() => new RouterConfig($routes));
+    }
+
+    protected function dependencies(ContainerInterface $container): void
+    {
+    }
 }
\ No newline at end of file
2023-08-08 15:42:57 +02:00
app Move route config to app 2023-08-08 15:42:57 +02:00
public Properly implement the router with config and interfaces 2023-08-07 17:51:53 +02:00
src Move route config to app 2023-08-08 15:42:57 +02:00
.gitignore First working version with non working routes 2023-07-28 16:14:55 +02:00
composer.json Properly implement the router with config and interfaces 2023-08-07 17:51:53 +02:00
composer.lock Properly implement the router with config and interfaces 2023-08-07 17:51:53 +02:00
README.md Add response and request objects and interfaces 2023-08-07 14:23:00 +02:00

Todos:

  • Collect routes properly
  • Process routes correctly
  • Add request and response objects

Routing: Currently the routes are hardcoded, we need we way to process all classes maybe and sort them into a list of routes.