From e270f9c588d7bd69b1843ca0ad3e8beb2aee684e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Thu, 3 Mar 2022 16:39:46 +0800 Subject: [PATCH] modify plugin name --- RpcJsonp.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/RpcJsonp.php b/RpcJsonp.php index 6136c39..cc0c076 100644 --- a/RpcJsonp.php +++ b/RpcJsonp.php @@ -2,6 +2,7 @@ namespace Kiri\Rpc; +use Exception; use Kiri; use Kiri\Abstracts\Component; use Kiri\Abstracts\Config; @@ -12,7 +13,6 @@ use Kiri\Context; use Kiri\Exception\ConfigException; use Kiri\Message\Constrict\RequestInterface; use Kiri\Message\Handler\DataGrip; -use Kiri\Message\Handler\Handler; use Kiri\Message\Handler\Router; use Kiri\Message\Handler\RouterCollector; use Kiri\Message\ServerRequest; @@ -25,6 +25,7 @@ use Kiri\Server\Events\OnTaskerStart; use Kiri\Server\Events\OnWorkerExit; use Kiri\Server\Events\OnWorkerStart; use Psr\Container\ContainerExceptionInterface; +use Psr\Container\ContainerInterface; use Psr\Container\NotFoundExceptionInterface; use Psr\Http\Message\ServerRequestInterface; use ReflectionException; @@ -57,6 +58,17 @@ class RpcJsonp extends Component implements OnConnectInterface, OnReceiveInterfa public RouterCollector $collector; + /** + * @param ContainerInterface $container + * @param array $config + * @throws Exception + */ + public function __construct(public ContainerInterface $container, array $config = []) + { + parent::__construct($config); + } + + /** * @return void * @throws ContainerExceptionInterface @@ -220,11 +232,11 @@ class RpcJsonp extends Component implements OnConnectInterface, OnReceiveInterfa try { $handler = $this->collector->find($data['service'], 'GET'); if (is_integer($handler) || is_null($handler)) { - throw new \Exception('Method not found', -32601); + throw new Exception('Method not found', -32601); } else { $controller = $handler->callback[0]; if (!method_exists($controller, $data['method'])) { - throw new \Exception('Method not found', -32601); + throw new Exception('Method not found', -32601); } $params = $this->container->getMethodParameters($controller::class, $data['method']); @@ -242,7 +254,7 @@ class RpcJsonp extends Component implements OnConnectInterface, OnReceiveInterfa /** * @param $params * @return ServerRequestInterface - * @throws \Exception + * @throws Exception */ private function createServerRequest($params): ServerRequestInterface {