chore: complete update

This commit is contained in:
2025-07-17 16:24:20 +02:00
parent 899227b0a4
commit 64a7051137
1300 changed files with 85570 additions and 2756 deletions

View File

@@ -4,48 +4,58 @@ declare(strict_types=1);
namespace App\Framework\Router;
use App\Framework\Http\HttpResponse;
use App\Framework\Core\DynamicRoute;
use App\Framework\DI\DefaultContainer;
use App\Framework\Http\Response;
use App\Framework\Http\Status;
use App\Framework\Http\Responses\NotFound;
use App\Framework\Router\Result\ContentNegotiationResult;
class RouteDispatcher
final readonly class RouteDispatcher
{
public function __construct(
private DefaultContainer $container,
private ParameterProcessor $parameterProcessor
) {}
/**
* Verarbeitet eine Route und führt den entsprechenden Controller-Action aus
*/
public function dispatch(RouteContext $routeContext): ActionResult|Response
{
$routeMatch = $routeContext->match;
if ($routeMatch->isMatch()) {
$controller = $routeMatch->route->controller;
$action = $routeMatch->route->action;
$params = $routeMatch->route->params;
$params = $this->prepareParameters(...$params);
$obj = new $controller();
$result = $obj->$action(...$params);
// Hier könntest du z. B. Response-Objekte erwarten oder generieren:
if ($result instanceof Response || $result instanceof ActionResult) {
return $result;
}
return $this->executeController($routeMatch);
}
// Fehlerbehandlung z.B. 404
return new HttpResponse(status: Status::NOT_FOUND, body: 'Nicht gefunden');
return new NotFound();
}
public function prepareParameters(...$params): mixed
/**
* Führt die Controller-Action mit den aufbereiteten Parametern aus
*/
private function executeController(RouteMatch $routeMatch): ActionResult|Response
{
$parameters = [];
foreach ($params as $param) {
if ($param['isBuiltin'] === true) {
$parameters[] = $param['default'];
} else {
#Container!
var_dump($param['isBuiltin']);
}
$controller = $routeMatch->route->controller;
$action = $routeMatch->route->action;
$params = $routeMatch->route->parameters;
$queryParams = [];
if($routeMatch->route instanceof DynamicRoute) {
$queryParams = $routeMatch->route->paramValues;
}
return $parameters;
$preparedParams = $this->parameterProcessor->prepareParameters($params, $queryParams);
$controllerInstance = $this->container->get($controller);
$result = $controllerInstance->$action(...$preparedParams);
if ($result instanceof Response || $result instanceof ActionResult) {
return $result;
}
// Wenn kein gültiges Result zurückgegeben wird
return new NotFound('Ungültige Antwort vom Controller');
}
}