Add console
This commit is contained in:
@ -1,49 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Ardent\Undercurrent\Http;
|
||||
|
||||
use Ardent\Undercurrent\Container\ContainerInterface;
|
||||
use Ardent\Undercurrent\Logger\LogContainer;
|
||||
|
||||
class Renderer
|
||||
{
|
||||
public function __construct(
|
||||
private readonly ContainerInterface $container,
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
public function render(): void
|
||||
{
|
||||
$request = new GenericRequest(
|
||||
MethodEnum::from($_SERVER['REQUEST_METHOD']),
|
||||
$_SERVER['REQUEST_URI'],
|
||||
$_REQUEST,
|
||||
);
|
||||
$router = $this->container->get(RouterInterface::class);
|
||||
$log = $this->container->get(LogContainer::class);
|
||||
try {
|
||||
$response = $router->dispatch($request);
|
||||
} catch (\Throwable $e) {
|
||||
$response = new GenericResponse(
|
||||
$e->getMessage(),
|
||||
StatusEnum::NOT_FOUND
|
||||
);
|
||||
//$response = $container->get(RouterConfig::class)->getExceptionRoute()->getController()::exception($e);
|
||||
}
|
||||
|
||||
http_response_code($response->getStatus()->value);
|
||||
|
||||
foreach ($response->getHeaders() as $header) {
|
||||
header($header);
|
||||
}
|
||||
|
||||
echo $response->getBody();
|
||||
|
||||
echo '<pre>Log:<br>';
|
||||
foreach ($log->getLogs() as $log) {
|
||||
echo sprintf('%s<br>', $log);
|
||||
}
|
||||
echo '</pre>';
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user