symfony/symfony — pull request #12388 by webmozart (2014-11-03 10:21:21+00:00)
Title: [Validator] Added missing error codes and turned codes into UUIDs

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

With the current implementation of error codes, checking which error occurred is unnecessarily complex:

```php
if ($violation->getConstraint() instanceof Length && Length::TOO_SHORT_ERROR === $violation->getCode()) {
// ...
}
```

Also, the code is completely missing for some constraints. This is fixed now. By using UUIDs, the check is reduced to:

```php
if (Length::TOO_SHORT_ERROR === $violation->getCode()) {
// ...
}
```

Also, APIs can simply output the error code and the name of the error without needing to point to the constraint as well.

Before:

```json
"errors": [
{
"code": "1",
"name": "TOO_SHORT_ERROR",
"message": "This value is too short. ...",
"constraint": "Symfony\Component\Validator\Constraints\Length"
}
]
```

After:

```json
"errors": [
{
"code": "9ff3fdc4-b214-49db-8718-39c315e33d45",
"name": "TOO_SHORT_ERROR",
"message": "This value is too short. ..."
}
]
```

This makes it possible to implement a service on symfony.com which looks up error codes, e.g.

symfony.com/error?code=9ff3fdc4-b214-49db-8718-39c315e33d45

Such a URL could redirect directly to the documentation of the appropriate constraint.