From ee71cdbae4db09b574ec88244327b238da92bc39 Mon Sep 17 00:00:00 2001 From: Roland Franssen Date: Thu, 30 May 2019 18:46:20 +0200 Subject: [PATCH] [Validator] Fix TimezoneValidator default option --- .../Validator/Constraints/Timezone.php | 10 ++++++++- .../Constraints/TimezoneValidator.php | 22 ------------------- .../Tests/Constraints/TimezoneTest.php | 2 +- .../Constraints/TimezoneValidatorTest.php | 4 +--- 4 files changed, 11 insertions(+), 27 deletions(-) diff --git a/src/Symfony/Component/Validator/Constraints/Timezone.php b/src/Symfony/Component/Validator/Constraints/Timezone.php index 0f4b57b0875a..9a46c15ddfd7 100644 --- a/src/Symfony/Component/Validator/Constraints/Timezone.php +++ b/src/Symfony/Component/Validator/Constraints/Timezone.php @@ -43,7 +43,7 @@ class Timezone extends Constraint /** * {@inheritdoc} */ - public function __construct(array $options = null) + public function __construct($options = null) { parent::__construct($options); @@ -58,4 +58,12 @@ public function __construct(array $options = null) throw new ConstraintDefinitionException('The option "intlCompatible" can only be used when the PHP intl extension is available.'); } } + + /** + * {@inheritdoc} + */ + public function getDefaultOption() + { + return 'zone'; + } } diff --git a/src/Symfony/Component/Validator/Constraints/TimezoneValidator.php b/src/Symfony/Component/Validator/Constraints/TimezoneValidator.php index d4261ff376c5..cf52239d0c24 100644 --- a/src/Symfony/Component/Validator/Constraints/TimezoneValidator.php +++ b/src/Symfony/Component/Validator/Constraints/TimezoneValidator.php @@ -75,28 +75,6 @@ public function validate($value, Constraint $constraint) ->addViolation(); } - /** - * {@inheritdoc} - */ - public function getDefaultOption() - { - return 'zone'; - } - - /** - * {@inheritdoc} - */ - protected function formatValue($value, $format = 0) - { - $value = parent::formatValue($value, $format); - - if (!$value || \DateTimeZone::PER_COUNTRY === $value) { - return $value; - } - - return array_search($value, (new \ReflectionClass(\DateTimeZone::class))->getConstants(), true) ?: $value; - } - private static function getPhpTimezones(int $zone, string $countryCode = null): array { if (null !== $countryCode) { diff --git a/src/Symfony/Component/Validator/Tests/Constraints/TimezoneTest.php b/src/Symfony/Component/Validator/Tests/Constraints/TimezoneTest.php index adc27a769980..450c82ffeb75 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/TimezoneTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/TimezoneTest.php @@ -23,7 +23,7 @@ public function testValidTimezoneConstraints() { new Timezone(); new Timezone(['zone' => \DateTimeZone::ALL]); - new Timezone(['zone' => \DateTimeZone::ALL_WITH_BC]); + new Timezone(\DateTimeZone::ALL_WITH_BC); new Timezone([ 'zone' => \DateTimeZone::PER_COUNTRY, 'countryCode' => 'AR', diff --git a/src/Symfony/Component/Validator/Tests/Constraints/TimezoneValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/TimezoneValidatorTest.php index 82a521d950a9..352e45c5d355 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/TimezoneValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/TimezoneValidatorTest.php @@ -267,9 +267,7 @@ public function testGroupedTimezonesWithInvalidCountry() */ public function testDeprecatedTimezonesAreValidWithBC(string $timezone) { - $constraint = new Timezone([ - 'zone' => \DateTimeZone::ALL_WITH_BC, - ]); + $constraint = new Timezone(\DateTimeZone::ALL_WITH_BC); $this->validator->validate($timezone, $constraint);