Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit251aa20

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 parentea0eb11 commit251aa20

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-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+
thrownewTransformationFailedException($ex->getMessage(),$ex->getCode(),$ex);
125+
}
122126

123127
if (0 !=intl_get_error_code()) {
124128
thrownewTransformationFailedException(intl_get_error_message());

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

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

30+
// Normalize intl. configuration settings.
31+
if (\extension_loaded('intl')) {
32+
$this->iniSet('intl.use_exceptions',0);
33+
$this->iniSet('intl.error_level',0);
34+
}
35+
3036
// Since we test against "de_AT", we need the full implementation
3137
IntlTestHelper::requireFullIntl($this,'57.1');
3238

@@ -322,4 +328,44 @@ public function testReverseTransformFiveDigitYearsWithTimestamp()
322328
$transformer =newDateTimeToLocalizedStringTransformer('UTC','UTC',null,null, \IntlDateFormatter::GREGORIAN,'yyyy-MM-dd HH:mm:ss');
323329
$transformer->reverseTransform('20107-03-21 12:34:56');
324330
}
331+
332+
publicfunctiontestReverseTransformWrapsIntlErrorsWithErrorLevel()
333+
{
334+
if (!\extension_loaded('intl')) {
335+
$this->markTestSkipped('intl extension is not loaded');
336+
}
337+
338+
$this->iniSet('intl.error_level',E_WARNING);
339+
340+
$this->expectException('Symfony\Component\Form\Exception\TransformationFailedException');
341+
$transformer =newDateTimeToLocalizedStringTransformer();
342+
$transformer->reverseTransform('12345');
343+
}
344+
345+
publicfunctiontestReverseTransformWrapsIntlErrorsWithExceptions()
346+
{
347+
if (!\extension_loaded('intl')) {
348+
$this->markTestSkipped('intl extension is not loaded');
349+
}
350+
351+
$this->iniSet('intl.use_exceptions',1);
352+
353+
$this->expectException('Symfony\Component\Form\Exception\TransformationFailedException');
354+
$transformer =newDateTimeToLocalizedStringTransformer();
355+
$transformer->reverseTransform('12345');
356+
}
357+
358+
publicfunctiontestReverseTransformWrapsIntlErrorsWithExceptionsAndErrorLevel()
359+
{
360+
if (!\extension_loaded('intl')) {
361+
$this->markTestSkipped('intl extension is not loaded');
362+
}
363+
364+
$this->iniSet('intl.use_exceptions',1);
365+
$this->iniSet('intl.error_level',E_WARNING);
366+
367+
$this->expectException('Symfony\Component\Form\Exception\TransformationFailedException');
368+
$transformer =newDateTimeToLocalizedStringTransformer();
369+
$transformer->reverseTransform('12345');
370+
}
325371
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp