Skip to content

Commit db5457e

Browse files
committed
Merge branch '3.4' into 4.2
* 3.4: [Serializer] Added check of constuctor modifiers to AbstractNormalizer [Intl] Simplify the compile binary [Routing] Fix routes annotation loading with glob pattern Fix hardcoded hotPathTagName [Validator] Improve constraint default option check [Validator] Fix annotation default for @count and @Length Update composer.json Fix getSetMethodNormalizer to correctly ignore the attributes specified in "ignored_attributes" Add missing "vi" translations add missing German translations [Intl] Fix test added missing translation use behavior instead of behaviour [Validator] Translate JSON message to Hungarian [Validator] fix sr_Latn translations [FrameworkBundle][HttpFoundation] make session service resettable
2 parents a25123c + 8f16fba commit db5457e

File tree

11 files changed

+131
-19
lines changed

11 files changed

+131
-19
lines changed

Constraint.php

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,20 @@ public static function getErrorName($errorCode)
105105
*/
106106
public function __construct($options = null)
107107
{
108+
$defaultOption = $this->getDefaultOption();
108109
$invalidOptions = [];
109110
$missingOptions = array_flip((array) $this->getRequiredOptions());
110111
$knownOptions = get_object_vars($this);
111112

112113
// The "groups" option is added to the object lazily
113114
$knownOptions['groups'] = true;
114115

115-
if (\is_array($options) && \count($options) >= 1 && isset($options['value']) && !property_exists($this, 'value')) {
116-
$options[$this->getDefaultOption()] = $options['value'];
116+
if (\is_array($options) && isset($options['value']) && !property_exists($this, 'value')) {
117+
if (null === $defaultOption) {
118+
throw new ConstraintDefinitionException(sprintf('No default option is configured for constraint "%s".', \get_class($this)));
119+
}
120+
121+
$options[$defaultOption] = $options['value'];
117122
unset($options['value']);
118123
}
119124

@@ -130,26 +135,24 @@ public function __construct($options = null)
130135
}
131136
}
132137
} elseif (null !== $options && !(\is_array($options) && 0 === \count($options))) {
133-
$option = $this->getDefaultOption();
134-
135-
if (null === $option) {
136-
throw new ConstraintDefinitionException(sprintf('No default option is configured for constraint %s', \get_class($this)));
138+
if (null === $defaultOption) {
139+
throw new ConstraintDefinitionException(sprintf('No default option is configured for constraint "%s".', \get_class($this)));
137140
}
138141

139-
if (\array_key_exists($option, $knownOptions)) {
140-
$this->$option = $options;
141-
unset($missingOptions[$option]);
142+
if (\array_key_exists($defaultOption, $knownOptions)) {
143+
$this->$defaultOption = $options;
144+
unset($missingOptions[$defaultOption]);
142145
} else {
143-
$invalidOptions[] = $option;
146+
$invalidOptions[] = $defaultOption;
144147
}
145148
}
146149

147150
if (\count($invalidOptions) > 0) {
148-
throw new InvalidOptionsException(sprintf('The options "%s" do not exist in constraint %s', implode('", "', $invalidOptions), \get_class($this)), $invalidOptions);
151+
throw new InvalidOptionsException(sprintf('The options "%s" do not exist in constraint "%s".', implode('", "', $invalidOptions), \get_class($this)), $invalidOptions);
149152
}
150153

151154
if (\count($missingOptions) > 0) {
152-
throw new MissingOptionsException(sprintf('The options "%s" must be set for constraint %s', implode('", "', array_keys($missingOptions)), \get_class($this)), array_keys($missingOptions));
155+
throw new MissingOptionsException(sprintf('The options "%s" must be set for constraint "%s".', implode('", "', array_keys($missingOptions)), \get_class($this)), array_keys($missingOptions));
153156
}
154157
}
155158

@@ -173,7 +176,7 @@ public function __set($option, $value)
173176
return;
174177
}
175178

176-
throw new InvalidOptionsException(sprintf('The option "%s" does not exist in constraint %s', $option, \get_class($this)), [$option]);
179+
throw new InvalidOptionsException(sprintf('The option "%s" does not exist in constraint "%s".', $option, \get_class($this)), [$option]);
177180
}
178181

179182
/**
@@ -199,7 +202,7 @@ public function __get($option)
199202
return $this->groups;
200203
}
201204

202-
throw new InvalidOptionsException(sprintf('The option "%s" does not exist in constraint %s', $option, \get_class($this)), [$option]);
205+
throw new InvalidOptionsException(sprintf('The option "%s" does not exist in constraint "%s".', $option, \get_class($this)), [$option]);
203206
}
204207

205208
/**
@@ -256,7 +259,7 @@ public function getRequiredOptions()
256259
*
257260
* By default, this is the fully qualified name of the constraint class
258261
* suffixed with "Validator". You can override this method to change that
259-
* behaviour.
262+
* behavior.
260263
*
261264
* @return string
262265
*/

