47 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			47 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| namespace App\Controller;
 | |
| 
 | |
| use Ardent\Undercurrent\Attribute\Route;
 | |
| use Ardent\Undercurrent\Http\GenericResponse;
 | |
| use Ardent\Undercurrent\Http\ResponseInterface;
 | |
| use Ardent\Undercurrent\Http\RouterConfig;
 | |
| use Ardent\Undercurrent\Http\StatusEnum;
 | |
| 
 | |
| class HelloWorldController
 | |
| {
 | |
|     #[Route('/')]
 | |
|     public function index(): ResponseInterface
 | |
|     {
 | |
|         return new GenericResponse('Index, <a href="/hello">Hello</a>');
 | |
|     }
 | |
| 
 | |
|     #[Route('/error')]
 | |
|     public function error(): ResponseInterface
 | |
|     {
 | |
|         return new GenericResponse('error', StatusEnum::NOT_FOUND);
 | |
|     }
 | |
| 
 | |
|     #[Route('/hello')]
 | |
|     public function hello(): ResponseInterface
 | |
|     {
 | |
|         return new GenericResponse('Hello World!');
 | |
|     }
 | |
| 
 | |
|     #[Route('/routes')]
 | |
|     public function routes(RouterConfig $config): ResponseInterface
 | |
|     {
 | |
|         $routes = implode('<br>', array_map(
 | |
|             fn($route) => sprintf('%s - %s->%s', $route->getRoute()->path, $route->getController(), $route->getMethod()),
 | |
|             $config->getRoutes()
 | |
|         ));
 | |
| 
 | |
|         return new GenericResponse($routes);
 | |
|     }
 | |
| 
 | |
|     #[Route('/world/{name}')]
 | |
|     public function world(string $name): ResponseInterface
 | |
|     {
 | |
|         return new GenericResponse("Hello $name!");
 | |
|     }
 | |
| } |