42 lines
1,021 B
PHP
42 lines
1,021 B
PHP
<?php
|
|
// ResolvedRouteInfo.php
|
|
// Created: 2024-03-28
|
|
// Updated: 2024-03-28
|
|
|
|
namespace Index\Http\Routing;
|
|
|
|
class ResolvedRouteInfo {
|
|
public function __construct(
|
|
private array $middlewares,
|
|
private array $supportedMethods,
|
|
private mixed $handler,
|
|
private array $args,
|
|
) {}
|
|
|
|
public function runMiddleware(array $args): mixed {
|
|
foreach($this->middlewares as $middleware) {
|
|
$result = $middleware[0](...array_merge($args, $middleware[1]));
|
|
if($result !== null)
|
|
return $result;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public function hasHandler(): bool {
|
|
return $this->handler !== null;
|
|
}
|
|
|
|
public function hasOtherMethods(): bool {
|
|
return !empty($this->supportedMethods);
|
|
}
|
|
|
|
public function getSupportedMethods(): array {
|
|
return $this->supportedMethods;
|
|
}
|
|
|
|
public function dispatch(array $args): mixed {
|
|
return ($this->handler)(...array_merge($args, $this->args));
|
|
}
|
|
}
|