24
24
use Symfony \Component \DependencyInjection \Compiler \CheckTypeDeclarationsPass ;
25
25
use Symfony \Component \DependencyInjection \Compiler \PassConfig ;
26
26
use Symfony \Component \DependencyInjection \Compiler \ResolveFactoryClassPass ;
27
+ use Symfony \Component \DependencyInjection \Compiler \ResolveParameterPlaceHoldersPass ;
28
+ use Symfony \Component \DependencyInjection \Container ;
27
29
use Symfony \Component \DependencyInjection \ContainerBuilder ;
28
30
use Symfony \Component \DependencyInjection \Exception \InvalidArgumentException ;
29
31
use Symfony \Component \DependencyInjection \Loader \XmlFileLoader ;
@@ -48,8 +50,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
48
50
$ io = new SymfonyStyle ($ input , $ output );
49
51
$ errorIo = $ io ->getErrorStyle ();
50
52
53
+ $ resolveEnvVars = $ input ->getOption ('resolve-env-vars ' );
54
+
51
55
try {
52
- $ container = $ this ->getContainerBuilder ();
56
+ $ container = $ this ->getContainerBuilder ($ resolveEnvVars );
53
57
} catch (RuntimeException $ e ) {
54
58
$ errorIo ->error ($ e ->getMessage ());
55
59
@@ -59,7 +63,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
59
63
$ container ->setParameter ('container.build_time ' , time ());
60
64
61
65
try {
62
- $ container ->compile (( bool ) $ input -> getOption ( ' resolve-env-vars ' ) );
66
+ $ container ->compile ($ resolveEnvVars );
63
67
} catch (InvalidArgumentException $ e ) {
64
68
$ errorIo ->error ($ e ->getMessage ());
65
69
@@ -71,7 +75,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
71
75
return 0 ;
72
76
}
73
77
74
- private function getContainerBuilder (): ContainerBuilder
78
+ private function getContainerBuilder (bool $ resolveEnvVars ): ContainerBuilder
75
79
{
76
80
if (isset ($ this ->container )) {
77
81
return $ this ->container ;
@@ -103,17 +107,23 @@ private function getContainerBuilder(): ContainerBuilder
103
107
throw new RuntimeException (\sprintf ('This command does not support the application container: "%s" is not a "%s". ' , get_debug_type ($ container ), ContainerBuilder::class));
104
108
}
105
109
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
+ }
109
119
110
120
$ container ->getCompilerPassConfig ()->setBeforeOptimizationPasses ([]);
111
- $ container ->getCompilerPassConfig ()->setOptimizationPasses ([new ResolveFactoryClassPass ()]);
112
121
$ container ->getCompilerPassConfig ()->setBeforeRemovingPasses ([]);
113
122
}
114
123
115
124
$ container ->setParameter ('container.build_hash ' , 'lint_container ' );
116
125
$ container ->setParameter ('container.build_id ' , 'lint_container ' );
126
+ $ container ->setParameter ('container.runtime_mode ' , 'web=0 ' );
117
127
118
128
$ container ->addCompilerPass (new CheckAliasValidityPass (), PassConfig::TYPE_BEFORE_REMOVING , -100 );
119
129
$ container ->addCompilerPass (new CheckTypeDeclarationsPass (true ), PassConfig::TYPE_AFTER_REMOVING , -100 );
0 commit comments