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 ;
28+ use Symfony \Component \DependencyInjection \Container ;
2729use Symfony \Component \DependencyInjection \ContainerBuilder ;
2830use Symfony \Component \DependencyInjection \Exception \InvalidArgumentException ;
2931use Symfony \Component \DependencyInjection \Loader \XmlFileLoader ;
@@ -48,8 +50,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4850 $ io = new SymfonyStyle ($ input , $ output );
4951 $ errorIo = $ io ->getErrorStyle ();
5052
53+ $ resolveEnvVars = $ input ->getOption ('resolve-env-vars ' );
54+
5155 try {
52- $ container = $ this ->getContainerBuilder ();
56+ $ container = $ this ->getContainerBuilder ($ resolveEnvVars );
5357 } catch (RuntimeException $ e ) {
5458 $ errorIo ->error ($ e ->getMessage ());
5559
@@ -59,7 +63,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5963 $ container ->setParameter ('container.build_time ' , time ());
6064
6165 try {
62- $ container ->compile (( bool ) $ input -> getOption ( ' resolve-env-vars ' ) );
66+ $ container ->compile ($ resolveEnvVars );
6367 } catch (InvalidArgumentException $ e ) {
6468 $ errorIo ->error ($ e ->getMessage ());
6569
@@ -71,7 +75,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7175 return 0 ;
7276 }
7377
74- private function getContainerBuilder (): ContainerBuilder
78+ private function getContainerBuilder (bool $ resolveEnvVars ): ContainerBuilder
7579 {
7680 if (isset ($ this ->container )) {
7781 return $ this ->container ;
@@ -103,17 +107,23 @@ private function getContainerBuilder(): ContainerBuilder
103107 throw new RuntimeException (\sprintf ('This command does not support the application container: "%s" is not a "%s". ' , get_debug_type ($ container ), ContainerBuilder::class));
104108 }
105109
106- $ parameterBag = $ container ->getParameterBag ();
107- $ refl = new \ReflectionProperty ($ parameterBag , 'resolved ' );
108- $ refl ->setValue ($ parameterBag , true );
110+ if ($ resolveEnvVars ) {
111+ $ container ->getCompilerPassConfig ()->setOptimizationPasses ([new ResolveParameterPlaceHoldersPass (), new ResolveFactoryClassPass ()]);
112+ } else {
113+ $ parameterBag = $ container ->getParameterBag ();
114+ $ refl = new \ReflectionProperty ($ parameterBag , 'resolved ' );
115+ $ refl ->setValue ($ parameterBag , true );
116+
117+ $ container ->getCompilerPassConfig ()->setOptimizationPasses ([new ResolveFactoryClassPass ()]);
118+ }
109119
110120 $ container ->getCompilerPassConfig ()->setBeforeOptimizationPasses ([]);
111- $ container ->getCompilerPassConfig ()->setOptimizationPasses ([new ResolveFactoryClassPass ()]);
112121 $ container ->getCompilerPassConfig ()->setBeforeRemovingPasses ([]);
113122 }
114123
115124 $ container ->setParameter ('container.build_hash ' , 'lint_container ' );
116125 $ container ->setParameter ('container.build_id ' , 'lint_container ' );
126+ $ container ->setParameter ('container.runtime_mode ' , 'web=0 ' );
117127
118128 $ container ->addCompilerPass (new CheckAliasValidityPass (), PassConfig::TYPE_BEFORE_REMOVING , -100 );
119129 $ container ->addCompilerPass (new CheckTypeDeclarationsPass (true ), PassConfig::TYPE_AFTER_REMOVING , -100 );
0 commit comments