[Validator] Fix TimezoneValidator default option
This commit is contained in:
parent
3392186e7f
commit
ee71cdbae4
@ -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 @@ class Timezone extends Constraint
|
||||
throw new ConstraintDefinitionException('The option "intlCompatible" can only be used when the PHP intl extension is available.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefaultOption()
|
||||
{
|
||||
return 'zone';
|
||||
}
|
||||
}
|
||||
|
@ -75,28 +75,6 @@ class TimezoneValidator extends ConstraintValidator
|
||||
->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) {
|
||||
|
@ -23,7 +23,7 @@ class TimezoneTest extends TestCase
|
||||
{
|
||||
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',
|
||||
|
@ -267,9 +267,7 @@ class TimezoneValidatorTest extends ConstraintValidatorTestCase
|
||||
*/
|
||||
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);
|
||||
|
||||
|
Reference in New Issue
Block a user