Removed old resolved route info class.

This commit is contained in:
flash 2025-03-07 22:09:52 +00:00
parent 6fec3889a6
commit 69e22beb08
Signed by: flash
GPG key ID: 2C9C2C574D47FE3E

View file

@ -1,62 +0,0 @@
<?php
// ResolvedRouteInfo.php
// Created: 2024-03-28
// Updated: 2025-03-02
namespace Index\Http\Routing;
/**
* Represents a resolved route.
*/
class ResolvedRouteInfo {
/**
* @param array{callable, mixed[]}[] $filters Filters that should be run prior to the route handler.
* @param string[] $supportedMethods HTTP methods that this route accepts.
* @param (callable(): mixed)|null $handler Route handler.
* @param mixed[] $args Argument list to pass to the filter and route handlers.
*/
public function __construct(
private array $filters,
public private(set) array $supportedMethods,
private mixed $handler,
private array $args,
) {}
/**
* Run filter handlers.
*
* @param mixed[] $args Additional arguments to pass to the filter handlers.
* @return mixed Return value from the first filter to return anything non-null, otherwise null.
*/
public function runFilters(array $args): mixed {
foreach($this->filters as $filter) {
$result = $filter[0](...array_merge($args, $filter[1]));
if($result !== null)
return $result;
}
return null;
}
/**
* Whether this route has a handler.
*
* @return bool true if it does.
*/
public function hasHandler(): bool {
return is_callable($this->handler);
}
/**
* Dispatches this route.
*
* @param mixed[] $args Additional arguments to pass to the route handler.
* @return mixed Return value of the route handler.
*/
public function dispatch(array $args): mixed {
if(!is_callable($this->handler))
return null;
return ($this->handler)(...array_merge($args, $this->args));
}
}