Play around with the rendering
This commit is contained in:
parent
24683e70a8
commit
18848e041f
@ -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('<br>', array_map(
|
||||
fn($route) => sprintf('%s - %s->%s', $route->getRoute()->path, $route->getController(), $route->getMethod()),
|
||||
$config->getRoutes()
|
||||
)) . "<br>$word";
|
||||
|
||||
return new GenericResponse($routes);
|
||||
return new RouteView($config);
|
||||
}
|
||||
|
||||
#[Route('/world/{name}')]
|
||||
|
@ -1,10 +1,12 @@
|
||||
<?php /** @var $this \Ardent\Undercurrent\View\BaseView */ ?>
|
||||
|
||||
<html lang="en">
|
||||
<head>
|
||||
<head>
|
||||
<title>Base view title</title>
|
||||
</head>
|
||||
<body>
|
||||
Base, slot: <?= $this->data['slot'] ?>
|
||||
</body>
|
||||
</head>
|
||||
<body>
|
||||
<a href="<?= $this->getRoute(\App\Controller\HelloWorldController::class, 'index') ?>">Index</a><br>
|
||||
Base slot: <br>
|
||||
<?= $this->data['slot'] ?>
|
||||
</body>
|
||||
</html>
|
@ -1,4 +1,5 @@
|
||||
<?php /** @var $this \Ardent\Undercurrent\View\BaseView */ ?>
|
||||
<?php $this->extends = '/base' ?>
|
||||
|
||||
Hello <a href="<?= $this->getRoute(\App\Controller\HelloWorldController::class, 'hello') ?>">index</a>!
|
||||
Hello world<br>
|
||||
<a href="<?= $this->getRoute(\App\Controller\HelloWorldController::class, 'routes') ?>">Routes</a>
|
||||
|
12
app/Template/routes.php
Normal file
12
app/Template/routes.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php /** @var $this \App\View\RouteView */ ?>
|
||||
|
||||
<?php
|
||||
foreach ($this->routes->getRoutes() as $route) {
|
||||
echo sprintf('<a href="%s">%s</a> - %s::%s<br>',
|
||||
$route->getRoute()->path,
|
||||
$route->getRoute()->path,
|
||||
$route->getController(),
|
||||
$route->getMethod()
|
||||
);
|
||||
}
|
||||
?>
|
14
app/View/RouteView.php
Normal file
14
app/View/RouteView.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\View;
|
||||
|
||||
use Ardent\Undercurrent\Http\RouterConfig;
|
||||
use Ardent\Undercurrent\View\BaseView;
|
||||
|
||||
class RouteView extends BaseView
|
||||
{
|
||||
public function __construct(protected readonly RouterConfig $routes)
|
||||
{
|
||||
parent::__construct('/routes.php', extends: '/base');
|
||||
}
|
||||
}
|
@ -72,7 +72,7 @@ class BaseKernel
|
||||
|
||||
echo $response->getBody();
|
||||
|
||||
echo '<pre>';
|
||||
echo '<pre>Log:<br>';
|
||||
foreach ($log->getLogs() as $log) {
|
||||
echo sprintf('%s<br>', $log);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user