-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[Validator] Add TimezoneValidator
#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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
4b87fb7
6cceda0
6124ef6
49e4b51
288a413
7545275
de78802
dfa4f98
6be950a
6d23035
13bc629
0491875
14689f7
c3dce5c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
zone or countryCode are provided
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,9 +44,17 @@ public function validate($value, Constraint $constraint) | |
| $timezoneIds = \DateTimeZone::listIdentifiers($zone, $constraint->countryCode); | ||
|
||
|
|
||
| if ($timezoneIds && !in_array($value, $timezoneIds, true)) { | ||
| if ($constraint->countryCode) { | ||
| $code = Timezone::NO_SUCH_TIMEZONE_IN_COUNTRY_ERROR; | ||
| } elseif (null !== $constraint->zone) { | ||
| $code = Timezone::NO_SUCH_TIMEZONE_IN_ZONE_ERROR; | ||
| } else { | ||
| $code = Timezone::NO_SUCH_TIMEZONE_ERROR; | ||
| } | ||
|
|
||
| $this->context->buildViolation($constraint->message) | ||
| ->setParameter('{{ extra_info }}', $this->formatExtraInfo($constraint->zone, $constraint->countryCode)) | ||
|
||
| ->setCode(Timezone::NO_SUCH_TIMEZONE_ERROR) | ||
| ->setCode($code) | ||
| ->addViolation(); | ||
| } | ||
| } | ||
|
|
||
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