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

Better fix for #4284 #4293

Closed
wants to merge 4 commits into from

Conversation

weierophinney
Copy link
Member

This commit provides a better fix for #4284 by making ext/intl an optional dependency, but enforcing its requirement via tests to extension_loaded and raising an ExtensionNotLoadedException when not found.

- 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.
@weierophinney
Copy link
Member Author

Build failure is due to a Travis issue on 5.4 (unable to download php-cs-fixer, or unable to coerce path to php-cs-fixer).


use DomainException;

class ExtensionNotLoadedException extends DomainException implements
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please extend from Zend\I18n\Exception\DomainException, if it does not exist, create it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no reason to do this. The only requirement we've explicitly stated is that exceptions should extend SPL exceptions, not that the inheritance has to be SPL -> namespaced exception of same name -> more specific version. In terms of inheritance trees, it's simpler and cleaner to define the exceptions as extending simply an SPL exception and implementing the component-specific marker exception.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, we've done this through the framework.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, not everywhere. It's typically been up to the component author;
I've been steering to simple extension.

On Monday, April 22, 2013, prolic wrote:

In library/Zend/I18n/Exception/ExtensionNotLoadedException.php:

@@ -0,0 +1,16 @@
+<?php
+/**

Well, we've done this through the framework.


Reply to this email directly or view it on GitHubhttps://github.com//pull/4293/files#r3905911
.

Matthew Weier O'Phinney
matthew@weierophinney.net
http://mwop.net/

- `s/InvalidArgument/ExtensionNotLoaded/` in `@throws` annotations
* @throws Exception\InvalidArgumentException
*/
public static function factory($options)
{
if (!extension_loaded('intl')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be in the constructor – create it.

__NAMESPACE__
));
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The translator requires the intl extension only to get a default locale if none was set Locale::getDefault().
It would be better to check for class exists and throw the exception only at this point a default locale couldn't detected or simply hard define one default locale.

- instead of __construct, as ext/intl is only needed if no locale is
  explicitly set.
weierophinney added a commit that referenced this pull request Apr 25, 2013
Forward port #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
weierophinney added a commit to zendframework/zend-i18n that referenced this pull request May 15, 2015
weierophinney added a commit to zendframework/zend-i18n that referenced this pull request May 15, 2015
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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants