19
19
use Symfony \CS \FileCacheManager ;
20
20
use Symfony \CS \Fixer ;
21
21
use Symfony \CS \FixerInterface ;
22
+ use WyriHaximus \ApiClient \Annotations \Nested ;
22
23
use WyriHaximus \ApiClient \Resource \ResourceInterface ;
23
24
24
25
class ResourceGenerator
@@ -260,6 +261,16 @@ protected function createBaseClass(array $yaml): string
260
261
$ class = $ factory ->class ($ yaml ['class ' ])
261
262
->implement ($ yaml ['class ' ] . 'Interface ' )
262
263
->makeAbstract ();
264
+
265
+ if (isset ($ yaml ['nested ' ])) {
266
+ $ nestedResources = [];
267
+ foreach ($ yaml ['nested ' ] as $ key => $ resource ) {
268
+ $ nestedResources [] = $ key . '=" ' . $ resource . '" ' ;
269
+ }
270
+ $ docBlock = "/** \r\n * @Nested( " . implode (', ' , $ nestedResources ) . ") \r\n */ " ;
271
+ $ class ->setDocComment ($ docBlock );
272
+ }
273
+
263
274
$ class ->addStmt (
264
275
new Node \Stmt \TraitUse ([
265
276
new Node \Name ('TransportAwareTrait ' )
@@ -275,13 +286,19 @@ protected function createBaseClass(array $yaml): string
275
286
$ class ->addStmt ($ this ->createMethod ($ factory , $ type , $ name , $ details ));
276
287
}
277
288
278
- $ node = $ factory ->namespace ($ yaml ['namespace ' ])
289
+ $ stmt = $ factory ->namespace ($ yaml ['namespace ' ]);
290
+ if (isset ($ yaml ['nested ' ])) {
291
+ $ stmt = $ stmt ->addStmt (
292
+ $ factory ->use (Nested::class)
293
+ );
294
+ }
295
+ $ stmt
279
296
->addStmt ($ factory ->use ('WyriHaximus\ApiClient\Resource\TransportAwareTrait ' ))
280
297
->addStmt ($ class )
281
-
282
- ->getNode ()
283
298
;
284
299
300
+ $ node = $ stmt ->getNode ();
301
+
285
302
$ prettyPrinter = new PrettyPrinter \Standard ();
286
303
return $ prettyPrinter ->prettyPrintFile ([
287
304
$ node
0 commit comments