8000 Update way of handling `zone` option · symfony/symfony@e09ad49 · GitHub
[go: up one dir, main page]

Skip to content

Commit e09ad49

Browse files
committed
Update way of handling zone option
1 parent 45e7de2 commit e09ad49

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Timezone extends Constraint
2424
{
2525
const NO_SUCH_TIMEZONE_ERROR = '45de6628-3479-46d6-a210-00ad584f530a';
2626

27-
public $zone = \DateTimeZone::ALL;
27+
public $zone;
2828

2929
public $countryCode;
3030

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ public function validate($value, Constraint $constraint)
4040
}
4141

4242
$value = (string) $value;
43-
$timezoneIds = \DateTimeZone::listIdentifiers($constraint->zone, $constraint->countryCode);
43+
$zone = null !== $constraint->zone ? $constraint->zone : \DateTimeZone::ALL;
44+
$timezoneIds = \DateTimeZone::listIdentifiers($zone, $constraint->countryCode);
4445

4546
if ($timezoneIds && !in_array($value, $timezoneIds, true)) {
4647
$this->context->buildViolation($constraint->message)
@@ -62,13 +63,16 @@ public function getDefaultOption()
6263
* Format the extra info which is appended to validation message based on
6364
* constraint options.
6465
*
65-
* @param int $zone
66+
* @param int|null $zone
6667
* @param string|null $countryCode
6768
*
6869
* @return string
6970
*/
7071
private function formatExtraInfo($zone, $countryCode = null)
7172
{
73+
if (null === $zone) {
74+
return '';
75+
}
7276
if ($countryCode) {
7377
$value = ' for ISO 3166-1 country code "'.$countryCode.'"';
7478
} else {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function getValidGroupedTimezones()
106106
/**
107107
* @dataProvider getInvalidTimezones
108108
*/
109-
public function testInvalidTimezones($timezone, $extraInfo)
109+
public function testInvalidTimezonesWithoutZone($timezone, $extraInfo)
110110
{
111111
$constraint = new Timezone(array(
112112
'message' => 'myMessage',
@@ -115,17 +115,17 @@ public function testInvalidTimezones($timezone, $extraInfo)
115115
$this->validator->validate($timezone, $constraint);
116116

117117
$this->buildViolation('myMessage')
118-
->setParameter('{{ extra_info }}', '"'.$extraInfo.'"')
118+
->setParameter('{{ extra_info }}', $extraInfo)
119119
->setCode(Timezone::NO_SUCH_TIMEZONE_ERROR)
120120
->assertRaised();
121121
}
122122

123123
public function getInvalidTimezones()
124124
{
125125
return array(
126-
array('Buenos_Aires/Argentina/America', ' for "ALL" zone'),
127-
array('Mayotte/Indian', ' for "ALL" zone'),
128-
array('foobar', ' for "ALL" zone'),
126+
array('Buenos_Aires/Argentina/America', ''),
127+
array('Mayotte/Indian', ''),
128+
array('foobar', ''),
129129
);
130130
}
131131

0 commit comments

Comments
 (0)
0