This commit is contained in:
as2252258@163.com
2021-08-29 04:06:49 +08:00
parent 9da50baed0
commit 133ca2c273
21 changed files with 356 additions and 495 deletions
+25 -31
View File
@@ -12,39 +12,33 @@ use Kiri\Kiri;
#[\Attribute(\Attribute::TARGET_METHOD)] class Route extends Attribute
{
/**
* Route constructor.
* @param string $uri
* @param string $method
* @param string $version
*/
public function __construct(
public string $uri,
public string $method,
public string $version = 'v.1.0'
)
{
$this->method = strtoupper($this->method);
}
/**
* Route constructor.
* @param string $uri
* @param string $method
* @param string $version
*/
public function __construct(string $uri, string $method, string $version = 'v.1.0')
{
}
/**
* @param mixed $class
* @param mixed|null $method
* @return Router
* @throws Exception
*/
public function execute(mixed $class, mixed $method = null): Router
{
// TODO: Implement setHandler() method.
$router = Kiri::app()->getRouter();
if (is_string($class)) {
$class = di($class);
}
$router->addRoute($this->uri, [$class, $method], $this->method);
return $router;
}
/**
* @param mixed $class
* @param mixed|null $method
* @return Router
* @throws Exception
*/
public static function execute(mixed $params, mixed $class, mixed $method = null): Router
{
// TODO: Implement setHandler() method.
$router = Kiri::app()->getRouter();
if (is_string($class)) {
$class = di($class);
}
$router->addRoute($params->uri, [$class, $method], strtoupper($params->method));
return $router;
}
}