Exemple #1
0
 /**
  * Internal function for checking the options array of proper input values
  * See {@link setOptions()} for details.
  *
  * @param  array  $options  Array of options, keyed by option name: format_type = 'iso' | 'php', fix_date = true | false,
  *                          locale = IfwPsn_Vendor_Zend_Locale | locale string, precision = whole number between -1 and 30
  * @throws IfwPsn_Vendor_Zend_Locale_Exception
  * @return Options array if no option was given
  */
 private static function _checkOptions(array $options = array())
 {
     if (count($options) == 0) {
         return self::$_options;
     }
     foreach ($options as $name => $value) {
         $name = strtolower($name);
         if ($name !== 'locale') {
             if (gettype($value) === 'string') {
                 $value = strtolower($value);
             }
         }
         switch ($name) {
             case 'number_format':
                 if ($value == IfwPsn_Vendor_Zend_Locale_Format::STANDARD) {
                     $locale = self::$_options['locale'];
                     if (isset($options['locale'])) {
                         $locale = $options['locale'];
                     }
                     $options['number_format'] = IfwPsn_Vendor_Zend_Locale_Data::getContent($locale, 'decimalnumber');
                 } else {
                     if (gettype($value) !== 'string' and $value !== NULL) {
                         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Locale/Exception.php';
                         $stringValue = (string) (is_array($value) ? implode(' ', $value) : $value);
                         throw new IfwPsn_Vendor_Zend_Locale_Exception("Unknown number format type '" . gettype($value) . "'. " . "Format '{$stringValue}' must be a valid number format string.");
                     }
                 }
                 break;
             case 'date_format':
                 if ($value == IfwPsn_Vendor_Zend_Locale_Format::STANDARD) {
                     $locale = self::$_options['locale'];
                     if (isset($options['locale'])) {
                         $locale = $options['locale'];
                     }
                     $options['date_format'] = IfwPsn_Vendor_Zend_Locale_Format::getDateFormat($locale);
                 } else {
                     if (gettype($value) !== 'string' and $value !== NULL) {
                         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Locale/Exception.php';
                         $stringValue = (string) (is_array($value) ? implode(' ', $value) : $value);
                         throw new IfwPsn_Vendor_Zend_Locale_Exception("Unknown dateformat type '" . gettype($value) . "'. " . "Format '{$stringValue}' must be a valid ISO or PHP date format string.");
                     } else {
                         if (isset($options['format_type']) === true and $options['format_type'] == 'php' or isset($options['format_type']) === false and self::$_options['format_type'] == 'php') {
                             $options['date_format'] = IfwPsn_Vendor_Zend_Locale_Format::convertPhpToIsoFormat($value);
                         }
                     }
                 }
                 break;
             case 'format_type':
                 if ($value != 'php' && $value != 'iso') {
                     require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Locale/Exception.php';
                     throw new IfwPsn_Vendor_Zend_Locale_Exception("Unknown date format type '{$value}'. Only 'iso' and 'php'" . " are supported.");
                 }
                 break;
             case 'fix_date':
                 if ($value !== true && $value !== false) {
                     require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Locale/Exception.php';
                     throw new IfwPsn_Vendor_Zend_Locale_Exception("Enabling correction of dates must be either true or false" . "(fix_date='{$value}').");
                 }
                 break;
             case 'locale':
                 $options['locale'] = IfwPsn_Vendor_Zend_Locale::findLocale($value);
                 break;
             case 'cache':
                 if ($value instanceof IfwPsn_Vendor_Zend_Cache_Core) {
                     IfwPsn_Vendor_Zend_Locale_Data::setCache($value);
                 }
                 break;
             case 'disablecache':
                 IfwPsn_Vendor_Zend_Locale_Data::disableCache($value);
                 break;
             case 'precision':
                 if ($value === NULL) {
                     $value = -1;
                 }
                 if ($value < -1 || $value > 30) {
                     require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Locale/Exception.php';
                     throw new IfwPsn_Vendor_Zend_Locale_Exception("'{$value}' precision is not a whole number less than 30.");
                 }
                 break;
             default:
                 require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Locale/Exception.php';
                 throw new IfwPsn_Vendor_Zend_Locale_Exception("Unknown option: '{$name}' = '{$value}'");
                 break;
         }
     }
     return $options;
 }
Exemple #2
0
 /**
  * Disables the set cache
  *
  * @param  boolean $flag True disables any set cache, default is false
  * @return void
  */
 public static function disableCache($flag)
 {
     require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Locale/Data.php';
     IfwPsn_Vendor_Zend_Locale_Data::disableCache($flag);
 }