Files
kiri-core/note/Route/Route.php
T

47 lines
1021 B
PHP
Raw Normal View History

2020-12-14 19:03:05 +08:00
<?php
2020-12-15 12:24:38 +08:00
namespace Annotation\Route;
2020-12-14 19:03:05 +08:00
2021-03-03 18:35:04 +08:00
use Annotation\Attribute;
2021-03-30 11:34:10 +08:00
use Exception;
2021-08-17 16:43:50 +08:00
use Http\Route\Router;
2021-08-11 01:04:57 +08:00
use Kiri\Kiri;
2020-12-14 19:03:05 +08:00
2021-03-03 18:35:04 +08:00
#[\Attribute(\Attribute::TARGET_METHOD)] class Route extends Attribute
2020-12-14 19:03:05 +08:00
{
2021-08-29 04:06:49 +08:00
/**
* Route constructor.
* @param string $uri
* @param string $method
* @param string $version
*/
2021-08-29 05:53:47 +08:00
public function __construct(public string $uri,public string $method,public string $version = 'v.1.0')
2021-08-29 04:06:49 +08:00
{
}
/**
2021-08-29 04:31:14 +08:00
* @param static $params
2021-08-29 04:06:49 +08:00
* @param mixed $class
* @param mixed|null $method
* @return Router
2021-08-29 04:31:14 +08:00
* @throws \Kiri\Exception\NotFindClassException
* @throws \ReflectionException
2021-08-29 04:06:49 +08:00
*/
2021-08-29 05:53:47 +08:00
public function execute(mixed $class, mixed $method = null): Router
2021-08-29 04:06:49 +08:00
{
// TODO: Implement setHandler() method.
$router = Kiri::app()->getRouter();
if (is_string($class)) {
$class = di($class);
}
2021-08-29 05:53:47 +08:00
$router->addRoute($this->uri, [$class, $method], strtoupper($this->method));
2021-08-29 04:06:49 +08:00
return $router;
}
2020-12-14 19:03:05 +08:00
}