@@ -115,6 +115,7 @@ public static function generate(string $namespace, array $clients, SchemaRegistr
115
115
)
116
116
);
117
117
118
+ $ rawCallReturnTypes = [];
118
119
$ operationCalls = [];
119
120
$ callReturnTypes = [];
120
121
@@ -129,10 +130,10 @@ public static function generate(string $namespace, array $clients, SchemaRegistr
129
130
$ fallbackName = 'Operation \\' . $ operationGroup . '\\Response \\' . (new Convert (str_replace ('/ ' , '\\' , $ contentType ) . '\\H ' . $ code ))->toPascal ();
130
131
$ object = '\\' . $ namespace . 'Schema \\' . $ schemaRegistry ->get ($ contentTypeSchema ->schema , $ fallbackName );
131
132
$ callReturnTypes [] = ($ contentTypeSchema ->schema ->type === 'array ' ? '\\' . Observable::class . '< ' : '' ) . $ object . ($ contentTypeSchema ->schema ->type === 'array ' ? '> ' : '' );
132
- $ contentTypeCases [] = $ returnType [] = $ contentTypeSchema ->schema ->type === 'array ' ? '\\' . Observable::class : $ object ;
133
+ $ rawCallReturnTypes [] = $ contentTypeCases [] = $ returnType [] = $ contentTypeSchema ->schema ->type === 'array ' ? '\\' . Observable::class : $ object ;
133
134
}
134
135
if (count ($ contentTypeCases ) === 0 ) {
135
- $ returnType [] = $ callReturnTypes [] = 'int ' ;
136
+ $ rawCallReturnTypes [] = $ returnType [] = $ callReturnTypes [] = 'int ' ;
136
137
}
137
138
}
138
139
$ operationCalls [] = [
@@ -175,7 +176,7 @@ public static function generate(string $namespace, array $clients, SchemaRegistr
175
176
}
176
177
177
178
$ class ->addStmt (
178
- $ factory ->method ('call ' )->makePublic ()->setReturnType (
179
+ $ factory ->method ('callAsync ' )->makePublic ()->setReturnType (
179
180
new Node \Name ('\\' . PromiseInterface::class)
180
181
)->setDocComment (
181
182
new Doc (implode (PHP_EOL , [
@@ -340,6 +341,46 @@ public static function generate(string $namespace, array $clients, SchemaRegistr
340
341
))
341
342
);
342
343
344
+ $ class ->addStmt (
345
+ $ factory ->method ('call ' )->makePublic ()->setDocComment (
346
+ new Doc (implode (PHP_EOL , [
347
+ '/** ' ,
348
+ ' * @return ' . (function (array $ operationCalls ): string {
349
+ $ count = count ($ operationCalls );
350
+ $ lastItem = $ count - 1 ;
351
+ $ left = '' ;
352
+ $ right = '' ;
353
+ for ($ i = 0 ; $ i < $ count ; $ i ++) {
354
+ if ($ i !== $ lastItem ) {
355
+ $ left .= '($call is ' . $ operationCalls [$ i ]['className ' ] . '::OPERATION_MATCH ? ' . implode ('| ' , array_unique ($ operationCalls [$ i ]['returnType ' ])) . ' : ' ;
356
+ } else {
357
+ $ left .= implode ('| ' , array_unique ($ operationCalls [$ i ]['returnType ' ]));
358
+ }
359
+ $ right .= ') ' ;
360
+ }
361
+ return $ left . $ right ;
362
+ })($ operationCalls ),
363
+ ' */ ' ,
364
+ ]))
365
+ )->setReturnType (implode ('| ' , array_unique ($ rawCallReturnTypes )))->addParam ((new Param ('call ' ))->setType ('string ' ))->addParam ((new Param ('params ' ))->setType ('array ' )->setDefault ([]))->addStmt (new Node \Stmt \Return_ (
366
+ new Node \Expr \FuncCall (
367
+ new Node \Name ('\React\Async\await ' ),
368
+ [
369
+ new Node \Arg (
370
+ new Node \Expr \MethodCall (
371
+ new Node \Expr \Variable ('this ' ),
372
+ new Node \Name ('callAsync ' ),
373
+ [
374
+ new Node \Arg (new Node \Expr \Variable ('call ' )),
375
+ new Node \Arg (new Node \Expr \Variable ('params ' )),
376
+ ]
377
+ )
378
+ ),
379
+ ],
380
+ )
381
+ ))
382
+ );
383
+
343
384
yield new File ($ namespace . '\\' . 'Client ' , $ stmt ->addStmt ($ class )->getNode ());
344
385
}
345
386
}
0 commit comments