@@ -320,7 +320,7 @@ private function normalizeDefaults(array $defaults): array
320
320
321
321
private function registerMetadataConfiguration (ContainerBuilder $ container , array $ config , XmlFileLoader $ loader ): void
322
322
{
323
- [$ xmlResources , $ yamlResources ] = $ this ->getResourcesToWatch ($ container , $ config );
323
+ [$ xmlResources , $ yamlResources, $ phpResources ] = $ this ->getResourcesToWatch ($ container , $ config );
324
324
325
325
$ container ->setParameter ('api_platform.class_name_resources ' , $ this ->getClassNameResources ());
326
326
@@ -335,6 +335,7 @@ private function registerMetadataConfiguration(ContainerBuilder $container, arra
335
335
}
336
336
337
337
// V3 metadata
338
+ $ loader ->load ('metadata/php.xml ' );
338
339
$ loader ->load ('metadata/xml.xml ' );
339
340
$ loader ->load ('metadata/links.xml ' );
340
341
$ loader ->load ('metadata/property.xml ' );
@@ -353,6 +354,8 @@ private function registerMetadataConfiguration(ContainerBuilder $container, arra
353
354
$ container ->getDefinition ('api_platform.metadata.resource_extractor.yaml ' )->replaceArgument (0 , $ yamlResources );
354
355
$ container ->getDefinition ('api_platform.metadata.property_extractor.yaml ' )->replaceArgument (0 , $ yamlResources );
355
356
}
357
+
358
+ $ container ->getDefinition ('api_platform.metadata.resource_extractor.php_file ' )->replaceArgument (0 , $ phpResources );
356
359
}
357
360
358
361
private function getClassNameResources (): array
@@ -417,7 +420,32 @@ private function getResourcesToWatch(ContainerBuilder $container, array $config)
417
420
}
418
421
}
419
422
420
- $ resources = ['yml ' => [], 'xml ' => [], 'dir ' => []];
423
+ $ resources = ['yml ' => [], 'xml ' => [], 'php ' => [], 'dir ' => []];
424
+
425
+ foreach ($ config ['mapping ' ]['imports ' ] ?? [] as $ path ) {
426
+ if (is_dir ($ path )) {
427
+ foreach (Finder::create ()->followLinks ()->files ()->in ($ path )->name ('/\.php$/ ' )->sortByName () as $ file ) {
428
+ $ resources [$ file ->getExtension ()][] = $ file ->getRealPath ();
429
+ }
430
+
431
+ $ resources ['dir ' ][] = $ path ;
432
+ $ container ->addResource (new DirectoryResource ($ path , '/\.php$/ ' ));
433
+
434
+ continue ;
435
+ }
436
+
437
+ if ($ container ->fileExists ($ path , false )) {
438
+ if (!str_ends_with ($ path , '.php ' )) {
439
+ throw new RuntimeException (\sprintf ('Unsupported mapping type in "%s", supported type is PHP. ' , $ path ));
440
+ }
441
+
442
+ $ resources ['php ' ][] = $ path ;
443
+
444
+ continue ;
445
+ }
446
+
447
+ throw new RuntimeException (\sprintf ('Could not open file or directory "%s". ' , $ path ));
448
+ }
421
449
422
450
foreach ($ paths as $ path ) {
423
451
if (is_dir ($ path )) {
@@ -446,7 +474,7 @@ private function getResourcesToWatch(ContainerBuilder $container, array $config)
446
474
447
475
$ container ->setParameter ('api_platform.resource_class_directories ' , $ resources ['dir ' ]);
448
476
449
- return [$ resources ['xml ' ], $ resources ['yml ' ]];
477
+ return [$ resources ['xml ' ], $ resources ['yml ' ], $ resources [ ' php ' ] ];
450
478
}
451
479
452
480
private function registerOAuthConfiguration (ContainerBuilder $ container , array $ config ): void
0 commit comments