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;
|
|
|
|
|
|
|
|
|
|
#[\Attribute(\Attribute::TARGET_METHOD)]
|
|
|
|
|
class Route extends AbstractRequestMethod implements InjectRouteInterface
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param string $path
|
|
|
|
|
* @param RequestMethod $method
|
|
|
|
|
*/
|
|
|
|
|
public function __construct(readonly public string $path, readonly public RequestMethod $method)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param object $class
|
|
|
|
|
* @param string $method
|
|
|
|
|
* @return void
|
|
|
|
|
* @throws \ReflectionException
|
|
|
|
|
*/
|
|
|
|
|
public function dispatch(object $class, string $method): void
|
|
|
|
|
{
|
|
|
|
|
// TODO: Implement dispatch() method.
|
|
|
|
|
Router::addRoute($this->method, $this->path, [$class, $method]);
|
|
|
|
|
}
|
|
|
|
|
}
|