Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Validator] AddTimezoneValidator#22262
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
TimeZoneValidatorTimeZoneValidatornicolas-grekas commentedApr 4, 2017
should be with a lowercase "z", see#21875 |
dbe965b to0328eb0Comparephansys commentedApr 4, 2017
Simple question: since |
TimeZoneValidatorTimezoneValidatorTimezoneValidatorTimezoneValidatorbbc03de toe5b599fCompare| } | ||
| $this->context->buildViolation($constraint->message) | ||
| ->setParameter('{{ extra_info }}', $this->formatExtraInfo($constraint->zone, $constraint->countryCode)) |
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.
This is a weird parameter, and binds localized text to this constraint validator... 👎 for that.
What about specialized params instead likezone_id /zone_name or so?
| */ | ||
| public function __construct($options = null) | ||
| { | ||
| if (isset($options['zone'])) { |
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.
What about\DateTimeZone::ALL as a default, or, ifcountryCode is given default to\DateTimeZone::PER_COUNTRY instead. So we dont have to expectnull :)
| public $message = 'This value is not a valid timezone{{ extra_info }}.'; | ||
| protected static $errorNames = array( | ||
| self::NO_SUCH_TIMEZONE_ERROR => 'NO_SUCH_TIMEZONE_ERROR', |
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.
missing few codes here
| const NO_SUCH_TIMEZONE_IN_COUNTRY_ERROR = 'c4a22222-dc92-4fc0-abb0-d95b268c7d0b'; | ||
| public $zone; | ||
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.
newlines between public props can be removed
| $value = (string) $value; | ||
| $zone = null !== $constraint->zone ? $constraint->zone : \DateTimeZone::ALL; | ||
| $timezoneIds = \DateTimeZone::listIdentifiers($zone, $constraint->countryCode); |
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.
listIdentifiers actually allows zones like\DateTimeZone::AMERICA | \DateTimeZone::EUROPE.. thats cool 👍
nicolas-grekas commentedOct 8, 2017
Moving to 4.1. Rebase on master might be needed, where PHP 7.1 features can be used btw. |
58de37e tob8cce71Comparephansys commentedFeb 6, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Rebased. I'll be waiting for feedback about the@ro0NL's proposal to use |
386a46c to72505afCompare| */ | ||
| public function __construct(array $options = null) | ||
| { | ||
| $this->zone = $options['zone'] ?? null; |
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.
calling the parent constructor actually sets the options on properties, so i think we should do the validation step after based on the property values set.
| * | ||
| * @return array | ||
| */ | ||
| private function generateValidationMessage(int $zone = null, string $countryCode = null): array |
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'd prefer not to have this method, the generated messages are also not translator friendly. Instead i would always set the (standard){{ value }} parameter (being the zone ID in this case) see e.g.https://github.com/symfony/symfony/blob/v4.1.5/src/Symfony/Component/Validator/Constraints/CurrencyValidator.php#L48
| public $zone; | ||
| public $countryCode; | ||
| public $message = 'This value is not a valid timezone{{ zone_message }}{{ country_code_message }}.'; |
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'd sayThis value is not a valid timezone.
the standard seems to not include the value in the message (which in this case cannot be translated), see e.g.https://github.com/symfony/symfony/blob/v4.1.5/src/Symfony/Component/Validator/Constraints/Currency.php#L31
also the message should be added toovalidators.en.xml + any language you know
ro0NL left a comment
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.
see also#28831, as we have to decide wether we use PHP or Intl for validating.
hhamon commentedApr 6, 2019 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Hey! What's the status of this PR please? Can I try to finish it? |
hhamon commentedApr 6, 2019
This PR has been reworked here#30900. |
fabpot commentedApr 6, 2019
Closing in favor of#30900. |
…phansys)This PR was merged into the 4.3-dev branch.Discussion----------[Validator] add new `Timezone` validation constraint| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | yes| BC breaks? | no| Deprecations? | no| Tests pass? | yes| License | MIT| Doc PR |symfony/symfony-docs#11317Rework of#22262.Commits-------536e53f [Validator] add new `Timezone` validation constraint.
Uh oh!
There was an error while loading.Please reload this page.
Add
TimezoneValidatorin order to validate timezones against\DateTimeZone::listIdentifiers().TODO:
\DateTimeZone::PER_COUNTRYargument