Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

[Validator] Code property can't be populated to ConstraintViolation #7276

Closed
wants to merge 7 commits into from

7 participants

@aeoris
Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #7273, #9691
License MIT
Doc PR symfony/symfony-docs#2302
...ny/Component/Validator/Constraints/BlankValidator.php
@@ -27,7 +27,7 @@ class BlankValidator extends ConstraintValidator
public function validate($value, Constraint $constraint)
{
if ('' !== $value && null !== $value) {
- $this->context->addViolation($constraint->message, array('{{ value }}' => $value));
+ $this->context->addViolation($constraint->message, array('{{ value }}' => $value), null, null, $constraint->code);
@vicb
vicb added a note

Take a look at context->addViolation(), I think passing null as the 3rd argument is not equivalent to what was done before, there's a gotcha in the method !

@aeoris
aeoris added a note

Oh! You mean passing $value instead? If so, please tell me and I will change all of them to consider that! Did you detect any other issues?

@vicb
vicb added a note

Yep this is what I mean (and you should add a unit test for that)

No other issue detected but I only quickly scanned it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@aeoris

Ping @vicb

Did my last couple commits solve the issue you pointed out?

@vicb
@aeoris aeoris referenced this pull request from a commit in aeoris/symfony-docs
@aeoris aeoris Add information on code property population 687fea6
@aeoris aeoris referenced this pull request in symfony/symfony-docs
Closed

[WCM] Add information on code property population #2302

@aeoris

Done! I just don't know whether this is a new feature or a bug fix, so I selected both and made a PR to symfony-docs as well.

@stof
Collaborator

you are adding a way to configure the code in the constraint. This is a new feature. I updated the description accordingly

@fabpot
Owner

ping @bschussek

@webmozart
Collaborator

@fabpot The implementation of this PR doesn't match the specification in #7273.

@aeoris Do you have time to update this PR?

@aeoris

@bschussek Haven't forgot this issue, and I'm happy to say that I finally have time enough to give it a go. I'm on it!

aeoris added some commits
@aeoris aeoris Merge remote-tracking branch 'upstream/master' into ConstraintViolati…
…onCode

Conflicts:
	src/Symfony/Component/Validator/Constraints/CountryValidator.php
	src/Symfony/Component/Validator/Constraints/LanguageValidator.php
	src/Symfony/Component/Validator/Constraints/LocaleValidator.php
	src/Symfony/Component/Validator/Constraints/MaxLengthValidator.php
	src/Symfony/Component/Validator/Constraints/MaxValidator.php
	src/Symfony/Component/Validator/Constraints/MinLengthValidator.php
	src/Symfony/Component/Validator/Constraints/MinValidator.php
e2eca8e
@aeoris aeoris Added unique error codes on constraints (#7273, #7276, #5525). 82249ff
@aeoris

@bschussek can you please check whether this PR matches #7273 now? Thanks!

@cordoval

@aeoris could you please add to the description table that it fixes #9691 please ? :baby:

@aeoris

@cordoval done, thanks!

@cordoval

:+1: just make sure you have not missed testing each of those codes i guess? also how are you generating the codes, so that in future additions is clear how you are generating those codes. Thanks.

@aeoris

@cordoval I'll double check the tests as soon as I get back home next Monday.

The codes are RFC 4122-compliant 128 bit random values as proposed here by @bschussek: #7273 (comment)

@aeoris

@cordoval I did indeed miss three code checks, but those are fixed now.

@stloyd

@fabpot @webmozart Could you have a look at this?

@aeoris

@webmozart any progress on this?

@webmozart webmozart referenced this pull request from a commit
@webmozart webmozart feature #11657 [Validator] Added ConstraintViolation::getConstraint()…
… (webmozart)

This PR was merged into the 2.6-dev branch.

Discussion
----------

[Validator] Added ConstraintViolation::getConstraint()

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #5050
| License       | MIT
| Doc PR        | -

This PR adds a `getConstraint()` method to the `ConstraintViolation` in order to access the constraint causing the violation.

Related to #7276, #7273 and #9691.

Commits
-------

ce1d209 [Validator] Added ConstraintViolation::getConstraint()
2293556
@webmozart
Collaborator

Replaced by #12005.

@webmozart webmozart closed this
@fabpot fabpot referenced this pull request from a commit
@fabpot fabpot minor #12015 [Validator] Simplified testing of violations (webmozart)
This PR was merged into the 2.3 branch.

Discussion
----------

[Validator] Simplified testing of violations

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

I simplified the assertion of violations in preparation of a replacement PR for #7276.

Commits
-------

8e5537b [Validator] Simplified testing of violations
87123f6
@webmozart webmozart referenced this pull request from a commit
@webmozart webmozart feature #12021 [Validator] Added error codes to all constraints with …
…multiple error causes (webmozart)

This PR was merged into the 2.6-dev branch.

Discussion
----------

[Validator] Added error codes to all constraints with multiple error causes

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #7276
| License       | MIT
| Doc PR        | TODO

This PR depends on #12015 and #12016 being merged first. However, a few changes in 52cb7df first must be backported to #12016.

This PR introduces error codes for all constraints with multiple error paths. This lets you determine what exactly the reason was that a constraint failed:

```php
$validator = Validation::createValidator();

$violations = $validator->validate('0-4X19-92619812', new Isbn());

foreach ($violations as $violation) {
    var_dump($violation->getCode());
    // => int(3)
    var_dump(Isbn::getErrorName($violation->getCode()));
    // => string(24) "ERROR_INVALID_CHARACTERS"
    var_dump($violation->getConstraint()->getErrorName($violation->getCode()));
    // => string(24) "ERROR_INVALID_CHARACTERS"
}
```

The `getErrorName()` method is especially helpful for REST APIs, where you can return both an error code and a description of that error now.

**Todos**

- [x] Backport a few structural changes to #12016
- [x] Update constraints outside of the Validator component
- [x] Rebase on master (after merging #12015 and #12016)

Commits
-------

3b50bf2 [Validator] Added error codes to all constraints with multiple error causes
95d68a1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 5, 2013
  1. @aeoris
Commits on Mar 6, 2013
  1. @aeoris
  2. @aeoris
Commits on Nov 2, 2013
  1. @aeoris

    Merge remote-tracking branch 'upstream/master' into ConstraintViolati…

    aeoris authored
    …onCode
    
    Conflicts:
    	src/Symfony/Component/Validator/Constraints/CountryValidator.php
    	src/Symfony/Component/Validator/Constraints/LanguageValidator.php
    	src/Symfony/Component/Validator/Constraints/LocaleValidator.php
    	src/Symfony/Component/Validator/Constraints/MaxLengthValidator.php
    	src/Symfony/Component/Validator/Constraints/MaxValidator.php
    	src/Symfony/Component/Validator/Constraints/MinLengthValidator.php
    	src/Symfony/Component/Validator/Constraints/MinValidator.php
Commits on Nov 3, 2013
  1. @aeoris
Commits on Feb 15, 2014
  1. @aeoris
  2. @aeoris

    CS fixes.

    aeoris authored
This page is out of date. Refresh to see the latest.
Showing with 342 additions and 181 deletions.
  1. +5 −0 src/Symfony/Component/Validator/Constraint.php
  2. +1 −1  src/Symfony/Component/Validator/Constraints/AbstractComparisonValidator.php
  3. +2 −0  src/Symfony/Component/Validator/Constraints/Blank.php
  4. +1 −1  src/Symfony/Component/Validator/Constraints/BlankValidator.php
  5. +2 −0  src/Symfony/Component/Validator/Constraints/CardScheme.php
  6. +2 −2 src/Symfony/Component/Validator/Constraints/CardSchemeValidator.php
  7. +5 −0 src/Symfony/Component/Validator/Constraints/Choice.php
  8. +4 −4 src/Symfony/Component/Validator/Constraints/ChoiceValidator.php
  9. +3 −2 src/Symfony/Component/Validator/Constraints/Collection.php
  10. +2 −3 src/Symfony/Component/Validator/Constraints/CollectionValidator.php
  11. +4 −0 src/Symfony/Component/Validator/Constraints/Count.php
  12. +3 −3 src/Symfony/Component/Validator/Constraints/CountValidator.php
  13. +2 −0  src/Symfony/Component/Validator/Constraints/Country.php
  14. +1 −1  src/Symfony/Component/Validator/Constraints/CountryValidator.php
  15. +2 −0  src/Symfony/Component/Validator/Constraints/Currency.php
  16. +1 −1  src/Symfony/Component/Validator/Constraints/CurrencyValidator.php
  17. +2 −0  src/Symfony/Component/Validator/Constraints/Date.php
  18. +2 −0  src/Symfony/Component/Validator/Constraints/DateTime.php
  19. +1 −1  src/Symfony/Component/Validator/Constraints/DateValidator.php
  20. +2 −0  src/Symfony/Component/Validator/Constraints/Email.php
  21. +1 −1  src/Symfony/Component/Validator/Constraints/EmailValidator.php
  22. +2 −0  src/Symfony/Component/Validator/Constraints/EqualTo.php
  23. +2 −0  src/Symfony/Component/Validator/Constraints/Expression.php
  24. +1 −1  src/Symfony/Component/Validator/Constraints/ExpressionValidator.php
  25. +2 −0  src/Symfony/Component/Validator/Constraints/False.php
  26. +1 −1  src/Symfony/Component/Validator/Constraints/FalseValidator.php
  27. +14 −0 src/Symfony/Component/Validator/Constraints/File.php
  28. +12 −12 src/Symfony/Component/Validator/Constraints/FileValidator.php
  29. +2 −0  src/Symfony/Component/Validator/Constraints/GreaterThan.php
  30. +2 −0  src/Symfony/Component/Validator/Constraints/GreaterThanOrEqual.php
  31. +2 −0  src/Symfony/Component/Validator/Constraints/Iban.php
  32. +2 −2 src/Symfony/Component/Validator/Constraints/IbanValidator.php
  33. +2 −0  src/Symfony/Component/Validator/Constraints/IdenticalTo.php
  34. +12 −0 src/Symfony/Component/Validator/Constraints/Image.php
  35. +10 −10 src/Symfony/Component/Validator/Constraints/ImageValidator.php
  36. +2 −0  src/Symfony/Component/Validator/Constraints/Ip.php
  37. +1 −1  src/Symfony/Component/Validator/Constraints/IpValidator.php
  38. +4 −0 src/Symfony/Component/Validator/Constraints/Isbn.php
  39. +16 −15 src/Symfony/Component/Validator/Constraints/IsbnValidator.php
  40. +2 −0  src/Symfony/Component/Validator/Constraints/Issn.php
  41. +2 −2 src/Symfony/Component/Validator/Constraints/IssnValidator.php
  42. +2 −0  src/Symfony/Component/Validator/Constraints/Language.php
  43. +1 −1  src/Symfony/Component/Validator/Constraints/LanguageValidator.php
  44. +4 −0 src/Symfony/Component/Validator/Constraints/Length.php
  45. +3 −3 src/Symfony/Component/Validator/Constraints/LengthValidator.php
  46. +2 −0  src/Symfony/Component/Validator/Constraints/LessThan.php
  47. +2 −0  src/Symfony/Component/Validator/Constraints/LessThanOrEqual.php
  48. +2 −0  src/Symfony/Component/Validator/Constraints/Locale.php
  49. +1 −1  src/Symfony/Component/Validator/Constraints/LocaleValidator.php
  50. +2 −0  src/Symfony/Component/Validator/Constraints/Luhn.php
  51. +2 −2 src/Symfony/Component/Validator/Constraints/LuhnValidator.php
  52. +2 −0  src/Symfony/Component/Validator/Constraints/NotBlank.php
  53. +1 −1  src/Symfony/Component/Validator/Constraints/NotBlankValidator.php
  54. +2 −0  src/Symfony/Component/Validator/Constraints/NotEqualTo.php
  55. +2 −0  src/Symfony/Component/Validator/Constraints/NotIdenticalTo.php
  56. +2 −0  src/Symfony/Component/Validator/Constraints/NotNull.php
  57. +1 −1  src/Symfony/Component/Validator/Constraints/NotNullValidator.php
  58. +2 −0  src/Symfony/Component/Validator/Constraints/Null.php
  59. +1 −1  src/Symfony/Component/Validator/Constraints/NullValidator.php
  60. +4 −0 src/Symfony/Component/Validator/Constraints/Range.php
  61. +3 −3 src/Symfony/Component/Validator/Constraints/RangeValidator.php
  62. +2 −0  src/Symfony/Component/Validator/Constraints/Regex.php
  63. +1 −1  src/Symfony/Component/Validator/Constraints/RegexValidator.php
  64. +2 −0  src/Symfony/Component/Validator/Constraints/Time.php
  65. +1 −1  src/Symfony/Component/Validator/Constraints/TimeValidator.php
  66. +2 −0  src/Symfony/Component/Validator/Constraints/True.php
  67. +1 −1  src/Symfony/Component/Validator/Constraints/TrueValidator.php
  68. +2 −0  src/Symfony/Component/Validator/Constraints/Type.php
  69. +1 −1  src/Symfony/Component/Validator/Constraints/TypeValidator.php
  70. +2 −0  src/Symfony/Component/Validator/Constraints/Url.php
  71. +1 −1  src/Symfony/Component/Validator/Constraints/UrlValidator.php
  72. +2 −2 src/Symfony/Component/Validator/ExecutionContextInterface.php
  73. +1 −1  src/Symfony/Component/Validator/Tests/Constraints/AbstractComparisonValidatorTestCase.php
  74. +1 −1  src/Symfony/Component/Validator/Tests/Constraints/BlankValidatorTest.php
  75. +8 −2 src/Symfony/Component/Validator/Tests/Constraints/CardSchemeValidatorTest.php
  76. +9 −9 src/Symfony/Component/Validator/Tests/Constraints/ChoiceValidatorTest.php
  77. +3 −3 src/Symfony/Component/Validator/Tests/Constraints/CollectionValidatorTest.php
  78. +3 −3 src/Symfony/Component/Validator/Tests/Constraints/CountValidatorTest.php
  79. +1 −1  src/Symfony/Component/Validator/Tests/Constraints/CountryValidatorTest.php
  80. +1 −1  src/Symfony/Component/Validator/Tests/Constraints/CurrencyValidatorTest.php
  81. +1 −1  src/Symfony/Component/Validator/Tests/Constraints/DateTimeValidatorTest.php
  82. +1 −1  src/Symfony/Component/Validator/Tests/Constraints/DateValidatorTest.php
  83. +1 −1  src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php
  84. +14 −1 src/Symfony/Component/Validator/Tests/Constraints/FalseValidatorTest.php
  85. +1 −1  src/Symfony/Component/Validator/Tests/Constraints/FileValidatorPathTest.php
  86. +16 −16 src/Symfony/Component/Validator/Tests/Constraints/FileValidatorTest.php
  87. +1 −1  src/Symfony/Component/Validator/Tests/Constraints/IbanValidatorTest.php
  88. +9 −9 src/Symfony/Component/Validator/Tests/Constraints/ImageValidatorTest.php
  89. +12 −12 src/Symfony/Component/Validator/Tests/Constraints/IpValidatorTest.php
  90. +9 −3 src/Symfony/Component/Validator/Tests/Constraints/IsbnValidatorTest.php
  91. +15 −5 src/Symfony/Component/Validator/Tests/Constraints/IssnValidatorTest.php
  92. +1 −1  src/Symfony/Component/Validator/Tests/Constraints/LanguageValidatorTest.php
  93. +3 −3 src/Symfony/Component/Validator/Tests/Constraints/LengthValidatorTest.php
  94. +1 −1  src/Symfony/Component/Validator/Tests/Constraints/LocaleValidatorTest.php
  95. +3 −1 src/Symfony/Component/Validator/Tests/Constraints/LuhnValidatorTest.php
  96. +4 −4 src/Symfony/Component/Validator/Tests/Constraints/NotBlankValidatorTest.php
  97. +1 −1  src/Symfony/Component/Validator/Tests/Constraints/NotNullValidatorTest.php
  98. +1 −1  src/Symfony/Component/Validator/Tests/Constraints/NullValidatorTest.php
  99. +6 −6 src/Symfony/Component/Validator/Tests/Constraints/RangeValidatorTest.php
  100. +1 −1  src/Symfony/Component/Validator/Tests/Constraints/RegexValidatorTest.php
  101. +1 −1  src/Symfony/Component/Validator/Tests/Constraints/TimeValidatorTest.php
  102. +1 −1  src/Symfony/Component/Validator/Tests/Constraints/TrueValidatorTest.php
  103. +12 −3 src/Symfony/Component/Validator/Tests/Constraints/TypeValidatorTest.php
  104. +1 −1  src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php
View
5 src/Symfony/Component/Validator/Constraint.php
@@ -54,6 +54,11 @@
public $groups = array(self::DEFAULT_GROUP);
/**
+ * @var mixed
+ */
+ public $code;
+
+ /**
* Initializes the constraint with options.
*
* You should pass an associative array. The keys should be the names of
View
2  src/Symfony/Component/Validator/Constraints/AbstractComparisonValidator.php
@@ -35,7 +35,7 @@ public function validate($value, Constraint $constraint)
'{{ value }}' => $this->valueToString($constraint->value),
'{{ compared_value }}' => $this->valueToString($constraint->value),
'{{ compared_value_type }}' => $this->valueToType($constraint->value)
- ));
+ ), $constraint->value, null, $constraint::ERROR);
}
}
View
2  src/Symfony/Component/Validator/Constraints/Blank.php
@@ -22,5 +22,7 @@
*/
class Blank extends Constraint
{
+ const ERROR = '3dfbbd3d-faed-46de-b781-fb1c3c9bbac3';
+
public $message = 'This value should be blank.';
}
View
2  src/Symfony/Component/Validator/Constraints/BlankValidator.php
@@ -27,7 +27,7 @@ class BlankValidator extends ConstraintValidator
public function validate($value, Constraint $constraint)
{
if ('' !== $value && null !== $value) {
- $this->context->addViolation($constraint->message, array('{{ value }}' => $value));
+ $this->context->addViolation($constraint->message, array('{{ value }}' => $value), $value, null, $constraint::ERROR);
}
}
}
View
2  src/Symfony/Component/Validator/Constraints/CardScheme.php
@@ -20,6 +20,8 @@
*/
class CardScheme extends Constraint
{
+ const ERROR = '300f90d4-23d9-4bfe-a922-ebecff115e9d';
+
public $message = 'Unsupported card type or invalid card number.';
public $schemes;
View
4 src/Symfony/Component/Validator/Constraints/CardSchemeValidator.php
@@ -108,7 +108,7 @@ public function validate($value, Constraint $constraint)
}
if (!is_numeric($value)) {
- $this->context->addViolation($constraint->message);
+ $this->context->addViolation($constraint->message, array(), $value, null, $constraint::ERROR);
return;
}
@@ -124,6 +124,6 @@ public function validate($value, Constraint $constraint)
}
}
- $this->context->addViolation($constraint->message);
+ $this->context->addViolation($constraint->message, array(), $value, null, $constraint::ERROR);
}
}
View
5 src/Symfony/Component/Validator/Constraints/Choice.php
@@ -22,6 +22,11 @@
*/
class Choice extends Constraint
{
+ const ERROR = '75d601e8-d9da-49a6-bf32-6df461244744';
+ const ERROR_MULTIPLE = '695ad03b-1cdc-4b97-81d2-60c7de8424b5';
+ const ERROR_MIN = '34f58897-1e70-4353-97d7-27ebd472406e';
+ const ERROR_MAX = '73311798-3160-48b9-b71a-1502ba9e45d6';
+
public $choices;
public $callback;
public $multiple = false;
View
8 src/Symfony/Component/Validator/Constraints/ChoiceValidator.php
@@ -59,25 +59,25 @@ public function validate($value, Constraint $constraint)
if ($constraint->multiple) {
foreach ($value as $_value) {
if (!in_array($_value, $choices, $constraint->strict)) {
- $this->context->addViolation($constraint->multipleMessage, array('{{ value }}' => $_value));
+ $this->context->addViolation($constraint->multipleMessage, array('{{ value }}' => $_value), $_value, null, $constraint::ERROR_MULTIPLE);
}
}
$count = count($value);
if ($constraint->min !== null && $count < $constraint->min) {
- $this->context->addViolation($constraint->minMessage, array('{{ limit }}' => $constraint->min), null, (int) $constraint->min);
+ $this->context->addViolation($constraint->minMessage, array('{{ limit }}' => $constraint->min), null, (int) $constraint->min, $constraint::ERROR_MIN);
return;
}
if ($constraint->max !== null && $count > $constraint->max) {
- $this->context->addViolation($constraint->maxMessage, array('{{ limit }}' => $constraint->max), null, (int) $constraint->max);
+ $this->context->addViolation($constraint->maxMessage, array('{{ limit }}' => $constraint->max), null, (int) $constraint->max, $constraint::ERROR_MAX);
return;
}
} elseif (!in_array($value, $choices, $constraint->strict)) {
- $this->context->addViolation($constraint->message, array('{{ value }}' => $value));
+ $this->context->addViolation($constraint->message, array('{{ value }}' => $value), $value, null, $constraint::ERROR);
}
}
}
View
5 src/Symfony/Component/Validator/Constraints/Collection.php
@@ -12,8 +12,6 @@
namespace Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
-use Symfony\Component\Validator\Constraints\Required;
-use Symfony\Component\Validator\Constraints\Optional;
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
/**
@@ -25,6 +23,9 @@
*/
class Collection extends Constraint
{
+ const ERROR_EXTRA_FIELD = 'd3a68ca4-4836-42d9-a2c8-c21103a18b3f';
+ const ERROR_MISSING_FIELD = 'fb668c0b-5d90-4bda-8a3e-1fe4f1d5335b';
+
public $fields;
public $allowExtraFields = false;
public $allowMissingFields = false;
View
5 src/Symfony/Component/Validator/Constraints/CollectionValidator.php
@@ -14,7 +14,6 @@
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
-use Symfony\Component\Validator\Constraints\Optional;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
@@ -50,7 +49,7 @@ public function validate($value, Constraint $constraint)
} elseif (!$fieldConstraint instanceof Optional && !$constraint->allowMissingFields) {
$this->context->addViolationAt('['.$field.']', $constraint->missingFieldsMessage, array(
'{{ field }}' => $field
- ), null);
+ ), $field, $constraint::ERROR_MISSING_FIELD);
}
}
@@ -59,7 +58,7 @@ public function validate($value, Constraint $constraint)
if (!isset($constraint->fields[$field])) {
$this->context->addViolationAt('['.$field.']', $constraint->extraFieldsMessage, array(
'{{ field }}' => $field
- ), $fieldValue);
+ ), $field, null, $constraint::ERROR_EXTRA_FIELD);
}
}
}
View
4 src/Symfony/Component/Validator/Constraints/Count.php
@@ -23,6 +23,10 @@
*/
class Count extends Constraint
{
+ const ERROR_MIN = '4b57ee81-3a6b-4b43-93ae-69441571d39e';
+ const ERROR_MAX = '9537c665-37eb-4515-a1fd-7beff83e6c1f';
+ const ERROR_EXACT = 'd3625fef-ce0a-4332-a89e-408078ed6e58';
+
public $minMessage = 'This collection should contain {{ limit }} element or more.|This collection should contain {{ limit }} elements or more.';
public $maxMessage = 'This collection should contain {{ limit }} element or less.|This collection should contain {{ limit }} elements or less.';
public $exactMessage = 'This collection should contain exactly {{ limit }} element.|This collection should contain exactly {{ limit }} elements.';
View
6 src/Symfony/Component/Validator/Constraints/CountValidator.php
@@ -39,7 +39,7 @@ public function validate($value, Constraint $constraint)
$this->context->addViolation($constraint->exactMessage, array(
'{{ count }}' => $count,
'{{ limit }}' => $constraint->min,
- ), $value, (int) $constraint->min);
+ ), $value, (int) $constraint->min, $constraint::ERROR_EXACT);
return;
}
@@ -48,7 +48,7 @@ public function validate($value, Constraint $constraint)
$this->context->addViolation($constraint->maxMessage, array(
'{{ count }}' => $count,
'{{ limit }}' => $constraint->max,
- ), $value, (int) $constraint->max);
+ ), $value, (int) $constraint->max, $constraint::ERROR_MAX);
return;
}
@@ -57,7 +57,7 @@ public function validate($value, Constraint $constraint)
$this->context->addViolation($constraint->minMessage, array(
'{{ count }}' => $count,
'{{ limit }}' => $constraint->min,
- ), $value, (int) $constraint->min);
+ ), $value, (int) $constraint->min, $constraint::ERROR_MIN);
}
}
}
View
2  src/Symfony/Component/Validator/Constraints/Country.php
@@ -22,5 +22,7 @@
*/
class Country extends Constraint
{
+ const ERROR = '326b7f14-6fde-4489-8e9b-8458ecc2e559';
+
public $message = 'This value is not a valid country.';
}
View
2  src/Symfony/Component/Validator/Constraints/CountryValidator.php
@@ -42,7 +42,7 @@ public function validate($value, Constraint $constraint)
$countries = Intl::getRegionBundle()->getCountryNames();
if (!isset($countries[$value])) {
- $this->context->addViolation($constraint->message, array('{{ value }}' => $value));
+ $this->context->addViolation($constraint->message, array('{{ value }}' => $value), $value, null, $constraint::ERROR);
}
}
}
View
2  src/Symfony/Component/Validator/Constraints/Currency.php
@@ -22,5 +22,7 @@
*/
class Currency extends Constraint
{
+ const ERROR = 'f68a8d40-4231-4afd-83ac-0bcd818dc818';
+
public $message = 'This value is not a valid currency.';
}
View
2  src/Symfony/Component/Validator/Constraints/CurrencyValidator.php
@@ -42,7 +42,7 @@ public function validate($value, Constraint $constraint)
$currencies = Intl::getCurrencyBundle()->getCurrencyNames();
if (!isset($currencies[$value])) {
- $this->context->addViolation($constraint->message, array('{{ value }}' => $value));
+ $this->context->addViolation($constraint->message, array('{{ value }}' => $value), $value, null, $constraint::ERROR);
}
}
}
View
2  src/Symfony/Component/Validator/Constraints/Date.php
@@ -22,5 +22,7 @@
*/
class Date extends Constraint
{
+ const ERROR = 'f360bec2-4636-46ad-8ef6-aecc65e08a00';
+
public $message = 'This value is not a valid date.';
}
View
2  src/Symfony/Component/Validator/Constraints/DateTime.php
@@ -22,5 +22,7 @@
*/
class DateTime extends Constraint
{
+ const ERROR = '383654a2-f53e-4529-ace3-176742663f3a';
+
public $message = 'This value is not a valid datetime.';
}
View
2  src/Symfony/Component/Validator/Constraints/DateValidator.php
@@ -40,7 +40,7 @@ public function validate($value, Constraint $constraint)
$value = (string) $value;
if (!preg_match(static::PATTERN, $value, $matches) || !checkdate($matches[2], $matches[3], $matches[1])) {
- $this->context->addViolation($constraint->message, array('{{ value }}' => $value));
+ $this->context->addViolation($constraint->message, array('{{ value }}' => $value), $value, null, $constraint::ERROR);
}
}
}
View
2  src/Symfony/Component/Validator/Constraints/Email.php
@@ -22,6 +22,8 @@
*/
class Email extends Constraint
{
+ const ERROR = '38b1dcdc-501a-43c1-98e1-4ab0971ca1b2';
+
public $message = 'This value is not a valid email address.';
public $checkMX = false;
public $checkHost = false;
View
2  src/Symfony/Component/Validator/Constraints/EmailValidator.php
@@ -50,7 +50,7 @@ public function validate($value, Constraint $constraint)
}
if (!$valid) {
- $this->context->addViolation($constraint->message, array('{{ value }}' => $value));
+ $this->context->addViolation($constraint->message, array('{{ value }}' => $value), $value, null, $constraint::ERROR);
}
}
View
2  src/Symfony/Component/Validator/Constraints/EqualTo.php
@@ -18,5 +18,7 @@
*/
class EqualTo extends AbstractComparison
{
+ const ERROR = 'f92206ec-df92-406d-931b-833343889cd7';
+
public $message = 'This value should be equal to {{ compared_value }}.';
}
View
2  src/Symfony/Component/Validator/Constraints/Expression.php
@@ -21,6 +21,8 @@
*/
class Expression extends Constraint
{
+ const ERROR = '2fe78c81-b47e-4d20-952b-f571a301a8df';
+
public $message = 'This value is not valid.';
public $expression;
View
2  src/Symfony/Component/Validator/Constraints/ExpressionValidator.php
@@ -64,7 +64,7 @@ public function validate($value, Constraint $constraint)
}
if (!$this->getExpressionLanguage()->evaluate($constraint->expression, $variables)) {
- $this->context->addViolation($constraint->message);
+ $this->context->addViolation($constraint->message, array('{{ value }}' => $value), $value, null, $constraint::ERROR);
}
}
View
2  src/Symfony/Component/Validator/Constraints/False.php
@@ -22,5 +22,7 @@
*/
class False extends Constraint
{
+ const ERROR = '890770b4-e5c4-49e5-a285-b480ab42b43a';
+
public $message = 'This value should be false.';
}
View
2  src/Symfony/Component/Validator/Constraints/FalseValidator.php
@@ -30,6 +30,6 @@ public function validate($value, Constraint $constraint)
return;
}
- $this->context->addViolation($constraint->message);
+ $this->context->addViolation($constraint->message, array(), $value, null, $constraint::ERROR);
}
}
View
14 src/Symfony/Component/Validator/Constraints/File.php
@@ -22,6 +22,20 @@
*/
class File extends Constraint
{
+ const ERROR_NOT_FOUND = '61fbc820-360e-4635-8410-6e18c55d0793';
+ const ERROR_NOT_READABLE = '27fb8e2a-e615-460a-8248-2b9fd7fb0f03';
+ const ERROR_MAX_SIZE = '94ab2b21-4bb2-4f2c-8b0f-2f23ee3fa083';
+ const ERROR_MIME_TYPE = 'aeaf332e-eb9f-4f5b-954b-73a4ee10099b';
+
+ const ERROR_UPLOAD_INI_SIZE = '3ccb63bf-288f-4a83-9ded-750eb60efeb7';
+ const ERROR_UPLOAD_FORM_SIZE = 'd8af3119-4ca1-4b68-b6a8-742fd1713dfb';
+ const ERROR_UPLOAD_PARTIAL = '9607840b-25a2-4a06-b6de-a443fdf7bc89';
+ const ERROR_UPLOAD_NO_FILE = '5025cb15-812e-411c-8837-cae3106dec7c';
+ const ERROR_UPLOAD_NO_TMP_DIR = '6507b3da-97db-4c89-9628-2b41b4772fed';
+ const ERROR_UPLOAD_CANT_WRITE = '3da80e51-9c7d-41ea-b077-7385633c9bbc';
+ const ERROR_UPLOAD_EXTENSION = 'fc050994-f85a-4226-b35f-7a7e55fe29d4';
+ const ERROR_UPLOAD = '4e786105-6f8b-42fa-a409-f29792fa297a';
+
public $maxSize = null;
public $mimeTypes = array();
public $notFoundMessage = 'The file could not be found.';
View
24 src/Symfony/Component/Validator/Constraints/FileValidator.php
@@ -55,35 +55,35 @@ public function validate($value, Constraint $constraint)
$this->context->addViolation($constraint->uploadIniSizeErrorMessage, array(
'{{ limit }}' => $maxSize,
'{{ suffix }}' => 'bytes',
- ));
+ ), $value, null, $constraint::ERROR_UPLOAD_INI_SIZE);
return;
case UPLOAD_ERR_FORM_SIZE:
- $this->context->addViolation($constraint->uploadFormSizeErrorMessage);
+ $this->context->addViolation($constraint->uploadFormSizeErrorMessage, array(), $value, null, $constraint::ERROR_UPLOAD_FORM_SIZE);
return;
case UPLOAD_ERR_PARTIAL:
- $this->context->addViolation($constraint->uploadPartialErrorMessage);
+ $this->context->addViolation($constraint->uploadPartialErrorMessage, array(), $value, null, $constraint::ERROR_UPLOAD_PARTIAL);
return;
case UPLOAD_ERR_NO_FILE:
- $this->context->addViolation($constraint->uploadNoFileErrorMessage);
+ $this->context->addViolation($constraint->uploadNoFileErrorMessage, array(), $value, null, $constraint::ERROR_UPLOAD_NO_FILE);
return;
case UPLOAD_ERR_NO_TMP_DIR:
- $this->context->addViolation($constraint->uploadNoTmpDirErrorMessage);
+ $this->context->addViolation($constraint->uploadNoTmpDirErrorMessage, array(), $value, null, $constraint::ERROR_UPLOAD_NO_TMP_DIR);
return;
case UPLOAD_ERR_CANT_WRITE:
- $this->context->addViolation($constraint->uploadCantWriteErrorMessage);
+ $this->context->addViolation($constraint->uploadCantWriteErrorMessage, array(), $value, null, $constraint::ERROR_UPLOAD_CANT_WRITE);
return;
case UPLOAD_ERR_EXTENSION:
- $this->context->addViolation($constraint->uploadExtensionErrorMessage);
+ $this->context->addViolation($constraint->uploadExtensionErrorMessage, array(), $value, null, $constraint::ERROR_UPLOAD_EXTENSION);
return;
default:
- $this->context->addViolation($constraint->uploadErrorMessage);
+ $this->context->addViolation($constraint->uploadErrorMessage, array(), $value, null, $constraint::ERROR_UPLOAD);
return;
}
@@ -96,13 +96,13 @@ public function validate($value, Constraint $constraint)
$path = $value instanceof FileObject ? $value->getPathname() : (string) $value;
if (!is_file($path)) {
- $this->context->addViolation($constraint->notFoundMessage, array('{{ file }}' => $path));
+ $this->context->addViolation($constraint->notFoundMessage, array('{{ file }}' => $path), $value, null, $constraint::ERROR_NOT_FOUND);
return;
}
if (!is_readable($path)) {
- $this->context->addViolation($constraint->notReadableMessage, array('{{ file }}' => $path));
+ $this->context->addViolation($constraint->notReadableMessage, array('{{ file }}' => $path), $value, null, $constraint::ERROR_NOT_READABLE);
return;
}
@@ -130,7 +130,7 @@ public function validate($value, Constraint $constraint)
'{{ limit }}' => $limit,
'{{ suffix }}' => $suffix,
'{{ file }}' => $path,
- ));
+ ), $value, null, $constraint::ERROR_MAX_SIZE);
return;
}
@@ -164,7 +164,7 @@ public function validate($value, Constraint $constraint)
'{{ type }}' => '"'.$mime.'"',
'{{ types }}' => '"'.implode('", "', $mimeTypes) .'"',
'{{ file }}' => $path,
- ));
+ ), $value, null, $constraint::ERROR_MIME_TYPE);
}
}
}
View
2  src/Symfony/Component/Validator/Constraints/GreaterThan.php
@@ -18,5 +18,7 @@
*/
class GreaterThan extends AbstractComparison
{
+ const ERROR = '48f4b8a5-832c-4ffc-92b5-64dcd6312c32';
+
public $message = 'This value should be greater than {{ compared_value }}.';
}
View
2  src/Symfony/Component/Validator/Constraints/GreaterThanOrEqual.php
@@ -18,5 +18,7 @@
*/
class GreaterThanOrEqual extends AbstractComparison
{
+ const ERROR = 'd53fb887-5eef-4c1c-8898-02ca753e949b';
+
public $message = 'This value should be greater than or equal to {{ compared_value }}.';
}
View
2  src/Symfony/Component/Validator/Constraints/Iban.php
@@ -18,5 +18,7 @@
*/
class Iban extends Constraint
{
+ const ERROR = '403389e4-59d7-4942-ad9c-b5ba5a0a6a92';
+
public $message = 'This is not a valid International Bank Account Number (IBAN).';
}
View
4 src/Symfony/Component/Validator/Constraints/IbanValidator.php
@@ -33,7 +33,7 @@ public function validate($value, Constraint $constraint)
$teststring = preg_replace('/\s+/', '', $value);
if (strlen($teststring) < 4) {
- $this->context->addViolation($constraint->message, array('{{ value }}' => $value));
+ $this->context->addViolation($constraint->message, array('{{ value }}' => $value), $value, null, $constraint::ERROR);
return;
}
@@ -55,7 +55,7 @@ public function validate($value, Constraint $constraint)
}
if ($rest != 1) {
- $this->context->addViolation($constraint->message, array('{{ value }}' => $value));
+ $this->context->addViolation($constraint->message, array('{{ value }}' => $value), $value, null, $constraint::ERROR);
return;
}
View
2  src/Symfony/Component/Validator/Constraints/IdenticalTo.php
@@ -18,5 +18,7 @@
*/
class IdenticalTo extends AbstractComparison
{
+ const ERROR = '5368c23a-37c0-4148-83bc-7ee8ac34a1af';
+
public $message = 'This value should be identical to {{ compared_value_type }} {{ compared_value }}.';
}
View
12 src/Symfony/Component/Validator/Constraints/Image.php
@@ -18,6 +18,17 @@
*/
class Image extends File
{
+ const ERROR_SIZE_NOT_DETECTED = '1ea61424-9a94-46e5-89b1-26fa91dacf55';
+ const ERROR_MAX_WIDTH = 'a92d747a-9cd8-4194-bbba-ac9d40f438fe';
+ const ERROR_MIN_WIDTH = '52479c81-46e9-4302-b15d-f9c36b6cd6ce';
+ const ERROR_MAX_HEIGHT = '57d13e39-13ed-4dde-b562-2d5a8b52ef96';
+ const ERROR_MIN_HEIGHT = '48378c83-eaf2-436a-b972-f28ca6cc5e2b';
+ const ERROR_MAX_RATIO = '90ddd17c-3beb-4f89-84d2-444734ae4e71';
+ const ERROR_MIN_RATIO = '17cd9582-15f0-4238-b778-f72a31b4debe';
+ const ERROR_DONT_ALLOW_SQUARE = 'ac8f80d1-9432-419e-859f-10142f6daed9';
+ const ERROR_DONT_ALLOW_LANDSCAPE = '2d77d2b1-1c41-405d-9dee-db260bae2fb8';
+ const ERROR_DONT_ALLOW_PORTRAIT = '84451f62-d4e2-4ab1-96be-dc7c25e0e4d9';
+
public $mimeTypes = 'image/*';
public $minWidth = null;
public $maxWidth = null;
@@ -29,6 +40,7 @@ class Image extends File
public $allowLandscape = true;
public $allowPortrait = true;
+ // The constant for a wrong MIME type is taken from the parent class.
public $mimeTypesMessage = 'This file is not a valid image.';
public $sizeNotDetectedMessage = 'The size of the image could not be detected.';
public $maxWidthMessage = 'The image width is too big ({{ width }}px). Allowed maximum width is {{ max_width }}px.';
View
20 src/Symfony/Component/Validator/Constraints/ImageValidator.php
@@ -46,7 +46,7 @@ public function validate($value, Constraint $constraint)
$size = @getimagesize($value);
if (empty($size) || ($size[0] === 0) || ($size[1] === 0)) {
- $this->context->addViolation($constraint->sizeNotDetectedMessage);
+ $this->context->addViolation($constraint->sizeNotDetectedMessage, array(), $value, null, $constraint::ERROR_SIZE_NOT_DETECTED);
return;
}
@@ -63,7 +63,7 @@ public function validate($value, Constraint $constraint)
$this->context->addViolation($constraint->minWidthMessage, array(
'{{ width }}' => $width,
'{{ min_width }}' => $constraint->minWidth
- ));
+ ), $value, null, $constraint::ERROR_MIN_WIDTH);
return;
}
@@ -78,7 +78,7 @@ public function validate($value, Constraint $constraint)
$this->context->addViolation($constraint->maxWidthMessage, array(
'{{ width }}' => $width,
'{{ max_width }}' => $constraint->maxWidth
- ));
+ ), $value, null, $constraint::ERROR_MAX_WIDTH);
return;
}
@@ -93,7 +93,7 @@ public function validate($value, Constraint $constraint)
$this->context->addViolation($constraint->minHeightMessage, array(
'{{ height }}' => $height,
'{{ min_height }}' => $constraint->minHeight
- ));
+ ), $value, null, $constraint::ERROR_MIN_HEIGHT);
return;
}
@@ -108,7 +108,7 @@ public function validate($value, Constraint $constraint)
$this->context->addViolation($constraint->maxHeightMessage, array(
'{{ height }}' => $height,
'{{ max_height }}' => $constraint->maxHeight
- ));
+ ), $value, null, $constraint::ERROR_MAX_HEIGHT);
}
}
@@ -123,7 +123,7 @@ public function validate($value, Constraint $constraint)
$this->context->addViolation($constraint->minRatioMessage, array(
'{{ ratio }}' => $ratio,
'{{ min_ratio }}' => $constraint->minRatio
- ));
+ ), $value, null, $constraint::ERROR_MIN_RATIO);
}
}
@@ -136,7 +136,7 @@ public function validate($value, Constraint $constraint)
$this->context->addViolation($constraint->maxRatioMessage, array(
'{{ ratio }}' => $ratio,
'{{ max_ratio }}' => $constraint->maxRatio
- ));
+ ), $value, null, $constraint::ERROR_MAX_RATIO);
}
}
@@ -144,21 +144,21 @@ public function validate($value, Constraint $constraint)
$this->context->addViolation($constraint->allowSquareMessage, array(
'{{ width }}' => $width,
'{{ height }}' => $height
- ));
+ ), $value, null, $constraint::ERROR_DONT_ALLOW_SQUARE);
}
if (!$constraint->allowLandscape && $width > $height) {
$this->context->addViolation($constraint->allowLandscapeMessage, array(
'{{ width }}' => $width,
'{{ height }}' => $height
- ));
+ ), $value, null, $constraint::ERROR_DONT_ALLOW_LANDSCAPE);
}
if (!$constraint->allowPortrait && $width < $height) {
$this->context->addViolation($constraint->allowPortraitMessage, array(
'{{ width }}' => $width,
'{{ height }}' => $height
- ));
+ ), $value, null, $constraint::ERROR_DONT_ALLOW_PORTRAIT);
}
}
View
2  src/Symfony/Component/Validator/Constraints/Ip.php
@@ -26,6 +26,8 @@
*/
class Ip extends Constraint
{
+ const ERROR = '77436b41-d7f5-4793-8e67-cd5e5d3722a1';
+
const V4 = '4';
const V6 = '6';
const ALL = 'all';
View
2  src/Symfony/Component/Validator/Constraints/IpValidator.php
@@ -91,7 +91,7 @@ public function validate($value, Constraint $constraint)
}
if (!filter_var($value, FILTER_VALIDATE_IP, $flag)) {
- $this->context->addViolation($constraint->message, array('{{ value }}' => $value));
+ $this->context->addViolation($constraint->message, array('{{ value }}' => $value), $value, null, $constraint::ERROR);
}
}
}
View
4 src/Symfony/Component/Validator/Constraints/Isbn.php
@@ -21,6 +21,10 @@
*/
class Isbn extends Constraint
{
+ const ERROR = 'af6f41b0-3626-4b78-96a3-a6027832d1cb';
+ const ERROR_ISBN10 = '7665fcb0-e6bf-4d31-8159-f9cf713bae5f';
+ const ERROR_ISBN13 = '6aa1c63f-c281-4741-bb12-d8505011414f';
+
public $isbn10Message = 'This value is not a valid ISBN-10.';
public $isbn13Message = 'This value is not a valid ISBN-13.';
public $bothIsbnMessage = 'This value is neither a valid ISBN-10 nor a valid ISBN-13.';
View
31 src/Symfony/Component/Validator/Constraints/IsbnValidator.php
@@ -37,52 +37,53 @@ public function validate($value, Constraint $constraint)
throw new UnexpectedTypeException($value, 'string');
}
- if (!is_numeric($value)) {
- $value = str_replace('-', '', $value);
+ $isbn = strtoupper($value);
+
+ if (!is_numeric($isbn)) {
+ $isbn = str_replace('-', '', $isbn);
}
$validation = 0;
- $value = strtoupper($value);
- $valueLength = strlen($value);
+ $valueLength = strlen($isbn);
if (10 === $valueLength && null !== $constraint->isbn10) {
for ($i = 0; $i < 10; $i++) {
- if ($value[$i] == 'X') {
+ if ($isbn[$i] == 'X') {
$validation += 10 * intval(10 - $i);
} else {
- $validation += intval($value[$i]) * intval(10 - $i);
+ $validation += intval($isbn[$i]) * intval(10 - $i);
}
}
if ($validation % 11 != 0) {
if (null !== $constraint->isbn13) {
- $this->context->addViolation($constraint->bothIsbnMessage);
+ $this->context->addViolation($constraint->bothIsbnMessage, array('{{ value }}' => $value), $value, null, $constraint::ERROR);
} else {
- $this->context->addViolation($constraint->isbn10Message);
+ $this->context->addViolation($constraint->isbn10Message, array('{{ value }}' => $value), $value, null, $constraint::ERROR_ISBN10);
}
}
} elseif (13 === $valueLength && null !== $constraint->isbn13) {
for ($i = 0; $i < 13; $i += 2) {
- $validation += intval($value[$i]);
+ $validation += intval($isbn[$i]);
}
for ($i = 1; $i < 12; $i += 2) {
- $validation += intval($value[$i]) * 3;
+ $validation += intval($isbn[$i]) * 3;
}
if ($validation % 10 != 0) {
if (null !== $constraint->isbn10) {
- $this->context->addViolation($constraint->bothIsbnMessage);
+ $this->context->addViolation($constraint->bothIsbnMessage, array('{{ value }}' => $value), $value, null, $constraint::ERROR);
} else {
- $this->context->addViolation($constraint->isbn13Message);
+ $this->context->addViolation($constraint->isbn13Message, array('{{ value }}' => $value), $value, null, $constraint::ERROR_ISBN13);
}
}
} else {
if (null !== $constraint->isbn10 && null !== $constraint->isbn13) {
- $this->context->addViolation($constraint->bothIsbnMessage);
+ $this->context->addViolation($constraint->bothIsbnMessage, array('{{ value }}' => $value), $value, null, $constraint::ERROR);
} elseif (null !== $constraint->isbn10) {
- $this->context->addViolation($constraint->isbn10Message);
+ $this->context->addViolation($constraint->isbn10Message, array('{{ value }}' => $value), $value, null, $constraint::ERROR_ISBN10);
} else {
- $this->context->addViolation($constraint->isbn13Message);
+ $this->context->addViolation($constraint->isbn13Message, array('{{ value }}' => $value), $value, null, $constraint::ERROR_ISBN13);
}
}
}
View
2  src/Symfony/Component/Validator/Constraints/Issn.php
@@ -20,6 +20,8 @@
*/
class Issn extends Constraint
{
+ const ERROR = '3e3590ed-7890-4ccf-8d62-12b4966d0a39';
+
public $message = 'This value is not a valid ISSN.';
public $caseSensitive = false;
public $requireHyphen = false;
View
4 src/Symfony/Component/Validator/Constraints/IssnValidator.php
@@ -43,7 +43,7 @@ public function validate($value, Constraint $constraint)
$pattern = "/^".$digitsPattern.$checksumPattern."$/";
if (!preg_match($pattern, $value)) {
- $this->context->addViolation($constraint->message);
+ $this->context->addViolation($constraint->message, array('{{ value }}' => $value), $value, null, $constraint::ERROR);
} else {
$digits = str_split(strtoupper(str_replace('-', '', $value)));
@@ -55,7 +55,7 @@ public function validate($value, Constraint $constraint)
$checksum = 'X' == reset($digits) ? 10 : (int) reset($digits);
if (0 != ($sum + $checksum) % 11) {
- $this->context->addViolation($constraint->message);
+ $this->context->addViolation($constraint->message, array('{{ value }}' => $value), $value, null, $constraint::ERROR);
}
}
}
View
2  src/Symfony/Component/Validator/Constraints/Language.php
@@ -22,5 +22,7 @@
*/
class Language extends Constraint
{
+ const ERROR = 'eb2120ee-6f0d-4fa8-9e63-79af6289bda6';
+
public $message = 'This value is not a valid language.';
}
View
2  src/Symfony/Component/Validator/Constraints/LanguageValidator.php
@@ -42,7 +42,7 @@ public function validate($value, Constraint $constraint)
$languages = Intl::getLanguageBundle()->getLanguageNames();
if (!isset($languages[$value])) {
- $this->context->addViolation($constraint->message, array('{{ value }}' => $value));
+ $this->context->addViolation($constraint->message, array('{{ value }}' => $value), $value, null, $constraint::ERROR);
}
}
}
View
4 src/Symfony/Component/Validator/Constraints/Length.php
@@ -23,6 +23,10 @@
*/
class Length extends Constraint
{
+ const ERROR = 'cca1a7c3-beed-44c8-a12c-dd94e6208631';
+ const ERROR_MAX = '2127fa68-8220-4d66-bdbd-6c9e12c4e529';
+ const ERROR_MIN = '7ec9200c-b68d-4aff-b29f-d546912ed243';
+
public $maxMessage = 'This value is too long. It should have {{ limit }} character or less.|This value is too long. It should have {{ limit }} characters or less.';
public $minMessage = 'This value is too short. It should have {{ limit }} character or more.|This value is too short. It should have {{ limit }} characters or more.';
public $exactMessage = 'This value should have exactly {{ limit }} character.|This value should have exactly {{ limit }} characters.';
View
6 src/Symfony/Component/Validator/Constraints/LengthValidator.php
@@ -47,7 +47,7 @@ public function validate($value, Constraint $constraint)
$this->context->addViolation($constraint->exactMessage, array(
'{{ value }}' => $stringValue,
'{{ limit }}' => $constraint->min,
- ), $value, (int) $constraint->min);
+ ), $value, (int) $constraint->min, $constraint::ERROR);
return;
}
@@ -56,7 +56,7 @@ public function validate($value, Constraint $constraint)
$this->context->addViolation($constraint->maxMessage, array(
'{{ value }}' => $stringValue,
'{{ limit }}' => $constraint->max,
- ), $value, (int) $constraint->max);
+ ), $value, (int) $constraint->max, $constraint::ERROR_MAX);
return;
}
@@ -65,7 +65,7 @@ public function validate($value, Constraint $constraint)
$this->context->addViolation($constraint->minMessage, array(
'{{ value }}' => $stringValue,
'{{ limit }}' => $constraint->min,
- ), $value, (int) $constraint->min);
+ ), $value, (int) $constraint->min, $constraint::ERROR_MIN);
}
}
}
View
2  src/Symfony/Component/Validator/Constraints/LessThan.php
@@ -18,5 +18,7 @@
*/
class LessThan extends AbstractComparison
{
+ const ERROR = '16a4f865-0060-40e9-9d60-8ab113bfb293';
+
public $message = 'This value should be less than {{ compared_value }}.';
}
View
2  src/Symfony/Component/Validator/Constraints/LessThanOrEqual.php
@@ -18,5 +18,7 @@
*/
class LessThanOrEqual extends AbstractComparison
{
+ const ERROR = '8bb5f334-d139-4821-ad09-00c63d55b5a8';
+
public $message = 'This value should be less than or equal to {{ compared_value }}.';
}
View
2  src/Symfony/Component/Validator/Constraints/Locale.php
@@ -22,5 +22,7 @@
*/
class Locale extends Constraint
{
+ const ERROR = 'ccf90455-5e51-47d9-a927-61a31dc4338c';
+
public $message = 'This value is not a valid locale.';
}
View
2  src/Symfony/Component/Validator/Constraints/LocaleValidator.php
@@ -42,7 +42,7 @@ public function validate($value, Constraint $constraint)
$locales = Intl::getLocaleBundle()->getLocaleNames();
if (!isset($locales[$value])) {
- $this->context->addViolation($constraint->message, array('{{ value }}' => $value));
+ $this->context->addViolation($constraint->message, array('{{ value }}' => $value), $value, null, $constraint::ERROR);
}
}
}
View
2  src/Symfony/Component/Validator/Constraints/Luhn.php
@@ -20,5 +20,7 @@
*/
class Luhn extends Constraint
{
+ const ERROR = 'e146c87e-3063-47ad-bde0-37cd2f5f117b';
+
public $message = 'Invalid card number.';
}
View
4 src/Symfony/Component/Validator/Constraints/LuhnValidator.php
@@ -39,7 +39,7 @@ public function validate($value, Constraint $constraint)
}
if (!is_numeric($value)) {
- $this->context->addViolation($constraint->message);
+ $this->context->addViolation($constraint->message, array('{{ value }}' => $value), $value, null, $constraint::ERROR);
return;
}
@@ -52,7 +52,7 @@ public function validate($value, Constraint $constraint)
}
if ($sum === 0 || ($sum % 10) !== 0) {
- $this->context->addViolation($constraint->message);
+ $this->context->addViolation($constraint->message, array('{{ value }}' => $value), $value, null, $constraint::ERROR);
}
}
}
View
2  src/Symfony/Component/Validator/Constraints/NotBlank.php
@@ -22,5 +22,7 @@
*/
class NotBlank extends Constraint
{
+ const ERROR = 'ca626403-7b11-487f-9dfb-c177a9040ce7';
+
public $message = 'This value should not be blank.';
}
View
2  src/Symfony/Component/Validator/Constraints/NotBlankValidator.php
@@ -27,7 +27,7 @@ class NotBlankValidator extends ConstraintValidator
public function validate($value, Constraint $constraint)
{
if (false === $value || (empty($value) && '0' != $value)) {
- $this->context->addViolation($constraint->message);
+ $this->context->addViolation($constraint->message, array(), $value, null, $constraint::ERROR);
}
}
}
View
2  src/Symfony/Component/Validator/Constraints/NotEqualTo.php
@@ -18,5 +18,7 @@
*/
class NotEqualTo extends AbstractComparison
{
+ const ERROR = 'fc9de329-a897-45c9-8fea-83ea2d1c8aed';
+
public $message = 'This value should not be equal to {{ compared_value }}.';
}
View
2  src/Symfony/Component/Validator/Constraints/NotIdenticalTo.php
@@ -18,5 +18,7 @@
*/
class NotIdenticalTo extends AbstractComparison
{
+ const ERROR = '2c96e376-8e6f-488c-9936-840a73fd3163';
+
public $message = 'This value should not be identical to {{ compared_value_type }} {{ compared_value }}.';
}
View
2  src/Symfony/Component/Validator/Constraints/NotNull.php
@@ -22,5 +22,7 @@
*/
class NotNull extends Constraint
{
+ const ERROR = '80ab39d6-9e19-4191-afd9-03aab806e7b8';
+
public $message = 'This value should not be null.';
}
View
2  src/Symfony/Component/Validator/Constraints/NotNullValidator.php
@@ -27,7 +27,7 @@ class NotNullValidator extends ConstraintValidator
public function validate($value, Constraint $constraint)
{
if (null === $value) {
- $this->context->addViolation($constraint->message);
+ $this->context->addViolation($constraint->message, array(), $value, null, $constraint::ERROR);
}
}
}
View
2  src/Symfony/Component/Validator/Constraints/Null.php
@@ -22,5 +22,7 @@
*/
class Null extends Constraint
{
+ const ERROR = '05b25fe2-0bfa-4ba3-b0aa-2491f80840a9';
+
public $message = 'This value should be null.';
}
View
2  src/Symfony/Component/Validator/Constraints/NullValidator.php
@@ -27,7 +27,7 @@ class NullValidator extends ConstraintValidator
public function validate($value, Constraint $constraint)
{
if (null !== $value) {
- $this->context->addViolation($constraint->message, array('{{ value }}' => $value));
+ $this->context->addViolation($constraint->message, array('{{ value }}' => $value), $value, null, $constraint::ERROR);
}
}
}
View
4 src/Symfony/Component/Validator/Constraints/Range.php
@@ -23,6 +23,10 @@
*/
class Range extends Constraint
{
+ const ERROR = 'bc619de0-7f99-4d29-b5cb-f93bce9f6274';
+ const ERROR_MIN = '0be45eb8-3d65-452b-9cbe-3b398c5c08c7';
+ const ERROR_MAX = 'ac98b917-6b0a-4bea-8bac-e937064d3b42';
+
public $minMessage = 'This value should be {{ limit }} or more.';
public $maxMessage = 'This value should be {{ limit }} or less.';
public $invalidMessage = 'This value should be a valid number.';
View
6 src/Symfony/Component/Validator/Constraints/RangeValidator.php
@@ -31,7 +31,7 @@ public function validate($value, Constraint $constraint)
if (!is_numeric($value)) {
$this->context->addViolation($constraint->invalidMessage, array(
'{{ value }}' => $value,
- ));
+ ), $value, null, $constraint::ERROR);
return;
}
@@ -40,7 +40,7 @@ public function validate($value, Constraint $constraint)
$this->context->addViolation($constraint->maxMessage, array(
'{{ value }}' => $value,
'{{ limit }}' => $constraint->max,
- ));
+ ), $value, null, $constraint::ERROR_MAX);
return;
}
@@ -49,7 +49,7 @@ public function validate($value, Constraint $constraint)
$this->context->addViolation($constraint->minMessage, array(
'{{ value }}' => $value,
'{{ limit }}' => $constraint->min,
- ));
+ ), $value, null, $constraint::ERROR_MIN);
}
}
}
View
2  src/Symfony/Component/Validator/Constraints/Regex.php
@@ -22,6 +22,8 @@
*/
class Regex extends Constraint
{
+ const ERROR = '3feb30b5-8882-4179-bf27-81155fcc71fc';
+
public $message = 'This value is not valid.';
public $pattern;
public $htmlPattern = null;
View
2  src/Symfony/Component/Validator/Constraints/RegexValidator.php
@@ -41,7 +41,7 @@ public function validate($value, Constraint $constraint)
$value = (string) $value;
if ($constraint->match xor preg_match($constraint->pattern, $value)) {
- $this->context->addViolation($constraint->message, array('{{ value }}' => $value));
+ $this->context->addViolation($constraint->message, array('{{ value }}' => $value), $value, null, $constraint::ERROR);
}
}
}
View
2  src/Symfony/Component/Validator/Constraints/Time.php
@@ -22,5 +22,7 @@
*/
class Time extends Constraint
{
+ const ERROR = 'a487eb1b-b785-49e0-97d8-b3eb6a165185';
+
public $message = 'This value is not a valid time.';
}
View
2  src/Symfony/Component/Validator/Constraints/TimeValidator.php
@@ -40,7 +40,7 @@ public function validate($value, Constraint $constraint)
$value = (string) $value;
if (!preg_match(static::PATTERN, $value)) {
- $this->context->addViolation($constraint->message, array('{{ value }}' => $value));
+ $this->context->addViolation($constraint->message, array('{{ value }}' => $value), $value, null, $constraint::ERROR);
}
}
}
View
2  src/Symfony/Component/Validator/Constraints/True.php
@@ -22,5 +22,7 @@
*/
class True extends Constraint
{
+ const ERROR = '36f92ba4-67e3-4e0b-a5ca-fe819568ed0d';
+
public $message = 'This value should be true.';
}
View
2  src/Symfony/Component/Validator/Constraints/TrueValidator.php
@@ -31,7 +31,7 @@ public function validate($value, Constraint $constraint)
}
if (true !== $value && 1 !== $value && '1' !== $value) {
- $this->context->addViolation($constraint->message);
+ $this->context->addViolation($constraint->message, array(), $value, null, $constraint::ERROR);
}
}
}
View
2  src/Symfony/Component/Validator/Constraints/Type.php
@@ -22,6 +22,8 @@
*/
class Type extends Constraint
{
+ const ERROR = 'f42711f9-d10d-4272-9b1c-76de264f642c';
+
public $message = 'This value should be of type {{ type }}.';
public $type;
View
2  src/Symfony/Component/Validator/Constraints/TypeValidator.php
@@ -46,6 +46,6 @@ public function validate($value, Constraint $constraint)
$this->context->addViolation($constraint->message, array(
'{{ value }}' => is_object($value) ? get_class($value) : (is_array($value) ? 'Array' : (string) $value),
'{{ type }}' => $constraint->type,
- ));
+ ), $value, null, $constraint::ERROR);
}
}
View
2  src/Symfony/Component/Validator/Constraints/Url.php
@@ -22,6 +22,8 @@
*/
class Url extends Constraint
{
+ const ERROR = '23af3103-a5ca-4459-b0ae-3a2043479a98';
+
public $message = 'This value is not a valid URL.';
public $protocols = array('http', 'https');
}
View
2  src/Symfony/Component/Validator/Constraints/UrlValidator.php
@@ -55,7 +55,7 @@ public function validate($value, Constraint $constraint)
$pattern = sprintf(static::PATTERN, implode('|', $constraint->protocols));
if (!preg_match($pattern, $value)) {
- $this->context->addViolation($constraint->message, array('{{ value }}' => $value));
+ $this->context->addViolation($constraint->message, array('{{ value }}' => $value), $value, null, $constraint::ERROR);
}
}
}
View
4 src/Symfony/Component/Validator/ExecutionContextInterface.php
@@ -92,7 +92,7 @@
* @param array $params The parameters substituted in the error message.
* @param mixed $invalidValue The invalid, validated value.
* @param integer|null $pluralization The number to use to pluralize of the message.
- * @param integer|null $code The violation code.
+ * @param mixed $code The violation code.
*
* @api
*/
@@ -107,7 +107,7 @@ public function addViolation($message, array $params = array(), $invalidValue =
* @param array $params The parameters substituted in the error message.
* @param mixed $invalidValue The invalid, validated value.
* @param integer|null $pluralization The number to use to pluralize of the message.
- * @param integer|null $code The violation code.
+ * @param mixed $code The violation code.
*
* @api
*/
View
2  src/Symfony/Component/Validator/Tests/Constraints/AbstractComparisonValidatorTestCase.php
@@ -105,7 +105,7 @@ public function testInvalidComparisonToValue($dirtyValue, $comparedValue, $compa
'{{ value }}' => $comparedValueString,
'{{ compared_value }}' => $comparedValueString,
'{{ compared_value_type }}' => $comparedValueType
- ));
+ ), $comparedValue, null, $constraint::ERROR);
$this->validator->validate($dirtyValue, $constraint);
}
View
2  src/Symfony/Component/Validator/Tests/Constraints/BlankValidatorTest.php
@@ -61,7 +61,7 @@ public function testInvalidValues($value)
->method('addViolation')
->with('myMessage', array(
'{{ value }}' => $value,
- ));
+ ), $this->identicalTo($value), null, Blank::ERROR);
$this->validator->validate($value, $constraint);
}
View
10 src/Symfony/Component/Validator/Tests/Constraints/CardSchemeValidatorTest.php
@@ -64,10 +64,16 @@ public function testValidNumbers($scheme, $number)
*/
public function testInvalidNumbers($scheme, $number)
{
+ $constraint = new CardScheme(array(
+ 'schemes' => $scheme,
+ 'message' => 'myMessage'
+ ));
+
$this->context->expects($this->once())
- ->method('addViolation');
+ ->method('addViolation')
+ ->with('myMessage', array(), $this->identicalTo($number), null, CardScheme::ERROR);
- $this->validator->validate($number, new CardScheme(array('schemes' => $scheme)));
+ $this->validator->validate($number, $constraint);
}
public function getValidNumbers()
View
18 src/Symfony/Component/Validator/Tests/Constraints/ChoiceValidatorTest.php
@@ -14,7 +14,7 @@
use Symfony\Component\Validator\Constraints\Choice;
use Symfony\Component\Validator\Constraints\ChoiceValidator;
-function choice_callback()
+function choiceCallback()
{
return array('foo', 'bar');
}
@@ -95,7 +95,7 @@ public function testValidChoiceArray()
public function testValidChoiceCallbackFunction()
{
- $constraint = new Choice(array('callback' => __NAMESPACE__.'\choice_callback'));
+ $constraint = new Choice(array('callback' => __NAMESPACE__.'\choiceCallback'));
$this->context->expects($this->never())
->method('addViolation');
@@ -105,7 +105,7 @@ public function testValidChoiceCallbackFunction()
public function testValidChoiceCallbackClosure()
{
- $constraint = new Choice(array('callback' => function() {
+ $constraint = new Choice(array('callback' => function () {
return array('foo', 'bar');
}));
@@ -159,7 +159,7 @@ public function testInvalidChoice()
->method('addViolation')
->with('myMessage', array(
'{{ value }}' => 'baz',
- ), null, null);
+ ), $this->identicalTo('baz'), null, Choice::ERROR);
$this->validator->validate('baz', $constraint);
}
@@ -176,7 +176,7 @@ public function testInvalidChoiceMultiple()
->method('addViolation')
->with('myMessage', array(
'{{ value }}' => 'baz',
- ));
+ ), $this->identicalTo('baz'), null, Choice::ERROR_MULTIPLE);
$this->validator->validate(array('foo', 'baz'), $constraint);
}
@@ -194,7 +194,7 @@ public function testTooFewChoices()
->method('addViolation')
->with('myMessage', array(
'{{ limit }}' => 2,
- ), null, 2);
+ ), null, 2, Choice::ERROR_MIN);
$this->validator->validate(array('foo'), $constraint);
}
@@ -212,7 +212,7 @@ public function testTooManyChoices()
->method('addViolation')
->with('myMessage', array(
'{{ limit }}' => 2,
- ), null, 2);
+ ), null, 2, Choice::ERROR_MAX);
$this->validator->validate(array('foo', 'bar', 'moo'), $constraint);
}
@@ -256,7 +256,7 @@ public function testStrictDisallowsDifferentType()
->method('addViolation')
->with('myMessage', array(
'{{ value }}' => '2',
- ));
+ ), $this->identicalTo('2'), null, Choice::ERROR);
$this->validator->validate('2', $constraint);
}
@@ -288,7 +288,7 @@ public function testStrictWithMultipleChoices()
->method('addViolation')
->with('myMessage', array(
'{{ value }}' => '3',
- ));
+ ), $this->identicalTo('3'), null, Choice::ERROR_MULTIPLE);
$this->validator->validate(array(2, '3'), $constraint);
}
View
6 src/Symfony/Component/Validator/Tests/Constraints/CollectionValidatorTest.php
@@ -148,7 +148,7 @@ public function testExtraFieldsDisallowed()
->method('addViolationAt')
->with('[baz]', 'myMessage', array(
'{{ field }}' => 'baz'
- ));
+ ), 'baz', null, Collection::ERROR_EXTRA_FIELD);
$this->validator->validate($data, new Collection(array(
'fields' => array(
@@ -212,7 +212,7 @@ public function testMissingFieldsDisallowed()
->method('addViolationAt')
->with('[foo]', 'myMessage', array(
'{{ field }}' => 'foo',
- ));
+ ), 'foo', Collection::ERROR_MISSING_FIELD);
$this->validator->validate($data, $constraint);
}
@@ -332,7 +332,7 @@ public function testRequiredFieldNotPresent()
->method('addViolationAt')
->with('[foo]', 'myMessage', array(
'{{ field }}' => 'foo',
- ));
+ ), 'foo', Collection::ERROR_MISSING_FIELD);
$this->validator->validate($data, new Collection(array(
'fields' => array(
View
6 src/Symfony/Component/Validator/Tests/Constraints/CountValidatorTest.php
@@ -139,7 +139,7 @@ public function testInvalidValuesMax($value)
->with('myMessage', $this->identicalTo(array(
'{{ count }}' => count($value),
'{{ limit }}' => 4,
- )), $value, 4);
+ )), $value, 4, Count::ERROR_MAX);
$this->validator->validate($value, $constraint);
}
@@ -159,7 +159,7 @@ public function testInvalidValuesMin($value)
->with('myMessage', $this->identicalTo(array(
'{{ count }}' => count($value),
'{{ limit }}' => 4,
- )), $value, 4);
+ )), $value, 4, Count::ERROR_MIN);
$this->validator->validate($value, $constraint);
}
@@ -180,7 +180,7 @@ public function testInvalidValuesExact($value)
->with('myMessage', $this->identicalTo(array(
'{{ count }}' => count($value),
'{{ limit }}' => 4,
- )), $value, 4);
+ )), $value, 4, Count::ERROR_EXACT);
$this->validator->validate($value, $constraint);
}
View
2  src/Symfony/Component/Validator/Tests/Constraints/CountryValidatorTest.php
@@ -92,7 +92,7 @@ public function testInvalidCountries($country)
->method('addViolation')
->with('myMessage', array(
'{{ value }}' => $country,
- ));
+ ), $country, Country::ERROR);
$this->validator->validate($country, $constraint);
}
View
2  src/Symfony/Component/Validator/Tests/Constraints/CurrencyValidatorTest.php
@@ -94,7 +94,7 @@ public function testInvalidCurrencies($currency)
->method('addViolation')
->with('myMessage', array(
'{{ value }}' => $currency,
- ));
+ ), $currency, null, Currency::ERROR);
$this->validator->validate($currency, $constraint);
}
View
2  src/Symfony/Component/Validator/Tests/Constraints/DateTimeValidatorTest.php
@@ -97,7 +97,7 @@ public function testInvalidDateTimes($dateTime)
->method('addViolation')
->with('myMessage', array(
'{{ value }}' => $dateTime,
- ));
+ ), $dateTime, null, DateTime::ERROR);
$this->validator->validate($dateTime, $constraint);
}