diff --git a/src/Protocol.php b/src/Protocol.php index 0017460..5bc6601 100644 --- a/src/Protocol.php +++ b/src/Protocol.php @@ -12,7 +12,7 @@ class Protocol * @param string $data * @return array|null */ - public static function parse(string $data) + public static function parse(string $data): ?array { if (!str_contains($data, Protocol::SPLIT_STRING)) { return null; diff --git a/src/Registry.php b/src/Registry.php index ad2ecd4..dacb16c 100644 --- a/src/Registry.php +++ b/src/Registry.php @@ -2,6 +2,10 @@ namespace Kiri\Rpc; +use Exception; +use Kiri\Exception\NotFindClassException; +use ReflectionException; + class Registry { // KV @@ -48,4 +52,17 @@ class Registry const DEFAULT_HTTP_TIMEOUT = 30; + /** + * @param $name + * @return array + * @throws NotFindClassException + * @throws ReflectionException + * @throws Exception + */ + public function getService($name): array + { + return di(Client::class)->get($name); + } + + } diff --git a/src/Service.php b/src/RpcProvider.php similarity index 80% rename from src/Service.php rename to src/RpcProvider.php index e1b6341..4dbca56 100644 --- a/src/Service.php +++ b/src/RpcProvider.php @@ -19,7 +19,7 @@ use Swoole\Server; /** * */ -class Service extends Tcp implements OnClose, OnConnect, OnReceive, OnRequest +class RpcProvider extends Tcp implements OnClose, OnConnect, OnReceive, OnRequest { @@ -33,14 +33,14 @@ class Service extends Tcp implements OnClose, OnConnect, OnReceive, OnRequest { $config['settings']['enable_delay_receive'] = true; $config['settings']['enable_unsafe_event'] = true; - $config['events'][Constant::RECEIVE] = [Service::class, 'onReceive']; - $implements = class_implements(Service::class); + $config['events'][Constant::RECEIVE] = [RpcProvider::class, 'onReceive']; + $implements = class_implements(RpcProvider::class); if (in_array(OnConnect::class, $implements)) { - $config['events'][Constant::CONNECT] = [Service::class, 'onConnect']; + $config['events'][Constant::CONNECT] = [RpcProvider::class, 'onConnect']; } if (in_array(OnClose::class, $implements)) { - $config['events'][Constant::DISCONNECT] = [Service::class, 'onDisconnect']; - $config['events'][Constant::CLOSE] = [Service::class, 'onClose']; + $config['events'][Constant::DISCONNECT] = [RpcProvider::class, 'onDisconnect']; + $config['events'][Constant::CLOSE] = [RpcProvider::class, 'onClose']; } $manager->addListener( $config['type'], $config['host'], $config['port'], $config['mode'], $config @@ -87,16 +87,14 @@ class Service extends Tcp implements OnClose, OnConnect, OnReceive, OnRequest public function onReceive(Server $server, int $fd, int $reactor_id, string $data): void { try { - - // TODO: Implement onReceive() method. [$cmd, [$body, $protocol]] = Protocol::parse($data); + + + + } catch(\Throwable $throwable){ } - - - - }