Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3b1e833

Browse filesBrowse files
committed
[Validator] removed the convention that error parameters are delimited with %%
1 parent 7ead257 commit 3b1e833
Copy full SHA for 3b1e833
Expand file treeCollapse file tree

33 files changed

+70
-77
lines changed

‎src/Symfony/Component/Validator/ConstraintViolation.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/ConstraintViolation.php
+1-8Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,7 @@ public function getMessageParameters()
3131

3232
public function getMessage()
3333
{
34-
$sources = array();
35-
$targets = array();
36-
foreach ($this->messageParameters as $key => $value) {
37-
$sources[] = '{{ '.$key.' }}';
38-
$targets[] = (string) $value;
39-
}
40-
41-
return str_replace($sources, $targets, $this->messageTemplate);
34+
return str_replace(array_keys($sources), array_values($targets), $this->messageTemplate);
4235
}
4336

4437
public function getRoot()

‎src/Symfony/Component/Validator/Constraints/AssertTypeValidator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/AssertTypeValidator.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ public function isValid($value, Constraint $constraint)
2323
}
2424

2525
$this->setMessage($constraint->message, array(
26-
'value' => $value,
27-
'type' => $constraint->type,
26+
'{{ value }}' => $value,
27+
'{{ type }}' => $constraint->type,
2828
));
2929

3030
return false;

