-
-
Notifications
You must be signed in to change notification settings - Fork 562
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
Validation messages translation #800
Validation messages translation #800
Conversation
Can you add a test to ensure overwriting |
Do you mean for DocumentValidator? |
Yeah. Basically what you wrote in the description:
|
Could you please give me an example how I can do it? |
{ | ||
public function getName() | ||
{ | ||
return (new ValuesOfCorrectType())->getName(); |
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.
Why is this function overwritten at all?
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.
Because getName()
used by DocumentValidator::addRule()
and we want to replace ValuesOfCorrectType
completely.
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.
And the default realization of getName()
uses static::class
graphql-php/src/Validator/Rules/ValidationRule.php
Lines 16 to 19 in 65428ce
public function getName() | |
{ | |
return $this->name === '' || $this->name === null ? static::class : $this->name; | |
} |
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.
That seems like an annoying gotcha for users that extend this class.
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.
🤷♂️ Maybe something like?
class ValuesOfCorrectType extends ValidationRule
{
// (1)
/** @var string */
protected $name = self::class;
// (2) or this (probably a breaking change)
public function __construct() {
$this->name = self::class;
}
Thanks for this POC, I will make sure this way of overwriting rules keeps working - see graphql-php/tests/Validator/CustomRuleTest.php Lines 19 to 55 in a5d64c7
|
Probably the most simple solution :)
And in AppServiceProvider:
Voila
Closes #711, overrides #713 and #718