Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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

Closed
phansys wants to merge14 commits intosymfony:masterfromphansys:tz_validator

Conversation

@phansys
Copy link
Contributor

@phansysphansys commentedApr 4, 2017
edited
Loading

QA
Branchmaster
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed ticketsn/a
LicenseMIT
Doc PRn/a (yet)

AddTimezoneValidator in order to validate timezones against\DateTimeZone::listIdentifiers().

TODO:

  • Add support for constraints with\DateTimeZone::PER_COUNTRY argument
  • Improve the validation message

@phansysphansys changed the titleAddTimeZoneValidator[Validator] AddTimeZoneValidatorApr 4, 2017
@phansysphansys changed the title[Validator] AddTimeZoneValidator[Validator] [WIP] AddTimeZoneValidatorApr 4, 2017
@nicolas-grekas
Copy link
Member

should be with a lowercase "z", see#21875

phansys reacted with thumbs up emoji

@nicolas-grekasnicolas-grekas added this to the3.4 milestoneApr 4, 2017
@phansysphansysforce-pushed thetz_validator branch 2 times, most recently fromdbe965b to0328eb0CompareApril 4, 2017 16:08
@phansys
Copy link
ContributorAuthor

Simple question: sinceDateTimeZone::listIdentifiers() accepts a string with "a two-letter ISO 3166-1 compatible country code" as second argument, could we useCountry validator atTimezone constructor in order to validate thecountryCode argument?

@phansysphansys changed the title[Validator] [WIP] AddTimeZoneValidator[Validator] [WIP] AddTimezoneValidatorApr 4, 2017
@phansysphansys changed the title[Validator] [WIP] AddTimezoneValidator[Validator] AddTimezoneValidatorApr 4, 2017
@phansysphansysforce-pushed thetz_validator branch 2 times, most recently frombbc03de toe5b599fCompareApril 9, 2017 20:21
}

$this->context->buildViolation($constraint->message)
->setParameter('{{ extra_info }}', $this->formatExtraInfo($constraint->zone, $constraint->countryCode))
Copy link
Contributor

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'])) {
Copy link
Contributor

@ro0NLro0NLJul 14, 2017
edited
Loading

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',
Copy link
Contributor

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;

Copy link
Contributor

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);
Copy link
Contributor

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
Copy link
Member

Moving to 4.1. Rebase on master might be needed, where PHP 7.1 features can be used btw.

@nicolas-grekasnicolas-grekas modified the milestones:3.4,4.1Oct 8, 2017
@phansysphansysforce-pushed thetz_validator branch 2 times, most recently from58de37e tob8cce71CompareFebruary 6, 2018 17:50
@phansys
Copy link
ContributorAuthor

phansys commentedFeb 6, 2018
edited
Loading

Rebased. I'll be waiting for feedback about the@ro0NL's proposal to useDateTimeZone::ALL as default zone. The other comments were already attended.

@phansysphansysforce-pushed thetz_validator branch 2 times, most recently from386a46c to72505afCompareFebruary 26, 2018 03:03
@nicolas-grekasnicolas-grekas modified the milestones:4.1,nextApr 20, 2018
*/
public function __construct(array $options = null)
{
$this->zone = $options['zone'] ?? null;
Copy link
Contributor

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
Copy link
Contributor

@ro0NLro0NLSep 30, 2018
edited
Loading

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 }}.';
Copy link
Contributor

@ro0NLro0NLSep 30, 2018
edited
Loading

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

Copy link
Contributor

@ro0NLro0NL left a 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
Copy link
Contributor

hhamon commentedApr 6, 2019
edited
Loading

Hey!

What's the status of this PR please? Can I try to finish it?

@hhamon
Copy link
Contributor

This PR has been reworked here#30900.

@fabpot
Copy link
Member

Closing in favor of#30900.

phansys reacted with thumbs up emoji

@fabpotfabpot closed thisApr 6, 2019
@phansysphansys deleted the tz_validator branchApril 6, 2019 17:57
fabpot added a commit that referenced this pull requestApr 6, 2019
…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.
@nicolas-grekasnicolas-grekas modified the milestones:next,4.3Apr 30, 2019
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

1 more reviewer

@ro0NLro0NLro0NL left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

4.3

Development

Successfully merging this pull request may close these issues.

6 participants

@phansys@nicolas-grekas@hhamon@fabpot@ro0NL@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp