1111
1212namespace Swoole ;
1313
14- use Swoole \Coroutine \Http \Client as HttpClient ;
1514use Swoole \RemoteObject \Client ;
1615use Swoole \RemoteObject \Exception ;
1716
@@ -23,7 +22,7 @@ class RemoteObject implements \ArrayAccess, \Stringable, \Iterator, \Countable
2322
2423 private string $ clientId ;
2524
26- private ?HttpClient $ client = null ;
25+ private ?Client $ client = null ;
2726
2827 public function __construct ($ coroutineId , $ clientId )
2928 {
@@ -89,7 +88,7 @@ public function __unserialize(array $data): void
8988 $ this ->objectId = $ data ['objectId ' ];
9089 $ this ->coroutineId = $ data ['coroutineId ' ];
9190 $ this ->clientId = $ data ['clientId ' ];
92- $ this ->client = Client::getClient ($ this ->clientId );
91+ $ this ->client = Client::getInstance ($ this ->clientId );
9392 }
9493
9594 public function __serialize (): array
@@ -122,7 +121,7 @@ public function __invoke(...$args)
122121 public static function call (Client $ client , string $ fn , array $ args )
123122 {
124123 $ object = new self (Coroutine::getCid (), $ client ->getId ());
125- $ object ->client = Client:: getClient ( $ client-> getId ()) ;
124+ $ object ->client = $ client ;
126125 $ rs = $ object ->execute ('/call_function ' , [
127126 'function ' => $ fn ,
128127 'args ' => serialize ($ args ),
@@ -141,7 +140,7 @@ public function getObjectId(): int
141140 public static function create (Client $ client , string $ class , array $ args ): RemoteObject
142141 {
143142 $ object = new self (Coroutine::getCid (), $ client ->getId ());
144- $ object ->client = Client:: getClient ( $ client-> getId ()) ;
143+ $ object ->client = $ client ;
145144 $ rs = $ object ->execute ('/new ' , [
146145 'class ' => $ class ,
147146 'args ' => serialize ($ args ),
@@ -236,15 +235,6 @@ private function execute(string $path, array $params = []): array
236235 if (!$ this ->client ) {
237236 throw new Exception ('This remote object is not bound to a client, and cannot initiate remote calls ' );
238237 }
239- $ rs = $ this ->client ->post ($ path , $ params );
240- if (!$ rs ) {
241- throw new Exception ($ this ->client ->errMsg );
242- }
243- $ result = unserialize ($ this ->client ->body );
244- if ($ result ['code ' ] != 0 ) {
245- $ ex = $ result ['exception ' ];
246- throw new Exception ('Server Error: ' . $ ex ['message ' ], $ ex ['code ' ]);
247- }
248- return $ result ;
238+ return $ this ->client ->execute ($ path , $ params );
249239 }
250240}
0 commit comments