-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Validator] Refactored the Validator for use in Drupal #6096
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
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
[Validator] Refactored the GraphWalker into an implementation of the …
…Visitor design pattern. With this refactoring comes a decoupling of the validator from the structure of the underlying metadata. This way it is possible for Drupal to use the validator for validating their Entity API by using their own metadata layer, which is not modeled as classes and properties/getter methods.
- Loading branch information
commit efe42cbb1f284b992d8de9f136c3b20848bee7f9
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package 9E19 . | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Validator; | ||
|
||
/** | ||
* An object backed by a PHP class. | ||
* | ||
* @author Bernhard Schussek <bschussek@gmail.com> | ||
*/ | ||
interface ClassBasedInterface | ||
{ | ||
/** | ||
* Returns the name of the backing PHP class. | ||
* | ||
* @return string The name of the backing class. | ||
*/ | ||
public function getClassName(); | ||
} |
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
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
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
136 changes: 136 additions & 0 deletions
136
src/Symfony/Component/Validator/ConstraintViolationInterface.php
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Validator; | ||
|
||
/** | ||
* A violation of a constraint that happened during validation. | ||
* | ||
* For each constraint that fails during validation one or more violations are | ||
* created. The violations store the violation message, the path to the failing | ||
* element in the validation graph and the root element that was originally | ||
* passed to the validator. For example, take the following graph: | ||
* | ||
* <pre> | ||
* (Person)---(firstName: string) | ||
* \ | ||
* (address: Address)---(street: string) | ||
* </pre> | ||
* | ||
* If the <tt>Person</tt> object is validated and validation fails for the | ||
* "firstName" property, the generated violation has the <tt>Person</tt> | ||
* instance as root and the property path "firstName". If validation fails | ||
* for the "street" property of the related <tt>Address</tt> instance, the root | ||
* element is still the person, but the property path is "address.street". | ||
* | ||
* @author Bernhard Schussek <bschussek@gmail.com> | ||
* | ||
* @api | ||
*/ | ||
interface ConstraintViolationInterface | ||
{ | ||
/** | ||
* Returns the violation message. | ||
* | ||
* @return string The violation message. | ||
* | ||
* @api | ||
*/ | ||
public function getMessage(); | ||
|
||
/** | ||
* Returns the raw violation message. | ||
* | ||
* The raw violation message contains placeholders for the parameters | ||
* returned by {@link getMessageParameters}. Typically you'll pass the | ||
* message template and parameters to a translation engine. | ||
* | ||
* @return string The raw violation message. | ||
* | ||
* @api | ||
*/ | ||
public function getMessageTemplate(); | ||
|
||
/** | ||
* Returns the parameters to be inserted into the raw violation message. | ||
* | ||
* @return array A possibly empty list of parameters indexed by the names | ||
* that appear in the message template. | ||
* | ||
* @see getMessageTemplate | ||
* | ||
* @api | ||
*/ | ||
public function getMessageParameters(); | ||
|
||
/** | ||
* Returns a number for pluralizing the violation message. | ||
* | ||
* For example, the message template could have different translation based | ||
* on a parameter "choices": | ||
* | ||
* <ul> | ||
* <li>Please select exactly one entry. (choices=1)</li> | ||
* <li>Please select two entries. (choices=2)</li> | ||
* </ul> | ||
* | ||
* This method returns the value of the parameter for choosing the right | ||
* pluralization form (in this case "choices"). | ||
* | ||
* @return integer|null The number to use to pluralize of the message. | ||
*/ | ||
public function getMessagePluralization(); | ||
|
||
/** | ||
* Returns the root element of the validation. | ||
* | ||
* @return mixed The value that was passed originally to the validator when | ||
* the validation was started. Because the validator traverses | ||
* the object graph, the value at which the violation occurs | ||
* is not necessarily the value that was originally validated. | ||
* | ||
* @api | ||
*/ | ||
public function getRoot(); | ||
|
||
/** | ||
* Returns the property path from the root element to the violation. | ||
* | ||
* @return string The property path indicates how the validator reached | ||
* the invalid value from the root element. If the root | ||
* element is a <tt>Person</tt> instance with a property | ||
* "address" that contains an <tt>Address</tt> instance | ||
* with an invalid property "street", the generated property | ||
* path is "address.street". Property access is denoted by | ||
* dots, while array access is denoted by square brackets, | ||
* for example "addresses[1].street". | ||
* | ||
* @api | ||
*/ | ||
public function getPropertyPath(); | ||
|
||
/** | ||
* Returns the value that caused the violation. | ||
* | ||
* @return mixed The invalid value that caused the validated constraint to | ||
* fail. | ||
* | ||
* @api | ||
*/ | ||
public function getInvalidValue(); | ||
|
||
/** | ||
* Returns a machine-digestible error code for the violation. | ||
* | ||
* @return mixed The error code. | ||
*/ | ||
public function getCode(); | ||
} |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The real change is introducing the interface, not moving the phpdoc tag
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, also all those changes must be noted in
UPGRADE
file.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stof Do you want me to reformulate this to:
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to mention the phpdoc tag here. Mentioning the introduction of the interface is enough IMO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is very important. The tags mark our public, guaranteed API. It's really important to tell people if we change that API.