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

Commit

Permalink
Throw exception inside getLocale()
Browse files Browse the repository at this point in the history
- instead of __construct, as ext/intl is only needed if no locale is
  explicitly set.
  • Loading branch information
weierophinney committed Apr 25, 2013
1 parent 2a06433 commit d21fdec
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/Translator/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,6 @@ class Translator
*/
protected $pluginManager;

/**
* @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__
));
}
}

/**
* Instantiate a translator
*
Expand Down Expand Up @@ -230,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

0 comments on commit d21fdec

Please sign in to comment.