Skip to content

Commit f5c6abf

Browse files
[DependencyInjection] Clarify that using expressions in parameters is not allowed
1 parent 46408f0 commit f5c6abf

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/Symfony/Component/DependencyInjection/Loader/Configurator/ParametersConfigurator.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
1313

1414
use Symfony\Component\DependencyInjection\ContainerBuilder;
15+
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
16+
use Symfony\Component\ExpressionLanguage\Expression;
1517

1618
/**
1719
* @author Nicolas Grekas <[email protected]>
@@ -34,6 +36,10 @@ public function __construct(ContainerBuilder $container)
3436
*/
3537
final public function set(string $name, $value): self
3638
{
39+
if ($value instanceof Expression) {
40+
throw new InvalidArgumentException(sprintf('Using an expression in parameter "%s" is not allowed.', $name));
41+
}
42+
3743
$this->container->setParameter($name, static::processValue($value, true));
3844

3945
return $this;

src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,10 @@ private function resolveServices($value, string $file, bool $isParameter = false
822822
$value[$k] = $this->resolveServices($v, $file, $isParameter);
823823
}
824824
} elseif (\is_string($value) && str_starts_with($value, '@=')) {
825+
if ($isParameter) {
826+
throw new InvalidArgumentException(sprintf('Using expressions in parameters is not allowed in "%s".', $file));
827+
}
828+
825829
if (!class_exists(Expression::class)) {
826830
throw new \LogicException('The "@=" expression syntax cannot be used without the ExpressionLanguage component. Try running "composer require symfony/expression-language".');
827831
}

0 commit comments

Comments
 (0)