44
55namespace Netgen \ApiPlatformExtras \DependencyInjection ;
66
7+ use RuntimeException ;
78use Symfony \Component \Config \Definition \ConfigurationInterface ;
9+ use Symfony \Component \Config \Resource \FileResource ;
810use Symfony \Component \DependencyInjection \ContainerBuilder ;
911use Symfony \Component \DependencyInjection \Extension \Extension ;
1012use Symfony \Component \DependencyInjection \Extension \PrependExtensionInterface ;
13+ use Symfony \Component \Yaml \Exception \ParseException ;
14+ use Symfony \Component \Yaml \Yaml ;
1115
1216use function dirname ;
1317use function in_array ;
1418use function is_array ;
19+ use function is_file ;
20+ use function is_readable ;
21+ use function sprintf ;
1522
1623final class NetgenApiPlatformExtrasExtension extends Extension implements PrependExtensionInterface
1724{
@@ -37,21 +44,24 @@ public function prepend(ContainerBuilder $container): void
3744 return ;
3845 }
3946
40- $ container ->prependExtensionConfig (
41- 'doctrine ' ,
42- [
43- 'orm ' => [
44- 'mappings ' => [
45- 'NetgenApiPlatformExtras ' => [
46- 'type ' => 'xml ' ,
47- 'is_bundle ' => false ,
48- 'dir ' => dirname (__DIR__ , 2 ) . '/config/doctrine ' ,
49- 'prefix ' => 'Netgen\ApiPlatformExtras\Entity ' ,
50- ],
51- ],
52- ],
53- ],
54- );
47+ $ configFile = dirname (__DIR__ , 2 ) . '/config/doctrine.yaml ' ;
48+
49+ if (!is_file ($ configFile ) || !is_readable ($ configFile )) {
50+ return ;
51+ }
52+
53+ try {
54+ $ config = Yaml::parseFile ($ configFile );
55+ } catch (ParseException $ e ) {
56+ throw new RuntimeException (sprintf ('Could not parse YAML file "%s": %s ' , $ configFile , $ e ->getMessage ()), 0 , $ e );
57+ }
58+
59+ if (!is_array ($ config )) {
60+ return ;
61+ }
62+
63+ $ container ->addResource (new FileResource ($ configFile ));
64+ $ container ->prependExtensionConfig ('doctrine ' , $ config ['doctrine ' ]);
5565 }
5666
5767 /**
0 commit comments