49 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			49 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?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(RoutesConfig::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>';
 | |
|     }
 | |
| } |