改名
This commit is contained in:
+27
-5
@@ -5,7 +5,9 @@ namespace Annotation;
|
|||||||
|
|
||||||
|
|
||||||
use Closure;
|
use Closure;
|
||||||
|
use HttpServer\Route\Node;
|
||||||
use Snowflake\Exception\ComponentException;
|
use Snowflake\Exception\ComponentException;
|
||||||
|
use Snowflake\Exception\ConfigException;
|
||||||
use Snowflake\Snowflake;
|
use Snowflake\Snowflake;
|
||||||
|
|
||||||
#[\Attribute(\Attribute::TARGET_METHOD)] class Route implements IAnnotation
|
#[\Attribute(\Attribute::TARGET_METHOD)] class Route implements IAnnotation
|
||||||
@@ -16,26 +18,46 @@ use Snowflake\Snowflake;
|
|||||||
* Route constructor.
|
* Route constructor.
|
||||||
* @param string $uri
|
* @param string $uri
|
||||||
* @param string $method
|
* @param string $method
|
||||||
|
* @param string|array $middleware
|
||||||
|
* @param string|array $interceptor
|
||||||
|
* @param string|array $limits
|
||||||
|
* @param string|array $after
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public string $uri,
|
public string $uri,
|
||||||
public string $method
|
public string $method,
|
||||||
|
public string|array $middleware,
|
||||||
|
public string|array $interceptor,
|
||||||
|
public string|array $limits,
|
||||||
|
public string|array $after
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array|Closure $closure
|
* @param array|Closure $handler
|
||||||
* @return mixed
|
* @param array $attributes
|
||||||
|
* @return ?Node
|
||||||
* @throws ComponentException
|
* @throws ComponentException
|
||||||
|
* @throws ConfigException
|
||||||
*/
|
*/
|
||||||
public function setHandler(array|Closure $closure): mixed
|
public function setHandler(array|Closure $handler, array $attributes): ?Node
|
||||||
{
|
{
|
||||||
$router = Snowflake::app()->getRouter();
|
$router = Snowflake::app()->getRouter();
|
||||||
// TODO: Implement setHandler() method.
|
// TODO: Implement setHandler() method.
|
||||||
|
|
||||||
return $router->addRoute($this->uri, $closure, $this->method);
|
$node = $router->addRoute($this->uri, $handler, $this->method);
|
||||||
|
foreach ($attributes as $name => $attribute) {
|
||||||
|
$first = 'add' . ucfirst($attribute);
|
||||||
|
|
||||||
|
$_handler = is_array($handler) ? $handler[0] : $handler;
|
||||||
|
if (!method_exists($_handler, $first)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$node->$first($attribute);
|
||||||
|
}
|
||||||
|
return $node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user