From 1eb6d7000c6d4b3c2318e2b04b34b04282d8eff6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Thu, 28 Oct 2021 14:02:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/RpcJsonp.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/RpcJsonp.php b/src/RpcJsonp.php index 70c15a3..e2c2367 100644 --- a/src/RpcJsonp.php +++ b/src/RpcJsonp.php @@ -6,8 +6,11 @@ use Annotation\Inject; use Http\Constrict\ResponseInterface; use Http\Handler\Abstracts\HandlerManager; use Http\Handler\Dispatcher; +use Http\Handler\Handler; use Http\Handler\Router; use Http\Message\ServerRequest; +use Kiri\Kiri; +use ReflectionMethod; use Server\SInterface\OnCloseInterface; use Server\SInterface\OnConnectInterface; use Server\SInterface\OnReceiveInterface; @@ -133,14 +136,22 @@ class RpcJsonp implements OnConnectInterface, OnReceiveInterface, OnCloseInterfa /** - * @param $handler + * @param Handler $handler * @param $data * @return array * @throws \Exception */ - private function handler($handler, $data): array + private function handler(Handler $handler, $data): array { - $dispatcher = (new Dispatcher($handler, $handler->_middlewares))->handle(new ServerRequest()); + $handler->params = []; + + /** @var ReflectionMethod $reflection */ + $reflection = Kiri::getDi()->getReflectMethod($handler->callback[0]::class, $handler->callback[1]); + foreach ($reflection->getParameters() as $value) { + $handler->params[] = $data['params'][$value->getName()] ?? null; + } + + $dispatcher = (new Dispatcher($handler, $handler->_middlewares))->handle((new ServerRequest())->withData($data['params'])); if ($dispatcher instanceof ResponseInterface) { $dispatcher = json_decode($dispatcher->getBody()->getContents(), true); }