8000 Support customized intl php.ini settings · symfony/symfony@ddc608e · GitHub
[go: up one dir, main page]

Skip to content

Commit ddc608e

Browse files
committed
Support customized intl php.ini settings
`IntlDateParser->parse()` behaves differently when `intl.error_level` and/or `intl.use_exceptions` are not 0. This change makes sure `\IntlException` is caught when `intl.use_exceptions` is 1 and warnings thrown when `intl.error_level` is not 0 are ignored.
1 parent ea0eb11 commit ddc608e

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformer.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,11 @@ public function reverseTransform($value)
118118
// to DST changes
119119
$dateOnly = $this->isPatternDateOnly();
120120

121-
$timestamp = $this->getIntlDateFormatter($dateOnly)->parse($value);
121+
try {
122+
$timestamp = @$this->getIntlDateFormatter($dateOnly)->parse($value);
123+
} catch (\IntlException $ex) {
124+
throw new TransformationFailedException($ex->getMessage(), $ex->getCode(), $ex);
125+
}
122126

123127
if (0 != intl_get_error_code()) {
124128
throw new TransformationFailedException(intl_get_error_message());

src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformerTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ protected function setUp(): void
2727
{
2828
parent::setUp();
2929

30+
// Normalize intl. configuration settings.
31+
$this->iniSet('intl.use_exceptions', 0);
32+
$this->iniSet('intl.error_level', 0);
33+
3034
// Since we test against "de_AT", we need the full implementation
3135
IntlTestHelper::requireFullIntl($this, '57.1');
3236

@@ -322,4 +326,32 @@ public function testReverseTransformFiveDigitYearsWithTimestamp()
322326
$transformer = new DateTimeToLocalizedStringTransformer('UTC', 'UTC', null, null, \IntlDateFormatter::GREGORIAN, 'yyyy-MM-dd HH:mm:ss');
323327
$transformer->reverseTransform('20107-03-21 12:34:56');
324328
}
329+
330+
public function testReverseTransformWrapsIntlErrorsWithErrorLevel()
331+
{
332+
$this->iniSet('intl.error_level', E_WARNING);
333+
334+
$this->expectException('Symfony\Component\Form\Exception\TransformationFailedException');
335+
$transformer = new DateTimeToLocalizedStringTransformer();
336+
$transformer->reverseTransform('12345');
337+
}
338+
339+
public function testReverseTransformWrapsIntlErrorsWithExceptions()
340+
{
341+
$this->iniSet('intl.use_exceptions', 1);
342+
343+
$this->expectException('Symfony\Component\Form\Exception\TransformationFailedException');
344+
$transformer = new DateTimeToLocalizedStringTransformer();
345+
$transformer->reverseTransform('12345');
346+
}
347+
348+
public function testReverseTransformWrapsIntlErrorsWithExceptionsAndErrorLevel()
349+
{
350+
$this->iniSet('intl.use_exceptions', 1);
351+
$this->iniSet('intl.error_level', E_WARNING);
352+
353+
$this->expectException('Symfony\Component\Form\Exception\TransformationFailedException');
354+
$transformer = new DateTimeToLocalizedStringTransformer();
355+
$transformer->reverseTransform('12345');
356+
}
325357
}

0 commit comments

Comments
 (0)
0