diff --git a/src/Annotation/JsonRpcMethod.php b/src/Annotation/JsonRpcMethod.php deleted file mode 100644 index aa90dd7..0000000 --- a/src/Annotation/JsonRpcMethod.php +++ /dev/null @@ -1,44 +0,0 @@ -getReflectMethod($class, $method); - $parent = $reflect->getDeclaringClass()->getAttributes(JsonRpc::class); - - if (empty($parent)) { - return parent::execute($class, $method); - } - /** @var JsonRpc $attribute */ - $attribute = $parent[0]->newInstance(); - Router::addService($attribute->service, function () use ($class, $method) { - Router::jsonp($this->method, [di($class), $method]); - }, $attribute->version); - return parent::execute($class, $method); // TODO: Change the autogenerated stub - } - - -} diff --git a/src/Annotation/RpcProduct.php b/src/Annotation/RpcProduct.php deleted file mode 100644 index f14ecad..0000000 --- a/src/Annotation/RpcProduct.php +++ /dev/null @@ -1,42 +0,0 @@ -get($class); - - RpcManager::addCmdHandler($this->cmd, [$class, $method], $this->protocol); - - return parent::execute($class, $method); // TODO: Change the autogenerated stub - } - - -} diff --git a/src/JsonRpcConsumers.php b/src/JsonRpcConsumers.php index 3833262..1140bd8 100644 --- a/src/JsonRpcConsumers.php +++ b/src/JsonRpcConsumers.php @@ -23,29 +23,30 @@ abstract class JsonRpcConsumers implements OnRpcConsumerInterface public Pool $pool; + protected string $name = ''; + + /** - * @param string $service * @param string $method * @param mixed $data * @param string $version * @throws Exception */ - public function notify(string $service, string $method, mixed $data, string $version = '2.0'): void + public function notify(string $method, mixed $data, string $version = '2.0'): void { - $config = $this->get_consul($service); + $config = $this->get_consul($this->name); if (Context::inCoroutine()) { $client = $this->clientOnCoroutine($config); } else { $client = $this->clientNotCoroutine($config); } - $client->send(json_encode(['jsonrpc' => $version, 'service' => $service, 'method' => $method, 'params' => $data])); + $client->send(json_encode(['jsonrpc' => $version, 'service' => $this->name, 'method' => $method, 'params' => $data])); $client->recv(1); $client->close(); } /** - * @param string $service * @param string $method * @param mixed $data * @param string $version @@ -53,9 +54,9 @@ abstract class JsonRpcConsumers implements OnRpcConsumerInterface * @return mixed * @throws Exception */ - public function get(string $service, string $method, mixed $data, string $version = '2.0', string $id = ''): mixed + public function get(string $method, mixed $data, string $version = '2.0', string $id = ''): mixed { - $config = $this->get_consul($service); + $config = $this->get_consul($this->name); if (Context::inCoroutine()) { $client = $this->clientOnCoroutine($config); } else { @@ -64,7 +65,7 @@ abstract class JsonRpcConsumers implements OnRpcConsumerInterface if (empty($id)) $id = Number::create(time()); - $client->send(json_encode(['jsonrpc' => $version, 'service' => $service, 'method' => $method, 'params' => $data, 'id' => $id])); + $client->send(json_encode(['jsonrpc' => $version, 'service' => $this->name, 'method' => $method, 'params' => $data, 'id' => $id])); $read = $client->recv(); $client->close(); return json_decode($read, true); diff --git a/src/RpcManager.php b/src/RpcManager.php index ce70b25..b07e62b 100644 --- a/src/RpcManager.php +++ b/src/RpcManager.php @@ -26,8 +26,6 @@ class RpcManager foreach ($lists as $reflection) { $methodName = $reflection->getName(); -// -// $params = Kiri::getDi()->getMethodParameters($class, $methodName); static::$_rpc[$name][$methodName] = [[$class, $methodName], null]; }