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

45 lines
1.0 KiB
PHP
Raw Normal View History

2023-04-15 23:29:27 +08:00
<?php
2023-04-16 01:24:30 +08:00
declare(strict_types=1);
2023-04-15 23:29:27 +08:00
2023-04-16 20:36:47 +08:00
namespace Kiri\Router\Annotate;
2023-04-15 23:29:27 +08:00
2023-04-15 23:31:16 +08:00
use Exception;
2023-04-16 01:24:30 +08:00
use Kiri\Router\Constrict\RequestMethod;
2023-04-16 23:08:57 +08:00
use Kiri\Router\Interface\InjectRouteInterface;
2023-08-02 14:00:25 +08:00
use Kiri\Router\OptionsController;
2023-04-15 23:31:16 +08:00
use Kiri\Router\Router;
use ReflectionException;
2023-04-15 23:29:27 +08:00
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
class Get extends AbstractRequestMethod implements InjectRouteInterface
{
2023-08-02 14:00:25 +08:00
/**
* @param string $path
* @param string $version
*/
2023-11-14 00:09:52 +08:00
public function __construct(readonly public string $path, readonly public string $version = '')
2023-04-16 21:00:58 +08:00
{
}
2023-04-15 23:29:27 +08:00
/**
* @param object $class
* @param string $method
* @return void
2023-04-15 23:31:16 +08:00
* @throws ReflectionException
* @throws Exception
2023-04-15 23:29:27 +08:00
*/
public function dispatch(object $class, string $method): void
{
// TODO: Implement dispatch() method.
2023-04-25 17:22:37 +08:00
$path = '/' . ltrim($this->path, '/');
2023-11-14 00:09:52 +08:00
if (!empty($this->version)) {
$path = '/' . trim($this->version) . $path;
}
2023-04-19 12:35:39 +08:00
Router::addRoute(RequestMethod::REQUEST_GET, $path, [$class, $method]);
2023-04-15 23:29:27 +08:00
}
}