Skip to content

Commit 07d4edd

Browse files
committed
Merge branch '4.2'
* 4.2: (45 commits) [Form] various minor fixes Ensure the parent process is always killed bugfix: the terminal state was wrong and not reseted [Console] Fix inconsistent result for choice questions in non-interactive mode Define null return type for Constraint::getDefaultOption() [Routing] Fix: annotation loader ignores method's default values [HttpKernel] Fix DebugHandlersListener constructor docblock Skip Glob brace test when GLOB_BRACE is unavailable bumped Symfony version to 4.2.6 updated VERSION for 4.2.5 updated CHANGELOG for 4.2.5 bumped Symfony version to 3.4.25 updated VERSION for 3.4.24 update CONTRIBUTORS for 3.4.24 updated CHANGELOG for 3.4.24 [EventDispatcher] cleanup fix testIgnoredAttributesInContext Re-generate icu 64.1 data Improve PHPdoc / IDE autocomplete for config tree builder [Bridge][Twig] DebugCommand - fix escaping and filter ...
2 parents 5ab03d9 + 0e4df29 commit 07d4edd

File tree

11 files changed

+133
-20
lines changed

11 files changed

+133
-20
lines changed

Constraint.php

Lines changed: 20 additions & 16 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
/**
@@ -229,12 +232,13 @@ public function addImplicitGroupName($group)
229232
*
230233
* Override this method to define a default option.
231234
*
232-
* @return string
235+
* @return string|null
233236
*
234237
* @see __construct()
235238
*/
236239
public function getDefaultOption()
237240
{
241+
return null;
238242
}
239243

240244
/**
@@ -256,7 +260,7 @@ public function getRequiredOptions()
256260
*
257261
* By default, this is the fully qualified name of the constraint class
258262
* suffixed with "Validator". You can override this method to change that
259-
* behaviour.
263+
* behavior.
260264
*
261265
* @return string
262266
*/

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
@@ -49,6 +49,9 @@ public function __construct($options = null)
4949
'min' => $options,
5050
'max' => $options,
5151
];
52+
} elseif (\is_array($options) && isset($options['value']) && !isset($options['min']) && !isset($options['max'])) {
53+
$options['min'] = $options['max'] = $options['value'];
54+
unset($options['value']);
5255
}
5356

5457
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,10 @@
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>
333337
<trans-unit id="87">
334338
<source>This value should be positive.</source>
335339
<target>Dieser Wert sollte positiv sein.</target>
@@ -346,6 +350,10 @@
346350
<source>This value should be either negative or zero.</source>
347351
<target>Dieser Wert sollte entweder negativ oder 0 sein.</target>
348352
</trans-unit>
353+
<trans-unit id="91">
354+
<source>This collection should contain only unique elements.</source>
355+
<target>Diese Sammlung darf keine doppelten Elemente enthalten.</target>
356+
</trans-unit>
349357
</body>
350358
</file>
351359
</xliff>

Resources/translations/validators.en.xlf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,10 @@
350350
<source>This value should be either negative or zero.</source>
351351
<target>This value should be either negative or zero.</target>
352352
</trans-unit>
353+
<trans-unit id="91">
354+
<source>This collection should contain only unique elements.</source>
355+
<target>This collection should contain only unique elements.</target>
356+
</trans-unit>
353357
</body>
354358
</file>
355359
</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,62 @@
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>
281337
<trans-unit id="87">
282338
<source>This value should be positive.</source>
283339
<target>Giá trị này có thể thực hiện được.</target>
@@ -294,6 +350,10 @@
294350
<source>This value should be either negative or zero.</source>
295351
<target>Giá trị này nên bị từ chối hoặc bằng không.</target>
296352
</trans-unit>
353+
<trans-unit id="91">
354+
<source>This collection should contain only unique elements.</source>
355+
<target>Danh sách này chỉ nên chứa các phần tử khác nhau.</target>
356+
</trans-unit>
297357
</body>
298358
</file>
299359
</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)