改名
This commit is contained in:
@@ -6,6 +6,8 @@ namespace Annotation\Route;
|
|||||||
|
|
||||||
use Annotation\Attribute;
|
use Annotation\Attribute;
|
||||||
use HttpServer\Route\MiddlewareManager;
|
use HttpServer\Route\MiddlewareManager;
|
||||||
|
use ReflectionException;
|
||||||
|
use Snowflake\Exception\NotFindClassException;
|
||||||
use Snowflake\Snowflake;
|
use Snowflake\Snowflake;
|
||||||
use HttpServer\IInterface\Middleware as IMiddleware;
|
use HttpServer\IInterface\Middleware as IMiddleware;
|
||||||
|
|
||||||
@@ -30,7 +32,7 @@ use HttpServer\IInterface\Middleware as IMiddleware;
|
|||||||
|
|
||||||
$array = [];
|
$array = [];
|
||||||
foreach ($this->middleware as $value) {
|
foreach ($this->middleware as $value) {
|
||||||
$sn = Snowflake::createObject($value);
|
$sn = di($value);
|
||||||
if (!($sn instanceof IMiddleware)) {
|
if (!($sn instanceof IMiddleware)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -40,11 +42,13 @@ use HttpServer\IInterface\Middleware as IMiddleware;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mixed $class
|
* @param mixed $class
|
||||||
* @param mixed|null $method
|
* @param mixed|null $method
|
||||||
* @return Middleware
|
* @return $this
|
||||||
*/
|
* @throws ReflectionException
|
||||||
|
* @throws NotFindClassException
|
||||||
|
*/
|
||||||
public function execute(mixed $class, mixed $method = null): static
|
public function execute(mixed $class, mixed $method = null): static
|
||||||
{
|
{
|
||||||
$middleware = Snowflake::getDi()->get(MiddlewareManager::class);
|
$middleware = Snowflake::getDi()->get(MiddlewareManager::class);
|
||||||
|
|||||||
+33
-36
@@ -7,49 +7,46 @@ namespace Annotation\Route;
|
|||||||
use Annotation\Attribute;
|
use Annotation\Attribute;
|
||||||
use Exception;
|
use Exception;
|
||||||
use HttpServer\Route\Router;
|
use HttpServer\Route\Router;
|
||||||
use Snowflake\Exception\ConfigException;
|
|
||||||
use Snowflake\Snowflake;
|
use Snowflake\Snowflake;
|
||||||
|
|
||||||
#[\Attribute(\Attribute::TARGET_METHOD)] class Route extends Attribute
|
#[\Attribute(\Attribute::TARGET_METHOD)] class Route extends Attribute
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Route constructor.
|
* Route constructor.
|
||||||
* @param string $uri
|
* @param string $uri
|
||||||
* @param string $method
|
* @param string $method
|
||||||
* @param string $version
|
* @param string $version
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public string $uri,
|
public string $uri,
|
||||||
public string $method,
|
public string $method,
|
||||||
public string $version = 'v.1.0'
|
public string $version = 'v.1.0'
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mixed $class
|
* @param mixed $class
|
||||||
* @param mixed|null $method
|
* @param mixed|null $method
|
||||||
* @return Router
|
* @return Router
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function execute(mixed $class, mixed $method = null): Router
|
public function execute(mixed $class, mixed $method = null): Router
|
||||||
{
|
{
|
||||||
// TODO: Implement setHandler() method.
|
// TODO: Implement setHandler() method.
|
||||||
$router = Snowflake::app()->getRouter();
|
$router = Snowflake::app()->getRouter();
|
||||||
$node = $router->addRoute($this->uri, [$class, $method], $this->method);
|
$attribute = Snowflake::getDi()->getMethodAttribute($class::class, $method);
|
||||||
if ($node !== null) {
|
foreach ($attribute as $item) {
|
||||||
$attribute = Snowflake::getDi()->getMethodAttribute($class::class, $method);
|
if ($item instanceof Route) {
|
||||||
foreach ($attribute as $item) {
|
continue;
|
||||||
if ($item instanceof Route) {
|
}
|
||||||
continue;
|
$item->execute($class, $method);
|
||||||
}
|
}
|
||||||
$item->execute($class, $method);
|
$router->addRoute($this->uri, [$class, $method], $this->method);
|
||||||
}
|
return $router;
|
||||||
}
|
}
|
||||||
return $router;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user