@@ -320,7 +320,7 @@ private function normalizeDefaults(array $defaults): array
320320
321321 private function registerMetadataConfiguration (ContainerBuilder $ container , array $ config , XmlFileLoader $ loader ): void
322322 {
323- [$ xmlResources , $ yamlResources ] = $ this ->getResourcesToWatch ($ container , $ config );
323+ [$ xmlResources , $ yamlResources, $ phpResources ] = $ this ->getResourcesToWatch ($ container , $ config );
324324
325325 $ container ->setParameter ('api_platform.class_name_resources ' , $ this ->getClassNameResources ());
326326
@@ -335,6 +335,7 @@ private function registerMetadataConfiguration(ContainerBuilder $container, arra
335335 }
336336
337337 // V3 metadata
338+ $ loader ->load ('metadata/php.xml ' );
338339 $ loader ->load ('metadata/xml.xml ' );
339340 $ loader ->load ('metadata/links.xml ' );
340341 $ loader ->load ('metadata/property.xml ' );
@@ -353,6 +354,8 @@ private function registerMetadataConfiguration(ContainerBuilder $container, arra
353354 $ container ->getDefinition ('api_platform.metadata.resource_extractor.yaml ' )->replaceArgument (0 , $ yamlResources );
354355 $ container ->getDefinition ('api_platform.metadata.property_extractor.yaml ' )->replaceArgument (0 , $ yamlResources );
355356 }
357+
358+ $ container ->getDefinition ('api_platform.metadata.resource_extractor.php_file ' )->replaceArgument (0 , $ phpResources );
356359 }
357360
358361 private function getClassNameResources (): array
@@ -417,7 +420,32 @@ private function getResourcesToWatch(ContainerBuilder $container, array $config)
417420 }
418421 }
419422
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+ }
421449
422450 foreach ($ paths as $ path ) {
423451 if (is_dir ($ path )) {
@@ -446,7 +474,7 @@ private function getResourcesToWatch(ContainerBuilder $container, array $config)
446474
447475 $ container ->setParameter ('api_platform.resource_class_directories ' , $ resources ['dir ' ]);
448476
449- return [$ resources ['xml ' ], $ resources ['yml ' ]];
477+ return [$ resources ['xml ' ], $ resources ['yml ' ], $ resources [ ' php ' ] ];
450478 }
451479
452480 private function registerOAuthConfiguration (ContainerBuilder $ container , array $ config ): void
0 commit comments