44
55namespace Netgen \ApiPlatformExtras \DependencyInjection ;
66
7- use RuntimeException ;
87use Symfony \Component \Config \Definition \ConfigurationInterface ;
98use Symfony \Component \Config \Resource \FileResource ;
109use Symfony \Component \DependencyInjection \ContainerBuilder ;
1110use Symfony \Component \DependencyInjection \Extension \Extension ;
1211use Symfony \Component \DependencyInjection \Extension \PrependExtensionInterface ;
13- use Symfony \Component \Yaml \Exception \ParseException ;
1412use Symfony \Component \Yaml \Yaml ;
1513
16- use function dirname ;
14+ use function file_get_contents ;
1715use function in_array ;
1816use function is_array ;
19- use function is_file ;
20- use function is_readable ;
21- use function sprintf ;
2217
2318final class NetgenApiPlatformExtrasExtension extends Extension implements PrependExtensionInterface
2419{
@@ -44,24 +39,10 @@ public function prepend(ContainerBuilder $container): void
4439 return ;
4540 }
4641
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 ));
42+ $ configFile = __DIR__ . '/../Resources/config/doctrine.yaml ' ;
43+ $ config = Yaml::parse ((string ) file_get_contents ($ configFile ));
6444 $ container ->prependExtensionConfig ('doctrine ' , $ config ['doctrine ' ]);
45+ $ container ->addResource (new FileResource ($ configFile ));
6546 }
6647
6748 /**
0 commit comments