Skip to content

Commit 6c4695f

Browse files
Merge branch '4.4' into 5.0
* 4.4: [DependencyInjection][CheckTypeDeclarationsPass] Handle unresolved parameters pointing to environment variables switch the context when validating nested forms remove unused param from validator service config Fix typo [HttpKernel] Fix regression where Store does not return response body correctly rework form validator tests Update AbstractController.php
2 parents 00bf63d + 02df1c9 commit 6c4695f

File tree

10 files changed

+443
-327
lines changed

10 files changed

+443
-327
lines changed

src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ protected function file($file, string $fileName = null, string $disposition = Re
197197
*
198198
* @throws \LogicException
199199
*/
200-
protected function addFlash(string $type, string $message): void
200+
protected function addFlash(string $type, $message): void
201201
{
202202
if (!$this->container->has('session')) {
203203
throw new \LogicException('You can not use the addFlash method if sessions are disabled. Enable them in "config/packages/framework.yaml".');

src/Symfony/Bundle/FrameworkBundle/Resources/config/validator.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd">
66

77
<parameters>
8-
<parameter key="validator.mapping.cache.prefix" />
98
<parameter key="validator.mapping.cache.file">%kernel.cache_dir%/validation.php</parameter>
109
</parameters>
1110

src/Symfony/Component/DependencyInjection/Compiler/CheckTypeDeclarationsPass.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,9 @@ private function checkType(Definition $checkedDefinition, $value, \ReflectionPar
199199
} elseif (\is_string($value)) {
200200
if ('%' === ($value[0] ?? '') && preg_match('/^%([^%]+)%$/', $value, $match)) {
201201
$value = $this->container->getParameter(substr($value, 1, -1));
202-
} elseif ($envPlaceholderUniquePrefix && false !== strpos($value, 'env_')) {
202+
}
203+
204+
if ($envPlaceholderUniquePrefix && \is_string($value) && false !== strpos($value, 'env_')) {
203205
// If the value is an env placeholder that is either mixed with a string or with another env placeholder, then its resolved value will always be a string, so we don't need to resolve it.
204206
// We don't need to change the value because it is already a string.
205207
if ('' === preg_replace('/'.$envPlaceholderUniquePrefix.'_\w+_[a-f0-9]{32}/U', '', $value, -1, $c) && 1 === $c) {

src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckTypeDeclarationsPassTest.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -780,17 +780,27 @@ public function testExpressionLanguageWithSyntheticService()
780780

781781
public function testProcessResolveParameters()
782782
{
783-
$container = new ContainerBuilder();
783+
putenv('ARRAY={"foo":"bar"}');
784+
785+
$container = new ContainerBuilder(new EnvPlaceholderParameterBag([
786+
'env_array_param' => '%env(json:ARRAY)%',
787+
]));
784788
$container->setParameter('array_param', ['foobar']);
785789
$container->setParameter('string_param', 'ccc');
786790

787-
$container
788-
->register('foobar', BarMethodCall::class)
791+
$definition = $container->register('foobar', BarMethodCall::class);
792+
$definition
789793
->addMethodCall('setArray', ['%array_param%'])
790794
->addMethodCall('setString', ['%string_param%']);
791795

796+
(new ResolveParameterPlaceHoldersPass())->process($container);
797+
798+
$definition->addMethodCall('setArray', ['%env_array_param%']);
799+
792800
(new CheckTypeDeclarationsPass(true))->process($container);
793801

794802
$this->addToAssertionCount(1);
803+
804+
putenv('ARRAY=');
795805
}
796806
}

src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ public function validate($form, Constraint $formConstraint)
9090
// in different steps without breaking early enough
9191
$this->resolvedGroups[$field] = (array) $group;
9292
$fieldFormConstraint = new Form();
93+
$this->context->setNode($this->context->getValue(), $field, $this->context->getMetadata(), $this->context->getPropertyPath());
9394
$validator->atPath(sprintf('children[%s]', $field->getName()))->validate($field, $fieldFormConstraint);
9495
}
9596
}
@@ -135,6 +136,7 @@ public function validate($form, Constraint $formConstraint)
135136
if ($field->isSubmitted()) {
136137
$this->resolvedGroups[$field] = $groups;
137138
$fieldFormConstraint = new Form();
139+
$this->context->setNode($this->context->getValue(), $field, $this->context->getMetadata(), $this->context->getPropertyPath());
138140
$validator->atPath(sprintf('children[%s]', $field->getName()))->validate($field, $fieldFormConstraint);
139141
}
140142
}

0 commit comments

Comments
 (0)