-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Validator] Added missing error codes and turned codes into UUIDs #15154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cb9c069
to
e873c82
Compare
e873c82
to
8874e88
Compare
👍 |
Thank you @webmozart. |
fabpot
added a commit
that referenced
this pull request
Jul 1, 2015
… into UUIDs (webmozart) This PR was merged into the 2.8 branch. Discussion ---------- [Validator] Added missing error codes and turned codes into UUIDs Reopened #12388 on the 2.8 branch. | 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 [ { "code": "1", "name": "TOO_SHORT_ERROR", "message": "This value is too short. ...", "constraint": "Symfony\\Component\\Validator\\Constraints\\Length" } ] ``` After: ```json [ { "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. We could even support user-submitted error codes which redirect to the documentation of that constraint. Commits ------- 8874e88 [Validator] Added missing error codes and turned codes into UUIDs
Merged
This was referenced Dec 8, 2015
fabpot
added a commit
that referenced
this pull request
Jul 8, 2016
…(Koc) This PR was merged into the 2.8 branch. Discussion ---------- [DoctrineBridge] added missing error code for constraint. | Q | A | ------------- | --- | Branch? | 2.8 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | wait for travis | Fixed tickets | #15154 | License | MIT | Doc PR | - Commits ------- 32cb269 [DoctrineBridge] added missing error code for constraint.
fabpot
added a commit
that referenced
this pull request
Mar 22, 2017
…straint fails. (Koc) This PR was merged into the 3.3-dev branch. Discussion ---------- [DX][Form][Validator] Add ability check if cocrete constraint fails. | Q | A | | --- | --- | | Branch? | master | | Bug fix? | no | | New feature? | yes | | BC breaks? | no | | Deprecations? | no | | Tests pass? | wait for travis | | Fixed tickets | #15154 | | License | MIT | | Doc PR | should open | Sometimes for big forms with multiple constraints we should handle some errors separately. ``` php // when using validator $constraintViolations = $validator->validate(...); if (count($constraintViolations->findByCodes(UniqueEntity::NOT_UNIQUE_ERROR))) { // display some message or send email or etc } // when using forms if (count($form->getErrors()->findByCodes(UniqueEntity::NOT_UNIQUE_ERROR))) { // display some message or send email or etc } ``` This PR add some useful methods to handle this. Before we should iterate all failed constraints using foreach. Feel free to suggest better names for new methods. Commits ------- 29a3a7e Add ability retrieve errors by their code.
3 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Reopened #12388 on the 2.8 branch.
With the current implementation of error codes, checking which error occurred is unnecessarily complex:
Also, the code is completely missing for some constraints. This is fixed now. By using UUIDs, the check is reduced to:
Also, APIs can simply output the error code and the name of the error without needing to point to the constraint as well.
Before:
After:
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. We could even support user-submitted error codes which redirect to the documentation of that constraint.