‎src/Symfony/Component/Validator/Constraints/BlankValidator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/BlankValidator.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class BlankValidator extends ConstraintValidator
1010
public function isValid($value, Constraint $constraint)
1111
{
1212
if ($value !== '' && $value !== null) {
13-
$this->setMessage($constraint->message, array('value' => $value));
13+
$this->setMessage($constraint->message, array('{{ value }}' => $value));
1414

1515
return false;
1616
}

‎src/Symfony/Component/Validator/Constraints/ChoiceValidator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/ChoiceValidator.php
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function isValid($value, Constraint $constraint)
5353
if ($constraint->multiple) {
5454
foreach ($value as $_value) {
5555
if (!in_array($_value, $choices, true)) {
56-
$this->setMessage($constraint->message, array('value' => $_value));
56+
$this->setMessage($constraint->message, array('{{ value }}' => $_value));
5757

5858
return false;
5959
}
@@ -62,18 +62,18 @@ public function isValid($value, Constraint $constraint)
6262
$count = count($value);
6363

6464
if ($constraint->min !== null && $count < $constraint->min) {
65-
$this->setMessage($constraint->minMessage, array('limit' => $constraint->min));
65+
$this->setMessage($constraint->minMessage, array('{{ limit }}' => $constraint->min));
6666

6767
return false;
6868
}
6969

7070
if ($constraint->max !== null && $count > $constraint->max) {
71-
$this->setMessage($constraint->maxMessage, array('limit' => $constraint->max));
71+
$this->setMessage($constraint->maxMessage, array('{{ limit }}' => $constraint->max));
7272

7373
return false;
7474
}
7575
} elseif (!in_array($value, $choices, true)) {
76-
$this->setMessage($constraint->message, array('value' => $value));
76+
$this->setMessage($constraint->message, array('{{ value }}' => $value));
7777

7878
return false;
7979
}

‎src/Symfony/Component/Validator/Constraints/CollectionValidator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/CollectionValidator.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ public function isValid($value, Constraint $constraint)
4848

4949
if (count($extraFields) > 0 && !$constraint->allowExtraFields) {
5050
$this->setMessage($constraint->extraFieldsMessage, array(
51-
'fields' => '"'.implode('", "', array_keys($extraFields)).'"'
51+
'{{ fields }}' => '"'.implode('", "', array_keys($extraFields)).'"'
5252
));
5353

5454
return false;
5555
}
5656

5757
if (count($missingFields) > 0 && !$constraint->allowMissingFields) {
5858
$this->setMessage($constraint->missingFieldsMessage, array(
59-
'fields' => '"'.implode('", "', $missingFields).'"'
59+
'{{ fields }}' => '"'.implode('", "', $missingFields).'"'
6060
));
6161

6262
return false;

‎src/Symfony/Component/Validator/Constraints/DateTimeValidator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/DateTimeValidator.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function isValid($value, Constraint $constraint)
2727
$value = (string)$value;
2828

2929
if (!preg_match(self::PATTERN, $value, $matches)) {
30-
$this->setMessage($constraint->message, array('value' => $value));
30+
$this->setMessage($constraint->message, array('{{ value }}' => $value));
3131

3232
return false;
3333
}

‎src/Symfony/Component/Validator/Constraints/DateValidator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/DateValidator.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function isValid($value, Constraint $constraint)
2323
$value = (string)$value;
2424

2525
if (!preg_match(self::PATTERN, $value, $matches)) {
26-
$this->setMessage($constraint->message, array('value' => $value));
26+
$this->setMessage($constraint->message, array('{{ value }}' => $value));
2727

2828
return false;
2929
}

‎src/Symfony/Component/Validator/Constraints/EmailValidator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/EmailValidator.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function isValid($value, Constraint $constraint)
2323
$value = (string)$value;
2424

2525
if (!preg_match(self::PATTERN, $value)) {
26-
$this->setMessage($constraint->message, array('value' => $value));
26+
$this->setMessage($constraint->message, array('{{ value }}' => $value));
2727

2828
return false;
2929
}
@@ -32,7 +32,7 @@ public function isValid($value, Constraint $constraint)
3232
$host = substr($value, strpos($value, '@') + 1);
3333

3434
if (!$this->checkMX($host)) {
35-
$this->setMessage($constraint->message, array('value' => $value));
35+
$this->setMessage($constraint->message, array('{{ value }}' => $value));
3636

3737
return false;
3838
}

‎src/Symfony/Component/Validator/Constraints/FileValidator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/FileValidator.php
+8-8Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ public function isValid($value, Constraint $constraint)
2727
$path = $value instanceof FileObject ? $value->getPath() : (string)$value;
2828

2929
if (!file_exists($path)) {
30-
$this->setMessage($constraint->notFoundMessage, array('file' => $path));
30+
$this->setMessage($constraint->notFoundMessage, array('{{ file }}' => $path));
3131

3232
return false;
3333
}
3434

3535
if (!is_readable($path)) {
36-
$this->setMessage($constraint->notReadableMessage, array('file' => $path));
36+
$this->setMessage($constraint->notReadableMessage, array('{{ file }}' => $path));
3737

3838
return false;
3939
}
@@ -57,9 +57,9 @@ public function isValid($value, Constraint $constraint)
5757

5858
if ($size > $limit) {
5959
$this->setMessage($constraint->maxSizeMessage, array(
60-
'size' => $size . $suffix,
61-
'limit' => $limit . $suffix,
62-
'file' => $path,
60+
'{{ size }}' => $size . $suffix,
61+
'{{ limit }}' => $limit . $suffix,
62+
'{{ file }}' => $path,
6363
));
6464

6565
return false;
@@ -73,9 +73,9 @@ public function isValid($value, Constraint $constraint)
7373

7474
if (!in_array($value->getMimeType(), (array)$constraint->mimeTypes)) {
7575
$this->setMessage($constraint->mimeTypesMessage, array(
76-
'type' => '"'.$value->getMimeType().'"',
77-
'types' => '"'.implode('", "', (array)$constraint->mimeTypes).'"',
78-
'file' => $path,
76+
'{{ type }}' => '"'.$value->getMimeType().'"',
77+
'{{ types }}' => '"'.implode('", "', (array)$constraint->mimeTypes).'"',
78+
'{{ file }}' => $path,
7979
));
8080

8181
return false;

‎src/Symfony/Component/Validator/Constraints/MaxLengthValidator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/MaxLengthValidator.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ public function isValid($value, Constraint $constraint)
2424

2525
if ($length > $constraint->limit) {
2626
$this->setMessage($constraint->message, array(
27-
'value' => $value,
28-
'limit' => $constraint->limit,
27+
'{{ value }}' => $value,
28+
'{{ limit }}' => $constraint->limit,
2929
));
3030

3131
return false;

‎src/Symfony/Component/Validator/Constraints/MaxValidator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/MaxValidator.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public function isValid($value, Constraint $constraint)
2020

2121
if ($value > $constraint->limit) {
2222
$this->setMessage($constraint->message, array(
23-
'value' => $value,
24-
'limit' => $constraint->limit,
23+
'{{ value }}' => $value,
24+
'{{ limit }}' => $constraint->limit,
2525
));
2626

2727
return false;

‎src/Symfony/Component/Validator/Constraints/MinLengthValidator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/MinLengthValidator.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ public function isValid($value, Constraint $constraint)
2424

2525
if ($length < $constraint->limit) {
2626
$this->setMessage($constraint->message, array(
27-
'value' => $value,
28-
'limit' => $constraint->limit,
27+
'{{ value }}' => $value,
28+
'{{ limit }}' => $constraint->limit,
2929
));
3030

3131
return false;

‎src/Symfony/Component/Validator/Constraints/MinValidator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/MinValidator.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public function isValid($value, Constraint $constraint)
2020

2121
if ($value < $constraint->limit) {
2222
$this->setMessage($constraint->message, array(
23-
'value' => $value,
24-
'limit' => $constraint->limit,
23+
'{{ value }}' => $value,
24+
'{{ limit }}' => $constraint->limit,
2525
));
2626

2727
return false;

‎src/Symfony/Component/Validator/Constraints/NullValidator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/NullValidator.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class NullValidator extends ConstraintValidator
1010
public function isValid($value, Constraint $constraint)
1111
{
1212
if (!is_null($value)) {
13-
$this->setMessage($constraint->message, array('value' => $value));
13+
$this->setMessage($constraint->message, array('{{ value }}' => $value));
1414

1515
return false;
1616
}

‎src/Symfony/Component/Validator/Constraints/RegexValidator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/RegexValidator.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function isValid($value, Constraint $constraint)
2626
(!$constraint->match && preg_match($constraint->pattern, $value))
2727
)
2828
{
29-
$this->setMessage($constraint->message, array('value' => $value));
29+
$this->setMessage($constraint->message, array('{{ value }}' => $value));
3030

3131
return false;
3232
}

‎src/Symfony/Component/Validator/Constraints/TimeValidator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/TimeValidator.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function isValid($value, Constraint $constraint)
2323
$value = (string)$value;
2424

2525
if (!preg_match(self::PATTERN, $value)) {
26-
$this->setMessage($constraint->message, array('value' => $value));
26+
$this->setMessage($constraint->message, array('{{ value }}' => $value));
2727

2828
return false;
2929
}

‎src/Symfony/Component/Validator/Constraints/UrlValidator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/UrlValidator.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function isValid($value, Constraint $constraint)
3434
$pattern = sprintf(self::PATTERN, implode('|', $constraint->protocols));
3535

3636
if (!preg_match($pattern, $value)) {
37-
$this->setMessage($constraint->message, array('value' => $value));
37+
$this->setMessage($constraint->message, array('{{ value }}' => $value));
3838

3939
return false;
4040
}

‎src/Symfony/Component/Validator/Constraints/ValidValidator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/ValidValidator.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function isValid($value, Constraint $constraint)
2727
} else if (!is_object($value)) {
2828
throw new UnexpectedTypeException($value, 'object or array');
2929
} else if ($constraint->class && !$value instanceof $constraint->class) {
30-
$this->setMessage($constraint->message, array('class' => $constraint->class));
30+
$this->setMessage($constraint->message, array('{{ class }}' => $constraint->class));
3131

3232
return false;
3333
} else {

‎tests/Symfony/Tests/Component/Validator/Constraints/AssertTypeValidatorTest.php

Copy file name to clipboardExpand all lines: tests/Symfony/Tests/Component/Validator/Constraints/AssertTypeValidatorTest.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ public function testMessageIsSet()
101101
$this->assertFalse($this->validator->isValid('foobar', $constraint));
102102
$this->assertEquals($this->validator->getMessageTemplate(), 'myMessage');
103103
$this->assertEquals($this->validator->getMessageParameters(), array(
104-
'value' => 'foobar',
105-
'type' => 'numeric',
104+
'{{ value }}' => 'foobar',
105+
'{{ type }}' => 'numeric',
106106
));
107107
}
108108

‎tests/Symfony/Tests/Component/Validator/Constraints/BlankValidatorTest.php

Copy file name to clipboardExpand all lines: tests/Symfony/Tests/Component/Validator/Constraints/BlankValidatorTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function testMessageIsSet()
5151
$this->assertFalse($this->validator->isValid('foobar', $constraint));
5252
$this->assertEquals($this->validator->getMessageTemplate(), 'myMessage');
5353
$this->assertEquals($this->validator->getMessageParameters(), array(
54-
'value' => 'foobar',
54+
'{{ value }}' => 'foobar',
5555
));
5656
}
5757
}

‎tests/Symfony/Tests/Component/Validator/Constraints/ChoiceValidatorTest.php

Copy file name to clipboardExpand all lines: tests/Symfony/Tests/Component/Validator/Constraints/ChoiceValidatorTest.php
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public function testInvalidChoice()
118118
$this->assertFalse($this->validator->isValid('baz', $constraint));
119119
$this->assertEquals($this->validator->getMessageTemplate(), 'myMessage');
120120
$this->assertEquals($this->validator->getMessageParameters(), array(
121-
'value' => 'baz',
121+
'{{ value }}' => 'baz',
122122
));
123123
}
124124

@@ -133,7 +133,7 @@ public function testInvalidChoiceMultiple()
133133
$this->assertFalse($this->validator->isValid(array('foo', 'baz'), $constraint));
134134
$this->assertEquals($this->validator->getMessageTemplate(), 'myMessage');
135135
$this->assertEquals($this->validator->getMessageParameters(), array(
136-
'value' => 'baz',
136+
'{{ value }}' => 'baz',
137137
));
138138
}
139139

@@ -149,7 +149,7 @@ public function testTooFewChoices()
149149
$this->assertFalse($this->validator->isValid(array('foo'), $constraint));
150150
$this->assertEquals($this->validator->getMessageTemplate(), 'myMessage');
151151
$this->assertEquals($this->validator->getMessageParameters(), array(
152-
'limit' => 2,
152+
'{{ limit }}' => 2,
153153
));
154154
}
155155

@@ -165,7 +165,7 @@ public function testTooManyChoices()
165165
$this->assertFalse($this->validator->isValid(array('foo', 'bar', 'moo'), $constraint));
166166
$this->assertEquals($this->validator->getMessageTemplate(), 'myMessage');
167167
$this->assertEquals($this->validator->getMessageParameters(), array(
168-
'limit' => 2,
168+
'{{ limit }}' => 2,
169169
));
170170
}
171171
}

‎tests/Symfony/Tests/Component/Validator/Constraints/DateTimeValidatorTest.php

Copy file name to clipboardExpand all lines: tests/Symfony/Tests/Component/Validator/Constraints/DateTimeValidatorTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function testMessageIsSet()
7676
$this->assertFalse($this->validator->isValid('foobar', $constraint));
7777
$this->assertEquals($this->validator->getMessageTemplate(), 'myMessage');
7878
$this->assertEquals($this->validator->getMessageParameters(), array(
79-
'value' => 'foobar',
79+
'{{ value }}' => 'foobar',
8080
));
8181
}
8282
}

‎tests/Symfony/Tests/Component/Validator/Constraints/DateValidatorTest.php

Copy file name to clipboardExpand all lines: tests/Symfony/Tests/Component/Validator/Constraints/DateValidatorTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function testMessageIsSet()
7070
$this->assertFalse($this->validator->isValid('foobar', $constraint));
7171
$this->assertEquals($this->validator->getMessageTemplate(), 'myMessage');
7272
$this->assertEquals($this->validator->getMessageParameters(), array(
73-
'value' => 'foobar',
73+
'{{ value }}' => 'foobar',
7474
));
7575
}
7676
}

‎tests/Symfony/Tests/Component/Validator/Constraints/EmailValidatorTest.php

Copy file name to clipboardExpand all lines: tests/Symfony/Tests/Component/Validator/Constraints/EmailValidatorTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function testMessageIsSet()
7070
$this->assertFalse($this->validator->isValid('foobar', $constraint));
7171
$this->assertEquals($this->validator->getMessageTemplate(), 'myMessage');
7272
$this->assertEquals($this->validator->getMessageParameters(), array(
73-
'value' => 'foobar',
73+
'{{ value }}' => 'foobar',
7474
));
7575
}
7676
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.