This commit is contained in:
2020-12-15 18:42:54 +08:00
parent 2dbf71d29e
commit 8595962637
2 changed files with 28 additions and 8 deletions
+28 -7
View File
@@ -3,30 +3,51 @@
namespace Annotation\Route; namespace Annotation\Route;
use HttpServer\Route\Node as RNode;
use ReflectionException;
use Snowflake\Exception\NotFindClassException;
use Snowflake\Snowflake;
trait Node trait Node
{ {
/** /**
* @param $node * @param RNode $node
* @return mixed * @return RNode
* @throws
*/ */
public function add($node): mixed public function add(RNode $node): RNode
{ {
if (!empty($this->middleware)) { if (!empty($this->middleware)) {
$node->addMiddleware($this->middleware); $node->addMiddleware($this->reflectClass($this->middleware));
} }
if (!empty($this->interceptor)) { if (!empty($this->interceptor)) {
$node->addInterceptor($this->interceptor); $node->addInterceptor($this->reflectClass($this->interceptor));
} }
if (!empty($this->limits)) { if (!empty($this->limits)) {
$node->addLimits($this->limits); $node->addLimits($this->reflectClass($this->limits));
} }
if (!empty($this->after)) { if (!empty($this->after)) {
$node->addAfter($this->after); $node->addAfter($this->reflectClass($this->after));
} }
return $node; return $node;
} }
/**
* @param array $classes
* @return array
* @throws ReflectionException
* @throws NotFindClassException
*/
private function reflectClass(array $classes): array
{
$di = Snowflake::getDi();
foreach ($classes as $key => $class) {
$classes[$key] = [$di->get($class), 'onHandler'];
}
return $classes;
}
} }
-1
View File
@@ -51,7 +51,6 @@ class Reduce
if ($pipe instanceof Middleware) { if ($pipe instanceof Middleware) {
return $pipe->onHandler($passable, $stack); return $pipe->onHandler($passable, $stack);
} else { } else {
var_dump($pipe);
return call_user_func($pipe, $passable, $stack); return call_user_func($pipe, $passable, $stack);
} }
}; };