From cc4307d1f39e7508c790e605a6c7b3d063eba91c Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Mon, 4 Nov 2013 18:40:13 +0400 Subject: [PATCH] Better Formatter error handler --- framework/yii/i18n/Formatter.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/framework/yii/i18n/Formatter.php b/framework/yii/i18n/Formatter.php index 3fcc189..1388dc1 100644 --- a/framework/yii/i18n/Formatter.php +++ b/framework/yii/i18n/Formatter.php @@ -131,7 +131,12 @@ class Formatter extends \yii\base\Formatter $formatter = new IntlDateFormatter($this->locale, $this->_dateFormats[$format], IntlDateFormatter::NONE); } else { $formatter = new IntlDateFormatter($this->locale, IntlDateFormatter::NONE, IntlDateFormatter::NONE); - $formatter->setPattern($format); + if ($formatter !== null) { + $formatter->setPattern($format); + } + } + if ($formatter === null) { + throw new InvalidConfigException(intl_get_error_message()); } return $formatter->format($value); } @@ -167,7 +172,12 @@ class Formatter extends \yii\base\Formatter $formatter = new IntlDateFormatter($this->locale, IntlDateFormatter::NONE, $this->_dateFormats[$format]); } else { $formatter = new IntlDateFormatter($this->locale, IntlDateFormatter::NONE, IntlDateFormatter::NONE); - $formatter->setPattern($format); + if ($formatter !== null) { + $formatter->setPattern($format); + } + } + if ($formatter === null) { + throw new InvalidConfigException(intl_get_error_message()); } return $formatter->format($value); } @@ -203,7 +213,12 @@ class Formatter extends \yii\base\Formatter $formatter = new IntlDateFormatter($this->locale, $this->_dateFormats[$format], $this->_dateFormats[$format]); } else { $formatter = new IntlDateFormatter($this->locale, IntlDateFormatter::NONE, IntlDateFormatter::NONE); - $formatter->setPattern($format); + if ($formatter !== null) { + $formatter->setPattern($format); + } + } + if ($formatter === null) { + throw new InvalidConfigException(intl_get_error_message()); } return $formatter->format($value); }