This commit is contained in:
2021-07-27 14:15:08 +08:00
parent dcb588e02d
commit 8ee27b9b14
2 changed files with 245 additions and 247 deletions
+6 -9
View File
@@ -9,7 +9,6 @@ use Annotation\Route\RpcProducer;
use Closure; use Closure;
use Exception; use Exception;
use HttpServer\Abstracts\HttpService; use HttpServer\Abstracts\HttpService;
use HttpServer\Controller;
use HttpServer\Http\Context; use HttpServer\Http\Context;
use HttpServer\Http\Request; use HttpServer\Http\Request;
use JetBrains\PhpStorm\Pure; use JetBrains\PhpStorm\Pure;
@@ -116,26 +115,24 @@ class Node extends HttpService
/** @var Aop $aop */ /** @var Aop $aop */
$aop = Snowflake::app()->get('aop'); $aop = Snowflake::app()->get('aop');
if ($this->handler instanceof Closure || !$aop->hasAop($this->handler)) { if ($this->handler instanceof Closure || !$aop->hasAop($this->handler)) {
return static function () use ($application) { return (static function ($application) {
$dispatchParam = Context::getContext('dispatch-param', [\request()]); $dispatchParam = Context::getContext('dispatch-param', [\request()]);
if (is_array($application->handler)){ if (is_array($application->handler)) {
Snowflake::injectProperty($application->handler[0]); Snowflake::injectProperty($application->handler[0]);
} }
return call_user_func($application->handler, ...$dispatchParam); return call_user_func($application->handler, ...$dispatchParam);
}; })($application);
} }
$reflect = $aop->getAop($this->handler); $reflect = $aop->getAop($this->handler);
$callback = [$reflect->getMethod('invoke'), 'invokeArgs']; return (static function ($callback, $application, $reflect) {
return static function () use ($callback, $application, $reflect) {
$dispatchParam = Context::getContext('dispatch-param', [\request()]); $dispatchParam = Context::getContext('dispatch-param', [\request()]);
$asp = $reflect->newInstance($application->handler); $asp = $reflect->newInstance($application->handler);
if (is_array($application->handler)){ if (is_array($application->handler)) {
Snowflake::injectProperty($application->handler[0]); Snowflake::injectProperty($application->handler[0]);
} }
call_user_func($callback, $asp, $dispatchParam); call_user_func($callback, $asp, $dispatchParam);
}; })([$reflect->getMethod('invoke'), 'invokeArgs'], $application, $reflect);
} }
+2 -1
View File
@@ -12,6 +12,7 @@ use Exception;
use HttpServer\IInterface\Task; use HttpServer\IInterface\Task;
use JetBrains\PhpStorm\Pure; use JetBrains\PhpStorm\Pure;
use ReflectionException; use ReflectionException;
use ReflectionProperty;
use Snowflake\Abstracts\Config; use Snowflake\Abstracts\Config;
use Snowflake\Core\Json; use Snowflake\Core\Json;
use Snowflake\Di\Container; use Snowflake\Di\Container;
@@ -58,7 +59,7 @@ class Snowflake
$attributes = static::getDi()->getClassProperty($class::class); $attributes = static::getDi()->getClassProperty($class::class);
/** /**
* @var string $property * @var string $property
* @var \ReflectionProperty $attribute * @var ReflectionProperty $attribute
*/ */
foreach ($attributes as $property => $attribute) { foreach ($attributes as $property => $attribute) {