Implement commands

This commit is contained in:
Tim
2023-08-16 16:04:35 +02:00
parent 1ee5c1c992
commit f8d1c66934
17 changed files with 200 additions and 48 deletions

54
src/Http/RoutesConfig.php Normal file
View File

@ -0,0 +1,54 @@
<?php
namespace Ardent\Undercurrent\Http;
use Ardent\Undercurrent\Attribute\Route;
use ReflectionAttribute;
use ReflectionClass;
class RoutesConfig
{
/**
* @var array<RouteConfig>
*/
private array $routes = [];
private array $controllers = [];
public function add(string $controllerClass): self
{
$this->controllers[] = $controllerClass;
$reflectionClass = new ReflectionClass($controllerClass);
foreach ($reflectionClass->getMethods() as $method) {
$attributes = $method->getAttributes(Route::class, ReflectionAttribute::IS_INSTANCEOF);
if (count($attributes) === 0) {
continue;
}
$route = $attributes[0]->newInstance();
$this->routes[] = new RouteConfig(
$route,
$controllerClass,
$method->getName(),
);
}
return $this;
}
/**
* @return array<RouteConfig>
*/
public function getRoutes(): array
{
return $this->routes;
}
public function getControllers(): array
{
return $this->controllers;
}
}