17
17
use Symfony \Component \DependencyInjection \Exception \InvalidArgumentException ;
18
18
use Symfony \Component \DependencyInjection \Exception \InvalidParameterTypeException ;
19
19
use Symfony \Component \DependencyInjection \Exception \RuntimeException ;
20
+ use Symfony \Component \DependencyInjection \ExpressionLanguage ;
20
21
use Symfony \Component \DependencyInjection \Parameter ;
21
22
use Symfony \Component \DependencyInjection \Reference ;
22
23
use Symfony \Component \DependencyInjection \ServiceLocator ;
24
+ use Symfony \Component \ExpressionLanguage \Expression ;
23
25
24
26
/**
25
27
* Checks whether injected parameters are compatible with type declarations.
@@ -39,6 +41,8 @@ final class CheckTypeDeclarationsPass extends AbstractRecursivePass
39
41
40
42
private $ autoload ;
41
43
44
+ private $ expressionLanguage ;
45
+
42
46
/**
43
47
* @param bool $autoload Whether services who's class in not loaded should be checked or not.
44
48
* Defaults to false to save loading code during compilation.
@@ -172,6 +176,8 @@ private function checkType(Definition $checkedDefinition, $value, \ReflectionPar
172
176
173
177
if ($ value instanceof Parameter) {
174
178
$ value = $ this ->container ->getParameter ($ value );
179
+ } elseif ($ value instanceof Expression) {
180
+ $ value = $ this ->getExpressionLanguage ()->evaluate ($ value , ['container ' => $ this ->container ]);
175
181
} elseif (\is_string ($ value ) && '% ' === ($ value [0 ] ?? '' ) && preg_match ('/^%([^%]+)%$/ ' , $ value , $ match )) {
176
182
$ value = $ this ->container ->getParameter ($ match [1 ]);
177
183
}
@@ -202,4 +208,13 @@ private function checkType(Definition $checkedDefinition, $value, \ReflectionPar
202
208
throw new InvalidParameterTypeException ($ this ->currentId , \is_object ($ value ) ? \get_class ($ value ) : \gettype ($ value ), $ parameter );
203
209
}
204
210
}
211
+
212
+ private function getExpressionLanguage (): ExpressionLanguage
213
+ {
214
+ if (null === $ this ->expressionLanguage ) {
215
+ $ this ->expressionLanguage = new ExpressionLanguage (null , $ this ->container ->getExpressionLanguageProviders ());
216
+ }
217
+
218
+ return $ this ->expressionLanguage ;
219
+ }
205
220
}
0 commit comments