bug #11342 [2.3][Form] Check if IntlDateFormatter constructor returned a valid object before using it (romainneutron)
This PR was merged into the 2.3 branch.
Discussion
----------
[2.3][Form] Check if IntlDateFormatter constructor returned a valid object before using it
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | n/a
| License | MIT
`IntlDateFormatter` constructor [may return false](http://www.php.net/manual/en/intldateformatter.create.php#refsect1-intldateformatter.create-returnvalues). This patches avoids fatal errors in these cases
This PR replaces #11334
Commits
-------
ebf967d
[Form] Check if IntlDateFormatter constructor returned a valid object before using it
This commit is contained in:
commit
797d8141e3
@ -152,6 +152,8 @@ class DateTimeToLocalizedStringTransformer extends BaseDateTimeTransformer
|
|||||||
* Returns a preconfigured IntlDateFormatter instance
|
* Returns a preconfigured IntlDateFormatter instance
|
||||||
*
|
*
|
||||||
* @return \IntlDateFormatter
|
* @return \IntlDateFormatter
|
||||||
|
*
|
||||||
|
* @throws TransformationFailedException in case the date formatter can not be constructed.
|
||||||
*/
|
*/
|
||||||
protected function getIntlDateFormatter()
|
protected function getIntlDateFormatter()
|
||||||
{
|
{
|
||||||
@ -162,6 +164,12 @@ class DateTimeToLocalizedStringTransformer extends BaseDateTimeTransformer
|
|||||||
$pattern = $this->pattern;
|
$pattern = $this->pattern;
|
||||||
|
|
||||||
$intlDateFormatter = new \IntlDateFormatter(\Locale::getDefault(), $dateFormat, $timeFormat, $timezone, $calendar, $pattern);
|
$intlDateFormatter = new \IntlDateFormatter(\Locale::getDefault(), $dateFormat, $timeFormat, $timezone, $calendar, $pattern);
|
||||||
|
|
||||||
|
// new \intlDateFormatter may return null instead of false in case of failure, see https://bugs.php.net/bug.php?id=66323
|
||||||
|
if (!$intlDateFormatter) {
|
||||||
|
throw new TransformationFailedException(intl_get_error_message(), intl_get_error_code());
|
||||||
|
}
|
||||||
|
|
||||||
$intlDateFormatter->setLenient(false);
|
$intlDateFormatter->setLenient(false);
|
||||||
|
|
||||||
return $intlDateFormatter;
|
return $intlDateFormatter;
|
||||||
|
@ -77,6 +77,12 @@ class DateType extends AbstractType
|
|||||||
$calendar,
|
$calendar,
|
||||||
$pattern
|
$pattern
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// new \intlDateFormatter may return null instead of false in case of failure, see https://bugs.php.net/bug.php?id=66323
|
||||||
|
if (!$formatter) {
|
||||||
|
throw new InvalidOptionsException(intl_get_error_message(), intl_get_error_code());
|
||||||
|
}
|
||||||
|
|
||||||
$formatter->setLenient(false);
|
$formatter->setLenient(false);
|
||||||
|
|
||||||
if ('choice' === $options['widget']) {
|
if ('choice' === $options['widget']) {
|
||||||
|
Reference in New Issue
Block a user