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

48 lines
843 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
use Closure;
2020-12-15 12:24:38 +08:00
use Exception;
2020-12-15 12:07:46 +08:00
use HttpServer\Route\Node;
2020-12-14 19:03:05 +08:00
use Snowflake\Exception\ComponentException;
2020-12-15 12:07:46 +08:00
use Snowflake\Exception\ConfigException;
2020-12-14 19:03:05 +08:00
use Snowflake\Snowflake;
2020-12-15 12:24:38 +08:00
use Annotation\IAnnotation;
2020-12-14 19:03:05 +08:00
#[\Attribute(\Attribute::TARGET_METHOD)] class Route implements IAnnotation
{
/**
* Route constructor.
* @param string $uri
* @param string $method
*/
public function __construct(
public string $uri,
2020-12-16 15:37:23 +08:00
public string $method
2020-12-14 19:03:05 +08:00
)
{
}
/**
2020-12-15 12:07:46 +08:00
* @param array|Closure $handler
* @return ?Node
2020-12-14 19:03:05 +08:00
* @throws ComponentException
2020-12-15 12:07:46 +08:00
* @throws ConfigException
2020-12-15 12:24:38 +08:00
* @throws Exception
2020-12-14 19:03:05 +08:00
*/
2020-12-15 15:54:29 +08:00
public function setHandler(array|Closure $handler): ?Node
2020-12-14 19:03:05 +08:00
{
$router = Snowflake::app()->getRouter();
// TODO: Implement setHandler() method.
2020-12-16 15:37:23 +08:00
return $router->addRoute($this->uri, $handler, $this->method);
2020-12-14 19:03:05 +08:00
}
}