Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ee71cdb

Browse files
ro0NLnicolas-grekas
authored andcommitted
[Validator] Fix TimezoneValidator default option
1 parent 3392186 commit ee71cdb

File tree

4 files changed

+11
-27
lines changed

4 files changed

+11
-27
lines changed

src/Symfony/Component/Validator/Constraints/Timezone.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class Timezone extends Constraint
4343
/**
4444
* {@inheritdoc}
4545
*/
46-
public function __construct(array $options = null)
46+
public function __construct($options = null)
4747
{
4848
parent::__construct($options);
4949

@@ -58,4 +58,12 @@ public function __construct(array $options = null)
5858
throw new ConstraintDefinitionException('The option "intlCompatible" can only be used when the PHP intl extension is available.');
5959
}
6060
}
61+
62+
/**
63+
* {@inheritdoc}
64+
*/
65+
public function getDefaultOption()
66+
{
67+
return 'zone';
68+
}
6169
}

src/Symfony/Component/Validator/Constraints/TimezoneValidator.php

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -75,28 +75,6 @@ public function validate($value, Constraint $constraint)
7575
->addViolation();
7676
}
7777

78-
/**
79-
* {@inheritdoc}
80-
*/
81-
public function getDefaultOption()
82-
{
83-
return 'zone';
84-
}
85-
86-
/**
87-
* {@inheritdoc}
88-
*/
89-
protected function formatValue($value, $format = 0)
90-
{
91-
$value = parent::formatValue($value, $format);
92-
93-
if (!$value || \DateTimeZone::PER_COUNTRY === $value) {
94-
return $value;
95-
}
96-
97-
return array_search($value, (new \ReflectionClass(\DateTimeZone::class))->getConstants(), true) ?: $value;
98-
}
99-
10078
private static function getPhpTimezones(int $zone, string $countryCode = null): array
10179
{
10280
if (null !== $countryCode) {

src/Symfony/Component/Validator/Tests/Constraints/TimezoneTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function testValidTimezoneConstraints()
2323
{
2424
new Timezone();
2525
new Timezone(['zone' => \DateTimeZone::ALL]);
26-
new Timezone(['zone' => \DateTimeZone::ALL_WITH_BC]);
26+
new Timezone(\DateTimeZone::ALL_WITH_BC);
2727
new Timezone([
2828
'zone' => \DateTimeZone::PER_COUNTRY,
2929
'countryCode' => 'AR',

src/Symfony/Component/Validator/Tests/Constraints/TimezoneValidatorTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,7 @@ public function testGroupedTimezonesWithInvalidCountry()
267267
*/
268268
public function testDeprecatedTimezonesAreValidWithBC(string $timezone)
269269
{
270-
$constraint = new Timezone([
271-
'zone' => \DateTimeZone::ALL_WITH_BC,
272-
]);
270+
$constraint = new Timezone(\DateTimeZone::ALL_WITH_BC);
273271

274272
$this->validator->validate($timezone, $constraint);
275273

0 commit comments

Comments
 (0)