Skip to content

Commit 6270bff

Browse files
Merge branch '3.4' into 4.2
* 3.4: fix translating file validation error message [Validator] Add missing Hungarian translations [3.4] [Validator] Add missing french validation translations. [Validator] Only traverse arrays that are cascaded into Handle case where no translations were found [Validator] Translate unique collection message to Hungarian fix tests Run test in separate process Use a class name that does not actually exist fix horizontal spacing of inlined Bootstrap forms [Translator] Warm up the translations cache in dev turn failed file uploads into form errors
2 parents 0e4df29 + 125e72d commit 6270bff

File tree

5 files changed

+83
-12
lines changed

5 files changed

+83
-12
lines changed

Constraints/Collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ protected function initializeNestedConstraints()
6868
}
6969

7070
if (!$field instanceof Optional && !$field instanceof Required) {
71-
$this->fields[$fieldName] = $field = new Required($field);
71+
$this->fields[$fieldName] = new Required($field);
7272
}
7373
}
7474
}

Resources/translations/validators.fr.xlf

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,34 @@
334334
<source>This value should be valid JSON.</source>
335335
<target>Cette valeur doit être un JSON valide.</target>
336336
</trans-unit>
337+
<trans-unit id="87">
338+
<source>This collection should contain only unique elements.</source>
339+
<target>Cette collection ne doit pas comporter de doublons.</target>
340+
</trans-unit>
341+
<trans-unit id="88">
342+
<source>This value should be positive.</source>
343+
<target>Cette valeur doit être strictement positive.</target>
344+
</trans-unit>
345+
<trans-unit id="89">
346+
<source>This value should be either positive or zero.</source>
347+
<target>Cette valeur doit être supérieure ou égale à zéro.</target>
348+
</trans-unit>
349+
<trans-unit id="90">
350+
<source>This value should be negative.</source>
351+
<target>Cette valeur doit être strictement négative.</target>
352+
</trans-unit>
353+
<trans-unit id="91">
354+
<source>This value should be either negative or zero.</source>
355+
<target>Cette valeur doit être inférieure ou égale à zéro.</target>
356+
</trans-unit>
357+
<trans-unit id="92">
358+
<source>This value is not a valid timezone.</source>
359+
<target>Cette valeur n'est pas un fuseau horaire valide.</target>
360+
</trans-unit>
361+
<trans-unit id="93">
362+
<source>This password has been leaked in a data breach, it must not be used. Please use another password.</source>
363+
<target>Ce mot de passe a été révélé par une faille de sécurité et ne doit plus être utilisé. Veuillez utiliser un autre mot de passe.</target>
364+
</trans-unit>
337365
</body>
338366
</file>
339367
</xliff>

Resources/translations/validators.hu.xlf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,30 @@
334334
<source>This value should be valid JSON.</source>
335335
<target>Ez az érték érvényes JSON kell, hogy legyen.</target>
336336
</trans-unit>
337+
<trans-unit id="87">
338+
<source>This value should be positive.</source>
339+
<target>Ennek az értéknek pozitívnak kell lennie.</target>
340+
</trans-unit>
341+
<trans-unit id="88">
342+
<source>This value should be either positive or zero.</source>
343+
<target>Ennek az értéknek pozitívnak vagy nullának kell lennie.</target>
344+
</trans-unit>
345+
<trans-unit id="89">
346+
<source>This value should be negative.</source>
347+
<target>Ennek az értéknek negatívnak kell lennie.</target>
348+
</trans-unit>
349+
<trans-unit id="90">
350+
<source>This value should be either negative or zero.</source>
351+
<target>Ennek az értéknek negatívnak vagy nullának kell lennie.</target>
352+
</trans-unit>
353+
<trans-unit id="91">
354+
<source>This collection should contain only unique elements.</source>
355+
<target>Ez a gyűjtemény csak egyedi elemeket tartalmazhat.</target>
356+
</trans-unit>
357+
<trans-unit id="92">
358+
<source>This value is not a valid timezone.</source>
359+
<target>Ez az érték nem egy érvényes időzóna.</target>
360+
</trans-unit>
337361
</body>
338362
</file>
339363
</xliff>

Tests/Validator/AbstractValidatorTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,30 @@ public function testRecursiveArrayReference()
589589
$this->assertNull($violations[0]->getCode());
590590
}
591591

592+
public function testOnlyCascadedArraysAreTraversed()
593+
{
594+
$entity = new Entity();
595+
$entity->reference = ['key' => new Reference()];
596+
597+
$callback = function ($value, ExecutionContextInterface $context) {
598+
$context->addViolation('Message %param%', ['%param%' => 'value']);
599+
};
600+
601+
$this->metadata->addPropertyConstraint('reference', new Callback([
602+
'callback' => function () {},
603+
'groups' => 'Group',
604+
]));
605+
$this->referenceMetadata->addConstraint(new Callback([
606+
'callback' => $callback,
607+
'groups' => 'Group',
608+
]));
609+
610+
$violations = $this->validate($entity, null, 'Group');
611+
612+
/* @var ConstraintViolationInterface[] $violations */
613+
$this->assertCount(0, $violations);
614+
}
615+
592616
public function testArrayTraversalCannotBeDisabled()
593617
{
594618
$entity = new Entity();

Validator/RecursiveContextualValidator.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -353,24 +353,18 @@ private function validateObject($object, $propertyPath, array $groups, $traversa
353353
* Validates each object in a collection against the constraints defined
354354
* for their classes.
355355
*
356-
* If the parameter $recursive is set to true, nested {@link \Traversable}
357-
* objects are iterated as well. Nested arrays are always iterated,
358-
* regardless of the value of $recursive.
356+
* Nested arrays are also iterated.
359357
*
360358
* @param iterable $collection The collection
361359
* @param string $propertyPath The current property path
362360
* @param (string|GroupSequence)[] $groups The validated groups
363361
* @param ExecutionContextInterface $context The current execution context
364-
*
365-
* @see ClassNode
366-
* @see CollectionNode
367362
*/
368363
private function validateEachObjectIn($collection, $propertyPath, array $groups, ExecutionContextInterface $context)
369364
{
370365
foreach ($collection as $key => $value) {
371366
if (\is_array($value)) {
372-
// Arrays are always cascaded, independent of the specified
373-
// traversal strategy
367+
// Also traverse nested arrays
374368
$this->validateEachObjectIn(
375369
$value,
376370
$propertyPath.'['.$key.']',
@@ -600,7 +594,8 @@ private function validateClassNode($object, $cacheKey, ClassMetadataInterface $m
600594
* in the passed metadata object. Then, if the value is an instance of
601595
* {@link \Traversable} and the selected traversal strategy permits it,
602596
* the value is traversed and each nested object validated against its own
603-
* constraints. Arrays are always traversed.
597+
* constraints. If the value is an array, it is traversed regardless of
598+
* the given strategy.
604599
*
605600
* @param mixed $value The validated value
606601
* @param object|null $object The current object
@@ -659,8 +654,8 @@ private function validateGenericNode($value, $object, $cacheKey, MetadataInterfa
659654

660655
$cascadingStrategy = $metadata->getCascadingStrategy();
661656

662-
// Quit unless we have an array or a cascaded object
663-
if (!\is_array($value) && !($cascadingStrategy & CascadingStrategy::CASCADE)) {
657+
// Quit unless we cascade
658+
if (!($cascadingStrategy & CascadingStrategy::CASCADE)) {
664659
return;
665660
}
666661

0 commit comments

Comments
 (0)