Skip to content

Commit 17f31bc

Browse files
Merge branch '4.4' into 5.4
* 4.4: [Serializer] Fix passing null to str_contains() [DependencyInjection] Don't reset env placeholders during compilation [HttpClient] Fix overriding default options with null [DependencyInjection] Clarify that using expressions in parameters is not allowed [GHA] Cancel running CI jobs when a PR is updated [Validator] Improve tests for the Image and File constraints [Validator][Tests] Fix AssertingContextualValidator not throwing on remaining expectations
2 parents 8289596 + f6d1ca0 commit 17f31bc

File tree

4 files changed

+39
-41
lines changed

4 files changed

+39
-41
lines changed

Compiler/MergeExtensionConfigurationPass.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,6 @@ public function process(ContainerBuilder $container)
7979
$container->getParameterBag()->mergeEnvPlaceholders($resolvingBag);
8080
}
8181

82-
if ($configAvailable) {
83-
BaseNode::resetPlaceholders();
84-
}
85-
8682
throw $e;
8783
}
8884

@@ -95,10 +91,6 @@ public function process(ContainerBuilder $container)
9591
$container->getParameterBag()->add($parameters);
9692
}
9793

98-
if ($configAvailable) {
99-
BaseNode::resetPlaceholders();
100-
}
101-
10294
$container->addDefinitions($definitions);
10395
$container->addAliases($aliases);
10496
}

Compiler/ValidateEnvPlaceholdersPass.php

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -48,46 +48,42 @@ public function process(ContainerBuilder $container)
4848

4949
$defaultBag = new ParameterBag($resolvingBag->all());
5050
$envTypes = $resolvingBag->getProvidedTypes();
51-
try {
52-
foreach ($resolvingBag->getEnvPlaceholders() + $resolvingBag->getUnusedEnvPlaceholders() as $env => $placeholders) {
53-
$values = [];
54-
if (false === $i = strpos($env, ':')) {
55-
$default = $defaultBag->has("env($env)") ? $defaultBag->get("env($env)") : self::TYPE_FIXTURES['string'];
56-
$defaultType = null !== $default ? get_debug_type($default) : 'string';
57-
$values[$defaultType] = $default;
58-
} else {
59-
$prefix = substr($env, 0, $i);
60-
foreach ($envTypes[$prefix] ?? ['string'] as $type) {
61-
$values[$type] = self::TYPE_FIXTURES[$type] ?? null;
62-
}
63-
}
64-
foreach ($placeholders as $placeholder) {
65-
BaseNode::setPlaceholder($placeholder, $values);
51+
foreach ($resolvingBag->getEnvPlaceholders() + $resolvingBag->getUnusedEnvPlaceholders() as $env => $placeholders) {
52+
$values = [];
53+
if (false === $i = strpos($env, ':')) {
54+
$default = $defaultBag->has("env($env)") ? $defaultBag->get("env($env)") : self::TYPE_FIXTURES['string'];
55+
$defaultType = null !== $default ? get_debug_type($default) : 'string';
56+
$values[$defaultType] = $default;
57+
} else {
58+
$prefix = substr($env, 0, $i);
59+
foreach ($envTypes[$prefix] ?? ['string'] as $type) {
60+
$values[$type] = self::TYPE_FIXTURES[$type] ?? null;
6661
}
6762
}
63+
foreach ($placeholders as $placeholder) {
64+
BaseNode::setPlaceholder($placeholder, $values);
65+
}
66+
}
6867

69-
$processor = new Processor();
70-
71-
foreach ($extensions as $name => $extension) {
72-
if (!($extension instanceof ConfigurationExtensionInterface || $extension instanceof ConfigurationInterface)
73-
|| !$config = array_filter($container->getExtensionConfig($name))
74-
) {
75-
// this extension has no semantic configuration or was not called
76-
continue;
77-
}
68+
$processor = new Processor();
7869

79-
$config = $resolvingBag->resolveValue($config);
70+
foreach ($extensions as $name => $extension) {
71+
if (!($extension instanceof ConfigurationExtensionInterface || $extension instanceof ConfigurationInterface)
72+
|| !$config = array_filter($container->getExtensionConfig($name))
73+
) {
74+
// this extension has no semantic configuration or was not called
75+
continue;
76+
}
8077

81-
if ($extension instanceof ConfigurationInterface) {
82-
$configuration = $extension;
83-
} elseif (null === $configuration = $extension->getConfiguration($config, $container)) {
84-
continue;
85-
}
78+
$config = $resolvingBag->resolveValue($config);
8679

87-
$this->extensionConfig[$name] = $processor->processConfiguration($configuration, $config);
80+
if ($extension instanceof ConfigurationInterface) {
81+
$configuration = $extension;
82+
} elseif (null === $configuration = $extension->getConfiguration($config, $container)) {
83+
continue;
8884
}
89-
} finally {
90-
BaseNode::resetPlaceholders();
85+
86+
$this->extensionConfig[$name] = $processor->processConfiguration($configuration, $config);
9187
}
9288

9389
$resolvingBag->clearUnusedEnvPlaceholders();

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 <p@tchwork.com>
@@ -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;

Loader/YamlFileLoader.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,10 @@ private function resolveServices($value, string $file, bool $isParameter = false
900900
$value[$k] = $this->resolveServices($v, $file, $isParameter);
901901
}
902902
} elseif (\is_string($value) && str_starts_with($value, '@=')) {
903+
if ($isParameter) {
904+
throw new InvalidArgumentException(sprintf('Using expressions in parameters is not allowed in "%s".', $file));
905+
}
906+
903907
if (!class_exists(Expression::class)) {
904908
throw new \LogicException('The "@=" expression syntax cannot be used without the ExpressionLanguage component. Try running "composer require symfony/expression-language".');
905909
}

0 commit comments

Comments
 (0)