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

47 lines
1.1 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-12-18 21:55:44 +08:00
use Kiri;
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-04-15 23:31:16 +08:00
use Kiri\Router\Router;
2023-12-18 21:55:44 +08:00
use ReflectionClass;
2023-04-15 23:31:16 +08:00
use ReflectionException;
2023-04-15 23:29:27 +08:00
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
class Post 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-12-18 21:55:44 +08:00
/**
* @param ReflectionClass $class
* @param string $method
* @return void
* @throws ReflectionException
*/
public function dispatch(ReflectionClass $class, string $method): void
2023-04-15 23:29:27 +08:00
{
// TODO: Implement dispatch() method.
2023-12-18 21:55:44 +08:00
$controller = Kiri::getDi()->makeReflection($class);
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-12-18 21:55:44 +08:00
Router::addRoute(RequestMethod::REQUEST_POST, $path, [$controller, $method]);
2023-04-15 23:29:27 +08:00
}
2023-04-15 23:31:16 +08:00
2023-04-15 23:29:27 +08:00
}