-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Validator] Allow objects implementing __toString() to be used as violation messages #31083
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
Conversation
src/Symfony/Component/Validator/ConstraintViolationInterface.php
Outdated
Show resolved
Hide resolved
@michaelcullum and I talked a bit around this issue and whether or not we should be pushing for a Stringable pseudo-class in PHP - there are prior discussions - see https://externals.io/message/98424 |
I am 👎 on making this change as it calls for breaking existing code that do not perform explicit string casts on the returned value of |
@nicolas-grekas none of them are particularly pretty - https://www.drupal.org/project/drupal/issues/3029540 - we've explored quite a few there. |
does the issue affect drupal users directly? (if not i think drupal core should just patch) e.g. symfony/src/Symfony/Component/Validator/Context/ExecutionContextInterface.php Lines 67 to 70 in 59c08ed
is the issue drupal users do |
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.
We have to do this change. Let's be friendly to our users. It's the only pragmatic move.
Here are some CS changes before approving on my side.
src/Symfony/Component/Validator/ConstraintViolationInterface.php
Outdated
Show resolved
Hide resolved
(please rebase also, on branch 4.4) |
note in 5.0 there are more typehints that could be blocking still;
|
@ro0NL thanks, then let's add |
59c08ed
to
58424ea
Compare
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.
please have a look at tests :)
src/Symfony/Component/Validator/Violation/ConstraintViolationBuilder.php
Show resolved
Hide resolved
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.
Good on my side (just one very minor CS comment)
Thanks for being so reactive.
src/Symfony/Component/Validator/Violation/ConstraintViolationBuilder.php
Show resolved
Hide resolved
(rebase needed) |
…lation messages [Validator] updated changelog [Validator] updated typehint for ConstraintViolationInterface::getMessage() [Validator] fixed spacing issue inadvertantly added in previous commit [Validator] fixed coding standard issues [Validator] Address feedback [Validator] Fix coding standard violation [Validator] update tests [Validator] Address feedback, Round 2 [Validator] Document ConstraintViolationBuilder::__construct() parameter [Validator] Update changelog [Validator] Adjust parameter documentation order
a0da99d
to
79f4dcd
Compare
Rebased and squashed |
Thank you @mdlutz24. |
… be used as violation messages (mdlutz24) This PR was merged into the 4.4 branch. Discussion ---------- [Validator] Allow objects implementing __toString() to be used as violation messages | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | I didn't see a doc on violations to update, but I'm happy to do documentation if somone can suggest the best place to do it. Currently in the Drupal project we use Translatable Markup object to hold most strings and currently pass them in as Constraint Violation messages. In Symfony 3 this works but with the added typehinting in Symfony 4, these markup objects are rendered into strings at the time of the violation creation. This causes any html in the message string to be considered unsafe by twig later in our rendering process. This pr explicitly allows objects implementing a __toString() method to be used as violation messages, and the violation will save and return the original stringable object. See https://www.drupal.org/project/drupal/issues/3029540 For our Drupal issue on the subject. Commits ------- 79f4dcd [Validator] Allow objects implementing __toString() to be used as violation messages
Currently in the Drupal project we use Translatable Markup object to hold most strings and currently pass them in as Constraint Violation messages. In Symfony 3 this works but with the added typehinting in Symfony 4, these markup objects are rendered into strings at the time of the violation creation. This causes any html in the message string to be considered unsafe by twig later in our rendering process. This pr explicitly allows objects implementing a __toString() method to be used as violation messages, and the violation will save and return the original stringable object.
See https://www.drupal.org/project/drupal/issues/3029540 For our Drupal issue on the subject.