diff --git a/src/json-rpc/src/ConfigProvider.php b/src/json-rpc/src/ConfigProvider.php index e9f4f3961..eac23e196 100644 --- a/src/json-rpc/src/ConfigProvider.php +++ b/src/json-rpc/src/ConfigProvider.php @@ -12,6 +12,10 @@ declare(strict_types=1); namespace Hyperf\JsonRpc; +use Hyperf\JsonRpc\Listener\RegisterProtocolListener; +use Hyperf\JsonRpc\Listener\RegisterServiceListener; +use Hyperf\ServiceGovernance\ServiceManager; + class ConfigProvider { public function __invoke(): array @@ -23,6 +27,15 @@ class ConfigProvider ], 'commands' => [ ], + 'listeners' => [ + RegisterProtocolListener::class, + value(function () { + if (class_exists(ServiceManager::class)) { + return RegisterServiceListener::class; + } + return null; + }), + ], 'scan' => [ 'paths' => [ __DIR__, diff --git a/src/json-rpc/src/Listener/RegisterProtocolListener.php b/src/json-rpc/src/Listener/RegisterProtocolListener.php index ed13faefd..1cc8c2a25 100644 --- a/src/json-rpc/src/Listener/RegisterProtocolListener.php +++ b/src/json-rpc/src/Listener/RegisterProtocolListener.php @@ -12,10 +12,9 @@ declare(strict_types=1); namespace Hyperf\JsonRpc\Listener; -use Hyperf\Event\Annotation\Listener; use Hyperf\Event\Contract\ListenerInterface; -use Hyperf\Framework\Event\BeforeServerStart; use Hyperf\Framework\Event\BeforeWorkerStart; +use Hyperf\Framework\Event\BootApplication; use Hyperf\JsonRpc\DataFormatter; use Hyperf\JsonRpc\JsonRpcHttpTransporter; use Hyperf\JsonRpc\JsonRpcTransporter; @@ -23,9 +22,6 @@ use Hyperf\JsonRpc\PathGenerator; use Hyperf\Rpc\ProtocolManager; use Hyperf\Utils\Packer\JsonPacker; -/** - * @Listener - */ class RegisterProtocolListener implements ListenerInterface { /** @@ -41,7 +37,7 @@ class RegisterProtocolListener implements ListenerInterface public function listen(): array { return [ - BeforeServerStart::class, + BootApplication::class, ]; } diff --git a/src/json-rpc/src/Listener/RegisterServiceListener.php b/src/json-rpc/src/Listener/RegisterServiceListener.php index 5ac4b91ae..5b07f0dd9 100644 --- a/src/json-rpc/src/Listener/RegisterServiceListener.php +++ b/src/json-rpc/src/Listener/RegisterServiceListener.php @@ -12,14 +12,10 @@ declare(strict_types=1); namespace Hyperf\JsonRpc\Listener; -use Hyperf\Event\Annotation\Listener; use Hyperf\Event\Contract\ListenerInterface; use Hyperf\RpcServer\Event\AfterPathRegister; use Hyperf\ServiceGovernance\ServiceManager; -/** - * @Listener - */ class RegisterServiceListener implements ListenerInterface { /** diff --git a/src/rpc/src/ProtocolManager.php b/src/rpc/src/ProtocolManager.php index a040261e5..50c667885 100644 --- a/src/rpc/src/ProtocolManager.php +++ b/src/rpc/src/ProtocolManager.php @@ -68,7 +68,7 @@ class ProtocolManager { $result = $this->config->get('protocols.' . Str::lower($name) . '.' . Str::lower($target)); if (! is_string($result)) { - throw new InvalidArgumentException(sprintf('Data Formatter %s is not exists.', Str::studly($target, ' '))); + throw new InvalidArgumentException(sprintf('%s is not exists.', Str::studly($target, ' '))); } return $result; }