diff --git a/app/Controller/HelloWorldController.php b/app/Controller/HelloWorldController.php index eed77a5..340740d 100644 --- a/app/Controller/HelloWorldController.php +++ b/app/Controller/HelloWorldController.php @@ -2,6 +2,7 @@ namespace App\Controller; +use App\View\RouteView; use Ardent\Undercurrent\Attribute\Route; use Ardent\Undercurrent\Http\GenericResponse; use Ardent\Undercurrent\Http\ResponseInterface; @@ -36,15 +37,10 @@ class HelloWorldController return new BaseView('/home', ['name' => $name]); } - #[Route('/routes/{word}')] - public function routes(RouterConfig $config, string $word): ResponseInterface + #[Route('/routes')] + public function routes(RouterConfig $config): ViewInterface { - $routes = implode('
', array_map( - fn($route) => sprintf('%s - %s->%s', $route->getRoute()->path, $route->getController(), $route->getMethod()), - $config->getRoutes() - )) . "
$word"; - - return new GenericResponse($routes); + return new RouteView($config); } #[Route('/world/{name}')] diff --git a/app/Template/base.php b/app/Template/base.php index f4cee5c..ef4b5e6 100644 --- a/app/Template/base.php +++ b/app/Template/base.php @@ -1,10 +1,12 @@ - - Base view title - - - Base, slot: data['slot'] ?> - + + Base view title + + +Index
+Base slot:
+data['slot'] ?> + \ No newline at end of file diff --git a/app/Template/index.php b/app/Template/index.php index 9d8a892..c8c8e1d 100644 --- a/app/Template/index.php +++ b/app/Template/index.php @@ -1,4 +1,5 @@ extends = '/base' ?> -Hello index! +Hello world
+Routes diff --git a/app/Template/routes.php b/app/Template/routes.php new file mode 100644 index 0000000..4031b7b --- /dev/null +++ b/app/Template/routes.php @@ -0,0 +1,12 @@ + + +routes->getRoutes() as $route) { + echo sprintf('%s - %s::%s
', + $route->getRoute()->path, + $route->getRoute()->path, + $route->getController(), + $route->getMethod() + ); +} +?> \ No newline at end of file diff --git a/app/View/RouteView.php b/app/View/RouteView.php new file mode 100644 index 0000000..40a996c --- /dev/null +++ b/app/View/RouteView.php @@ -0,0 +1,14 @@ +getBody(); - echo '
';
+        echo '
Log:
'; foreach ($log->getLogs() as $log) { echo sprintf('%s
', $log); } diff --git a/src/View/BaseView.php b/src/View/BaseView.php index 5050e86..3263226 100644 --- a/src/View/BaseView.php +++ b/src/View/BaseView.php @@ -11,7 +11,7 @@ class BaseView implements ViewInterface public function __construct( private readonly string $path, private readonly array $data = [], - private ?string $extends = null, + protected ?string $extends = null, ) { } @@ -38,7 +38,7 @@ class BaseView implements ViewInterface return $output; } - public function getRoute(string $class, string $method, array $params = []): string + protected function getRoute(string $class, string $method, array $params = []): string { return $this->helper->getRouter()->toUri($class, $method, $params); }