Exemplo n.º 1
0
 /**
  * Sets a new default locale which will be used when no locale can be detected
  * If provided you can set a quality between 0 and 1 (or 2 and 100)
  * which represents the percent of quality the browser
  * requested within HTTP
  *
  * @param  string|\Zend\Locale\Locale $locale  Locale to set
  * @param  float              $quality The quality to set from 0 to 1
  * @throws \Zend\Locale\Exception When a autolocale was given
  * @throws \Zend\Locale\Exception When a unknown locale was given
  * @return void
  */
 public static function setDefault($locale, $quality = 1)
 {
     if ($locale === 'auto' or $locale === 'root' or $locale === 'default' or $locale === 'environment' or $locale === 'browser') {
         throw new Exception('Only fully qualified locales can be used as default!');
     }
     if ($quality < 0.1 or $quality > 100) {
         throw new Exception("Quality must be between 0.1 and 100");
     }
     if ($quality > 1) {
         $quality /= 100;
     }
     $locale = self::_prepareLocale($locale);
     if (isset(self::$_localeData[(string) $locale]) === true) {
         self::$_default = array((string) $locale => $quality);
     } else {
         $elocale = explode('_', (string) $locale);
         if (isset(self::$_localeData[$elocale[0]]) === true) {
             self::$_default = array($elocale[0] => $quality);
         } else {
             throw new Exception("Unknown locale '" . (string) $locale . "' can not be set as default!");
         }
     }
     self::$_auto = self::getBrowser() + self::getEnvironment() + self::getDefault();
 }