Files
kiri-router/src/Annotate/Route.php
T

38 lines
854 B
PHP
Raw Normal View History

2023-04-16 20:25:37 +08:00
<?php
2023-04-16 20:36:47 +08:00
namespace Kiri\Router\Annotate;
2023-04-16 20:25:37 +08:00
use Kiri\Router\Constrict\RequestMethod;
2023-04-16 23:08:57 +08:00
use Kiri\Router\Interface\InjectRouteInterface;
2023-04-16 20:25:37 +08:00
use Kiri\Router\Router;
2023-04-19 12:35:39 +08:00
use ReflectionException;
2023-04-16 20:25:37 +08:00
#[\Attribute(\Attribute::TARGET_METHOD)]
class Route extends AbstractRequestMethod implements InjectRouteInterface
{
/**
* @param string $path
* @param RequestMethod $method
*/
2023-04-19 12:35:39 +08:00
public function __construct(readonly public string $path, readonly public RequestMethod $method, readonly public string $version = 'v1')
2023-04-16 20:25:37 +08:00
{
}
/**
* @param object $class
* @param string $method
* @return void
2023-04-19 12:35:39 +08:00
* @throws ReflectionException
2023-04-16 20:25:37 +08:00
*/
public function dispatch(object $class, string $method): void
{
// TODO: Implement dispatch() method.
2023-04-19 12:35:39 +08:00
$path = $this->version . '/' . ltrim($this->path, '/');
Router::addRoute([$this->method], $path, [$class, $method]);
2023-04-16 20:25:37 +08:00
}
}