Constraints/Count.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ public function __construct($options = null)
4343
'min' => $options,
4444
'max' => $options,
4545
];
46+
} elseif (\is_array($options) && isset($options['value']) && !isset($options['min']) && !isset($options['max'])) {
47+
$options['min'] = $options['max'] = $options['value'];
48+
unset($options['value']);
4649
}
4750

4851
parent::__construct($options);

Constraints/Length.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ public function __construct($options = null)
4747
'min' => $options,
4848
'max' => $options,
4949
];
50+
} elseif (\is_array($options) && isset($options['value']) && !isset($options['min']) && !isset($options['max'])) {
51+
$options['min'] = $options['max'] = $options['value'];
52+
unset($options['value']);
5053
}
5154

5255
parent::__construct($options);

Resources/translations/validators.de.xlf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,14 @@
330330
<source>This Business Identifier Code (BIC) is not associated with IBAN {{ iban }}.</source>
331331
<target>Diese internationale Bankleitzahl (BIC) ist nicht mit der IBAN {{ iban }} assoziiert.</target>
332332
</trans-unit>
333+
<trans-unit id="86">
334+
<source>This value should be valid JSON.</source>
335+
<target>Dieser Wert sollte gültiges JSON sein.</target>
336+
</trans-unit>
337+
<trans-unit id="87">
338+
<source>This collection should contain only unique elements.</source>
339+
<target>Diese Sammlung darf keine doppelten Elemente enthalten.</target>
340+
</trans-unit>
333341
</body>
334342
</file>
335343
</xliff>

Resources/translations/validators.en.xlf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,10 @@
334334
<source>This value should be valid JSON.</source>
335335
<target>This value should be valid JSON.</target>
336336
</trans-unit>
337+
<trans-unit id="87">
338+
<source>This collection should contain only unique elements.</source>
339+
<target>This collection should contain only unique elements.</target>
340+
</trans-unit>
337341
</body>
338342
</file>
339343
</xliff>

Resources/translations/validators.hu.xlf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,10 @@
330330
<source>This Business Identifier Code (BIC) is not associated with IBAN {{ iban }}.</source>
331331
<target>Ez a Bankazonosító kód (BIC) nem kapcsolódik az IBAN kódhoz ({{ iban }}).</target>
332332
</trans-unit>
333+
<trans-unit id="86">
334+
<source>This value should be valid JSON.</source>
335+
<target>Ez az érték érvényes JSON kell, hogy legyen.</target>
336+
</trans-unit>
333337
</body>
334338
</file>
335339
</xliff>

Resources/translations/validators.sr_Latn.xlf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@
220220
</trans-unit>
221221
<trans-unit id="58">
222222
<source>Unsupported card type or invalid card number.</source>
223-
<target>Tip kartije nije podržan ili broj kartice nije validan.</target>
223+
<target>Tip kartice nije podržan ili broj kartice nije validan.</target>
224224
</trans-unit>
225225
<trans-unit id="59">
226226
<source>This is not a valid International Bank Account Number (IBAN).</source>
@@ -324,7 +324,7 @@
324324
</trans-unit>
325325
<trans-unit id="84">
326326
<source>This value should be a multiple of {{ compared_value }}.</source>
327-
<target>Ova vrednost bi trebalo da bude višestruko veća od {{ compared_value }}.</target>
327+
<target>Ova vrednost bi trebalo da bude deljiva sa {{ compared_value }}.</target>
328328
</trans-unit>
329329
<trans-unit id="85">
330330
<source>This Business Identifier Code (BIC) is not associated with IBAN {{ iban }}.</source>

