Skip to content

Commit

Permalink
[zendframework#4284] Mark ext/intl as suggested only
Browse files Browse the repository at this point in the history
- Marking as required in the framework makes it impossible to install
  the full ZF2 distribution when ext/intl is not available.
- Based on discussion in zendframework#4284, both zf2 and zend-i18n composer.json
  files should be in sync; otherwise, full zf2 will be installed if
  ext/intl is not available when attempting to install zend-i18n.
- Updated all code to raise a new "ExtensionNotLoadedException" when
  ext/intl is required but not detected.
  • Loading branch information
weierophinney committed Apr 25, 2013
1 parent 433c7c2 commit 751ce18
Show file tree
Hide file tree
Showing 15 changed files with 138 additions and 3 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
"homepage": "http://framework.zend.com/",
"license": "BSD-3-Clause",
"require": {
"php": ">=5.3.3",
"ext-intl": "*"
"php": ">=5.3.3"
},
"require-dev": {
"doctrine/common": ">=2.1",
Expand All @@ -19,6 +18,7 @@
"phpunit/PHPUnit": "3.7.*"
},
"suggest": {
"ext-intl": "ext/intl for i18n features (included in default builds of PHP)",
"doctrine/common": "Doctrine\\Common >=2.1 for annotation features",
"ircmaxell/random-lib": "Fallback random byte generator for Zend\\Math\\Rand if OpenSSL/Mcrypt extensions are unavailable",
"pecl-weakref": "Implementation of weak references for Zend\\Stdlib\\CallbackHandler",
Expand Down
16 changes: 16 additions & 0 deletions library/Zend/I18n/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 library/Zend/I18n/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\InvalidArgumentException 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 library/Zend/I18n/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 library/Zend/I18n/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
8 changes: 8 additions & 0 deletions library/Zend/I18n/Translator/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,18 @@ class Translator
*
* @param array|Traversable $options
* @return Translator
* @throws Exception\ExtensionNotLoadedException if ext/intl is not present
* @throws Exception\InvalidArgumentException
*/
public static function factory($options)
{
if (!extension_loaded('intl')) {
throw new Exception\ExtensionNotLoadedException(sprintf(
'%s component requires the intl PHP extension',
__NAMESPACE__
));
}

if ($options instanceof Traversable) {
$options = ArrayUtils::iteratorToArray($options);
} elseif (!is_array($options)) {
Expand Down
9 changes: 9 additions & 0 deletions library/Zend/I18n/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 library/Zend/I18n/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 library/Zend/I18n/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 library/Zend/I18n/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\InvalidArgumentException 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 library/Zend/I18n/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 $formatters = array();

/**
* @throws Exception\InvalidArgumentException 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__
));
}
}

/**
* The 3-letter ISO 4217 currency code indicating the currency to use.
*
Expand Down
13 changes: 13 additions & 0 deletions library/Zend/I18n/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\InvalidArgumentException 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__
));
}
}

/**
* Set timezone to use instead of the default.
*
Expand Down
14 changes: 14 additions & 0 deletions library/Zend/I18n/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 @@ -46,6 +47,19 @@ class NumberFormat extends AbstractHelper
*/
protected $formatters = array();

/**
* @throws Exception\InvalidArgumentException 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__
));
}
}

/**
* Set format style to use instead of the default.
*
Expand Down
13 changes: 13 additions & 0 deletions library/Zend/I18n/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\InvalidArgumentException 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__
));
}
}

/**
* Set the plural rule to use
*
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/I18n/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
"target-dir": "Zend/I18n",
"require": {
"php": ">=5.3.3",
"ext-intl": "*",
"zendframework/zend-stdlib": "self.version"
},
"suggest": {
"ext-intl": "Required for most features of Zend\\I18n; included in default builds of PHP",
"zendframework/zend-filter": "You should install this package to use the provided filters",
"zendframework/zend-validator": "You should install this package to use the provided validators",
"zendframework/zend-view": "You should install this package to use the provided view helpers"
Expand Down

0 comments on commit 751ce18

Please sign in to comment.