2424use Symfony \Component \DependencyInjection \Compiler \CheckTypeDeclarationsPass ;
2525use Symfony \Component \DependencyInjection \Compiler \PassConfig ;
2626use Symfony \Component \DependencyInjection \Compiler \ResolveFactoryClassPass ;
27+ use Symfony \Component \DependencyInjection \Compiler \ResolveParameterPlaceHoldersPass ;
2728use Symfony \Component \DependencyInjection \Container ;
2829use Symfony \Component \DependencyInjection \ContainerBuilder ;
2930use Symfony \Component \DependencyInjection \Exception \InvalidArgumentException ;
@@ -49,8 +50,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4950 $ io = new SymfonyStyle ($ input , $ output );
5051 $ errorIo = $ io ->getErrorStyle ();
5152
53+ $ resolveEnvVars = $ input ->getOption ('resolve-env-vars ' );
54+
5255 try {
53- $ container = $ this ->getContainerBuilder ();
56+ $ container = $ this ->getContainerBuilder ($ resolveEnvVars );
5457 } catch (RuntimeException $ e ) {
5558 $ errorIo ->error ($ e ->getMessage ());
5659
@@ -60,7 +63,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6063 $ container ->setParameter ('container.build_time ' , time ());
6164
6265 try {
63- $ container ->compile (( bool ) $ input -> getOption ( ' resolve-env-vars ' ) );
66+ $ container ->compile ($ resolveEnvVars );
6467 } catch (InvalidArgumentException $ e ) {
6568 $ errorIo ->error ($ e ->getMessage ());
6669
@@ -72,7 +75,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7275 return 0 ;
7376 }
7477
75- private function getContainerBuilder (): ContainerBuilder
78+ private function getContainerBuilder (bool $ resolveEnvVars ): ContainerBuilder
7679 {
7780 if (isset ($ this ->container )) {
7881 return $ this ->container ;
@@ -99,16 +102,22 @@ private function getContainerBuilder(): ContainerBuilder
99102
100103 (new XmlFileLoader ($ container = new ContainerBuilder ($ parameterBag = new EnvPlaceholderParameterBag ()), new FileLocator ()))->load ($ kernelContainer ->getParameter ('debug.container.dump ' ));
101104
102- $ refl = new \ReflectionProperty ($ parameterBag , 'resolved ' );
103- $ refl ->setValue ($ parameterBag , true );
105+ if ($ resolveEnvVars ) {
106+ $ container ->getCompilerPassConfig ()->setOptimizationPasses ([new ResolveParameterPlaceHoldersPass (), new ResolveFactoryClassPass ()]);
107+ } else {
108+ $ refl = new \ReflectionProperty ($ parameterBag , 'resolved ' );
109+ $ refl ->setValue ($ parameterBag , true );
110+
111+ $ container ->getCompilerPassConfig ()->setOptimizationPasses ([new ResolveFactoryClassPass ()]);
112+ }
104113
105114 $ container ->getCompilerPassConfig ()->setBeforeOptimizationPasses ([]);
106- $ container ->getCompilerPassConfig ()->setOptimizationPasses ([new ResolveFactoryClassPass ()]);
107115 $ container ->getCompilerPassConfig ()->setBeforeRemovingPasses ([]);
108116 }
109117
110118 $ container ->setParameter ('container.build_hash ' , 'lint_container ' );
111119 $ container ->setParameter ('container.build_id ' , 'lint_container ' );
120+ $ container ->setParameter ('container.runtime_mode ' , 'web=0 ' );
112121
113122 $ container ->addCompilerPass (new CheckAliasValidityPass (), PassConfig::TYPE_BEFORE_REMOVING , -100 );
114123 $ container ->addCompilerPass (new CheckTypeDeclarationsPass (true ), PassConfig::TYPE_AFTER_REMOVING , -100 );
0 commit comments