Resources/translations/validators.vi.xlf

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,66 @@
278278
<source>This value should not be identical to {{ compared_value_type }} {{ compared_value }}.</source>
279279
<target>Giá trị không được phép giống như {{ compared_value_type }} {{ compared_value }}.</target>
280280
</trans-unit>
281+
<trans-unit id="73">
282+
<source>The image ratio is too big ({{ ratio }}). Allowed maximum ratio is {{ max_ratio }}.</source>
283+
<target>Tỷ lệ bức ảnh quá lớn ({{ ratio }}). Tỷ lệ tối đa cho phép là {{ max_ratio }}.</target>
284+
</trans-unit>
285+
<trans-unit id="74">
286+
<source>The image ratio is too small ({{ ratio }}). Minimum ratio expected is {{ min_ratio }}.</source>
287+
<target>Tỷ lệ bức ảnh quá nhỏ ({{ ratio }}). Tỷ lệ tối thiểu mong muốn là {{ min_ratio }}.</target>
288+
</trans-unit>
289+
<trans-unit id="75">
290+
<source>The image is square ({{ width }}x{{ height }}px). Square images are not allowed.</source>
291+
<target>Bức ảnh là hình vuông ({{ width }}x{{ height }}px). Ảnh hình vuông không được phép.</target>
292+
</trans-unit>
293+
<trans-unit id="76">
294+
<source>The image is landscape oriented ({{ width }}x{{ height }}px). Landscape oriented images are not allowed.</source>
295+
<target>Bức ảnh theo chiều ngang ({{ width }}x{{ height }}px). Ảnh chiều ngang không được phép.</target>
296+
</trans-unit>
297+
<trans-unit id="77">
298+
<source>The image is portrait oriented ({{ width }}x{{ height }}px). Portrait oriented images are not allowed.</source>
299+
<target>Bức ảnh theo chiều dọc ({{ width }}x{{ height }}px). Ảnh chiều dọc không được phép.</target>
300+
</trans-unit>
301+
<trans-unit id="78">
302+
<source>An empty file is not allowed.</source>
303+
<target>Một file rỗng không được phép.</target>
304+
</trans-unit>
305+
<trans-unit id="79">
306+
<source>The host could not be resolved.</source>
307+
<target>Máy chủ không thể được tìm thấy.</target>
308+
</trans-unit>
309+
<trans-unit id="80">
310+
<source>This value does not match the expected {{ charset }} charset.</source>
311+
<target>Giá trị này không đúng định dạng bộ ký tự mong muốn {{ charset }}.</target>
312+
</trans-unit>
313+
<trans-unit id="81">
314+
<source>This is not a valid Business Identifier Code (BIC).</source>
315+
<target>Giá trị này không đúng định dạng mã định danh doanh nghiệp (BIC).</target>
316+
</trans-unit>
317+
<trans-unit id="82">
318+
<source>Error</source>
319+
<target>Lỗi</target>
320+
</trans-unit>
321+
<trans-unit id="83">
322+
<source>This is not a valid UUID.</source>
323+
<target>Giá trị này không đúng định dạng UUID.</target>
324+
</trans-unit>
325+
<trans-unit id="84">
326+
<source>This value should be a multiple of {{ compared_value }}.</source>
327+
<target>Giá trị này nên là bội số của {{ compared_value }}.</target>
328+
</trans-unit>
329+
<trans-unit id="85">
330+
<source>This Business Identifier Code (BIC) is not associated with IBAN {{ iban }}.</source>
331+
<target>Mã định danh doanh nghiệp (BIC) này không liên kết với IBAN {{ iban }}.</target>
332+
</trans-unit>
333+
<trans-unit id="86">
334+
<source>This value should be valid JSON.</source>
335+
<target>Giá trị này nên đúng định dạng JSON.</target>
336+
</trans-unit>
337+
<trans-unit id="87">
338+
<source>This collection should contain only unique elements.</source>
339+
<target>Danh sách này chỉ nên chứa các phần tử khác nhau.</target>
340+
</trans-unit>
281341
</body>
282342
</file>
283343
</xliff>

Tests/ConstraintTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public function testOptionsAsDefaultOption()
225225

226226
/**
227227
* @expectedException \Symfony\Component\Validator\Exception\InvalidOptionsException
228-
* @expectedExceptionMessage The options "0", "5" do not exist
228+
* @expectedExceptionMessage The options "0", "5" do not exist in constraint "Symfony\Component\Validator\Tests\Fixtures\ConstraintA".
229229
*/
230230
public function testInvalidOptions()
231231
{
@@ -242,4 +242,13 @@ public function testOptionsWithInvalidInternalPointer()
242242

243243
$this->assertEquals('foo', $constraint->property1);
244244
}
245+
246+
/**
247+
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
248+
* @expectedExceptionMessage No default option is configured for constraint "Symfony\Component\Validator\Tests\Fixtures\ConstraintB".
249+
*/
250+
public function testAnnotationSetUndefinedDefaultOption()
251+
{
252+
new ConstraintB(['value' => 1]);
253+
}
245254
}

Tests/Constraints/CountValidatorTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,13 @@ public function testDefaultOption()
195195
$this->assertEquals(5, $constraint->min);
196196
$this->assertEquals(5, $constraint->max);
197197
}
198+
199+
public function testConstraintAnnotationDefaultOption()
200+
{
201+
$constraint = new Count(['value' => 5, 'exactMessage' => 'message']);
202+
203+
$this->assertEquals(5, $constraint->min);
204+
$this->assertEquals(5, $constraint->max);
205+
$this->assertEquals('message', $constraint->exactMessage);
206+
}
198207
}

0 commit comments

Comments
 (0)