This commit is contained in:
2021-08-06 10:50:07 +08:00
parent 857d5c0e13
commit 1dcace00ef
2 changed files with 43 additions and 42 deletions
+6 -2
View File
@@ -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;
} }
@@ -43,7 +45,9 @@ 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
{ {
+1 -4
View File
@@ -7,7 +7,6 @@ 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
@@ -38,8 +37,6 @@ use Snowflake\Snowflake;
{ {
// 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);
if ($node !== null) {
$attribute = Snowflake::getDi()->getMethodAttribute($class::class, $method); $attribute = Snowflake::getDi()->getMethodAttribute($class::class, $method);
foreach ($attribute as $item) { foreach ($attribute as $item) {
if ($item instanceof Route) { if ($item instanceof Route) {
@@ -47,7 +44,7 @@ use Snowflake\Snowflake;
} }
$item->execute($class, $method); $item->execute($class, $method);
} }
} $router->addRoute($this->uri, [$class, $method], $this->method);
return $router; return $router;
} }