@@ -305,7 +305,7 @@ private function normalizeDefaults(array $defaults): array
305
305
306
306
private function registerMetadataConfiguration (ContainerBuilder $ container , array $ config , XmlFileLoader $ loader ): void
307
307
{
308
- [$ xmlResources , $ yamlResources ] = $ this ->getResourcesToWatch ($ container , $ config );
308
+ [$ xmlResources , $ yamlResources, $ phpResources ] = $ this ->getResourcesToWatch ($ container , $ config );
309
309
310
310
$ container ->setParameter ('api_platform.class_name_resources ' , $ this ->getClassNameResources ());
311
311
@@ -320,6 +320,7 @@ private function registerMetadataConfiguration(ContainerBuilder $container, arra
320
320
}
321
321
322
322
// V3 metadata
323
+ $ loader ->load ('metadata/php.xml ' );
323
324
$ loader ->load ('metadata/xml.xml ' );
324
325
$ loader ->load ('metadata/links.xml ' );
325
326
$ loader ->load ('metadata/property.xml ' );
@@ -338,6 +339,8 @@ private function registerMetadataConfiguration(ContainerBuilder $container, arra
338
339
$ container ->getDefinition ('api_platform.metadata.resource_extractor.yaml ' )->replaceArgument (0 , $ yamlResources );
339
340
$ container ->getDefinition ('api_platform.metadata.property_extractor.yaml ' )->replaceArgument (0 , $ yamlResources );
340
341
}
342
+
343
+ $ container ->getDefinition ('api_platform.metadata.resource_extractor.php_file ' )->replaceArgument (0 , $ phpResources );
341
344
}
342
345
343
346
private function getClassNameResources (): array
@@ -402,7 +405,32 @@ private function getResourcesToWatch(ContainerBuilder $container, array $config)
402
405
}
403
406
}
404
407
405
- $ resources = ['yml ' => [], 'xml ' => [], 'dir ' => []];
408
+ $ resources = ['yml ' => [], 'xml ' => [], 'php ' => [], 'dir ' => []];
409
+
410
+ foreach ($ config ['mapping ' ]['imports ' ] ?? [] as $ path ) {
411
+ if (is_dir ($ path )) {
412
+ foreach (Finder::create ()->followLinks ()->files ()->in ($ path )->name ('/\.php$/ ' )->sortByName () as $ file ) {
413
+ $ resources [$ file ->getExtension ()][] = $ file ->getRealPath ();
414
+ }
415
+
416
+ $ resources ['dir ' ][] = $ path ;
417
+ $ container ->addResource (new DirectoryResource ($ path , '/\.php$/ ' ));
418
+
419
+ continue ;
420
+ }
421
+
422
+ if ($ container ->fileExists ($ path , false )) {
423
+ if (!preg_match ('/\.php$/ ' , (string ) $ path , $ matches )) {
424
+ throw new RuntimeException (\sprintf ('Unsupported mapping type in "%s", supported type is PHP. ' , $ path ));
425
+ }
426
+
427
+ $ resources ['php ' === $ matches [1 ]][] = $ path ;
428
+
429
+ continue ;
430
+ }
431
+
432
+ throw new RuntimeException (\sprintf ('Could not open file or directory "%s". ' , $ path ));
433
+ }
406
434
407
435
foreach ($ paths as $ path ) {
408
436
if (is_dir ($ path )) {
@@ -431,7 +459,7 @@ private function getResourcesToWatch(ContainerBuilder $container, array $config)
431
459
432
460
$ container ->setParameter ('api_platform.resource_class_directories ' , $ resources ['dir ' ]);
433
461
434
- return [$ resources ['xml ' ], $ resources ['yml ' ]];
462
+ return [$ resources ['xml ' ], $ resources ['yml ' ], $ resources [ ' php ' ] ];
435
463
}
436
464
437
465
private function registerOAuthConfiguration (ContainerBuilder $ container , array $ config ): void
0 commit comments