Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/4284' into develop
Browse files Browse the repository at this point in the history
Forward port zendframework/zendframework#4293

Conflicts:
	library/Zend/I18n/View/Helper/CurrencyFormat.php
	library/Zend/I18n/View/Helper/DateFormat.php
	library/Zend/I18n/View/Helper/NumberFormat.php
	library/Zend/I18n/View/Helper/Plural.php
	library/Zend/I18n/composer.json
  • Loading branch information
Show file tree
Hide file tree
Showing 14 changed files with 135 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"phpunit/PHPUnit": "~4.0"
},
"suggest": {
"ext-intl": "ext/intl for i18n features",
"ext-intl": "Required for most features of Zend\\I18n; included in default builds of PHP",
"zendframework/zend-cache": "Zend\\Cache component",
"zendframework/zend-config": "Zend\\Config component",
"zendframework/zend-eventmanager": "You should install this package to use the events in the translator",
Expand Down
16 changes: 16 additions & 0 deletions src/Exception/ExtensionNotLoadedException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\I18n\Exception;

use DomainException;

class ExtensionNotLoadedException extends DomainException implements
ExceptionInterface
{}
14 changes: 14 additions & 0 deletions src/Filter/AbstractLocale.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,23 @@

use Locale;
use Zend\Filter\AbstractFilter;
use Zend\I18n\Exception;

abstract class AbstractLocale extends AbstractFilter
{
/**
* @throws Exception\ExtensionNotLoadedException if ext/intl is not present
*/
public function __construct()
{
if (!extension_loaded('intl')) {
throw new Exception\ExtensionNotLoadedException(sprintf(
'%s component requires the intl PHP extension',
__NAMESPACE__
));
}
}

/**
* Sets the locale option
*
Expand Down
1 change: 1 addition & 0 deletions src/Filter/Alnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Alnum extends AbstractLocale
*/
public function __construct($allowWhiteSpaceOrOptions = null, $locale = null)
{
parent::__construct();
if ($allowWhiteSpaceOrOptions !== null) {
if (static::isOptions($allowWhiteSpaceOrOptions)) {
$this->setOptions($allowWhiteSpaceOrOptions);
Expand Down
1 change: 1 addition & 0 deletions src/Filter/NumberFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function __construct(
$style = NumberFormatter::DEFAULT_STYLE,
$type = NumberFormatter::TYPE_DOUBLE)
{
parent::__construct();
if ($localeOrOptions !== null) {
if ($localeOrOptions instanceof Traversable) {
$localeOrOptions = iterator_to_array($localeOrOptions);
Expand Down
7 changes: 7 additions & 0 deletions src/Translator/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,17 @@ public function setLocale($locale)
* Get the default locale.
*
* @return string
* @throws Exception\ExtensionNotLoadedException if ext/intl is not present and no locale set
*/
public function getLocale()
{
if ($this->locale === null) {
if (!extension_loaded('intl')) {
throw new Exception\ExtensionNotLoadedException(sprintf(
'%s component requires the intl PHP extension',
__NAMESPACE__
));
}
$this->locale = Locale::getDefault();
}

Expand Down
9 changes: 9 additions & 0 deletions src/Validator/Float.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Locale;
use NumberFormatter;
use Traversable;
use Zend\I18n\Exception as I18nException;
use Zend\Stdlib\ArrayUtils;
use Zend\Validator\AbstractValidator;
use Zend\Validator\Exception;
Expand Down Expand Up @@ -40,9 +41,17 @@ class Float extends AbstractValidator
* Constructor for the integer validator
*
* @param array|Traversable $options
* @throws Exception\ExtensionNotLoadedException if ext/intl is not present
*/
public function __construct($options = array())
{
if (!extension_loaded('intl')) {
throw new I18nException\ExtensionNotLoadedException(sprintf(
'%s component requires the intl PHP extension',
__NAMESPACE__
));
}

if ($options instanceof Traversable) {
$options = ArrayUtils::iteratorToArray($options);
}
Expand Down
9 changes: 9 additions & 0 deletions src/Validator/Int.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Locale;
use NumberFormatter;
use Traversable;
use Zend\I18n\Exception as I18nException;
use Zend\Stdlib\ArrayUtils;
use Zend\Validator\AbstractValidator;
use Zend\Validator\Exception;
Expand Down Expand Up @@ -40,9 +41,17 @@ class Int extends AbstractValidator
* Constructor for the integer validator
*
* @param array|Traversable $options
* @throws Exception\ExtensionNotLoadedException if ext/intl is not present
*/
public function __construct($options = array())
{
if (!extension_loaded('intl')) {
throw new I18nException\ExtensionNotLoadedException(sprintf(
'%s component requires the intl PHP extension',
__NAMESPACE__
));
}

if ($options instanceof Traversable) {
$options = ArrayUtils::iteratorToArray($options);
}
Expand Down
9 changes: 9 additions & 0 deletions src/Validator/PostCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use Locale;
use Traversable;
use Zend\I18n\Exception as I18nException;
use Zend\Stdlib\ArrayUtils;
use Zend\Validator\AbstractValidator;
use Zend\Validator\Callback;
Expand Down Expand Up @@ -226,9 +227,17 @@ class PostCode extends AbstractValidator
* Accepts a string locale and/or "format".
*
* @param array|Traversable $options
* @throws Exception\ExtensionNotLoadedException if ext/intl is not present
*/
public function __construct($options = array())
{
if (!extension_loaded('intl')) {
throw new I18nException\ExtensionNotLoadedException(sprintf(
'%s component requires the intl PHP extension',
__NAMESPACE__
));
}

if ($options instanceof Traversable) {
$options = ArrayUtils::iteratorToArray($options);
}
Expand Down
14 changes: 14 additions & 0 deletions src/View/Helper/AbstractTranslatorHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace Zend\I18n\View\Helper;

use Zend\I18n\Exception;
use Zend\I18n\Translator\Translator;
use Zend\I18n\Translator\TranslatorAwareInterface;
use Zend\View\Helper\AbstractHelper;
Expand All @@ -30,6 +31,19 @@ abstract class AbstractTranslatorHelper extends AbstractHelper implements
*/
protected $translatorTextDomain = 'default';

/**
* @throws Exception\ExtensionsNotLoadedException if ext/intl is not present
*/
public function __construct()
{
if (!extension_loaded('intl')) {
throw new Exception\ExtensionNotLoadedException(sprintf(
'%s component requires the intl PHP extension',
__NAMESPACE__
));
}
}

/**
* Whether translator should be used
*
Expand Down
14 changes: 14 additions & 0 deletions src/View/Helper/CurrencyFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use Locale;
use NumberFormatter;
use Zend\I18n\Exception;
use Zend\View\Helper\AbstractHelper;

/**
Expand Down Expand Up @@ -46,6 +47,19 @@ class CurrencyFormat extends AbstractHelper
*/
protected $showDecimals = true;

/**
* @throws Exception\ExtensionNotLoadedException if ext/intl is not present
*/
public function __construct()
{
if (!extension_loaded('intl')) {
throw new Exception\ExtensionNotLoadedException(sprintf(
'%s component requires the intl PHP extension',
__NAMESPACE__
));
}
}

/**
* Format a number
*
Expand Down
13 changes: 13 additions & 0 deletions src/View/Helper/DateFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ class DateFormat extends AbstractHelper
*/
protected $formatters = array();

/**
* @throws Exception\ExtensionNotLoadedException if ext/intl is not present
*/
public function __construct()
{
if (!extension_loaded('intl')) {
throw new Exception\ExtensionNotLoadedException(sprintf(
'%s component requires the intl PHP extension',
__NAMESPACE__
));
}
}

/**
* Format a date
*
Expand Down
14 changes: 14 additions & 0 deletions src/View/Helper/NumberFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use Locale;
use NumberFormatter;
use Zend\I18n\Exception;
use Zend\View\Helper\AbstractHelper;

/**
Expand Down Expand Up @@ -53,6 +54,19 @@ class NumberFormat extends AbstractHelper
*/
protected $locale;

/**
* @throws Exception\ExtensionNotLoadedException if ext/intl is not present
*/
public function __construct()
{
if (!extension_loaded('intl')) {
throw new Exception\ExtensionNotLoadedException(sprintf(
'%s component requires the intl PHP extension',
__NAMESPACE__
));
}
}

/**
* Format a number
*
Expand Down
13 changes: 13 additions & 0 deletions src/View/Helper/Plural.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ class Plural extends AbstractHelper
*/
protected $rule;

/**
* @throws Exception\ExtensionNotLoadedException if ext/intl is not present
*/
public function __construct()
{
if (!extension_loaded('intl')) {
throw new Exception\ExtensionNotLoadedException(sprintf(
'%s component requires the intl PHP extension',
__NAMESPACE__
));
}
}

/**
* Given an array of strings, a number and, if wanted, an optional locale (the default one is used
* otherwise), this picks the right string according to plural rules of the locale
Expand Down

0 comments on commit 2a3844c

Please sign in to comment.