Exemple #1
0
 public function setUp()
 {
     $this->_cache = Cache::factory('Core', 'File',
              array('lifetime' => 1, 'automatic_serialization' => true),
              array('cache_dir' => __DIR__ . '/../../_files/'));
     Cldr::setCache($this->_cache);
 }
Exemple #2
0
    public function setUp()
    {
        $this->_cacheDir = sys_get_temp_dir() . '/zend_locale_cldr';
        $this->_removeRecursive($this->_cacheDir);
        mkdir($this->_cacheDir);

        $this->_cache = CacheFactory::factory(array(
            'adapter' => array(
                'name' => 'Filesystem',
                'options' => array(
                    'ttl'       => 1,
                    'cache_dir' => $this->_cacheDir,
                )
            ),
            'plugins' => array(
                array(
                    'name' => 'serializer',
                    'options' => array(
                        'serializer' => 'php_serialize',
                    ),
                ),
            ),
        ));

        Cldr::setCache($this->_cache);
    }
Exemple #3
0
 /**
  * Sets class wide options, if no option was given, the actual set options will be returned
  *
  * @param  array  $options  Options to set
  * @throws \Zend\Date\Exception
  * @return Options array if no option was given
  */
 public static function setOptions(array $options = array())
 {
     if (empty($options)) {
         return self::$_options;
     }
     foreach ($options as $name => $value) {
         $name = strtolower($name);
         if (array_key_exists($name, self::$_options)) {
             switch ($name) {
                 case 'format_type':
                     if (strtolower($value) != 'php' && strtolower($value) != 'iso') {
                         throw new Exception\InvalidArgumentException("Unknown format type ({$value}) for dates, only 'iso' and 'php' supported");
                         /*, 0, null, $value */
                     }
                     break;
                 case 'fix_dst':
                     if (!is_bool($value)) {
                         throw new Exception\InvalidArgumentException("'fix_dst' has to be boolean");
                         /* , 0, null, $value */
                     }
                     break;
                 case 'extend_month':
                     if (!is_bool($value)) {
                         throw new Exception\InvalidArgumentException("'extend_month' has to be boolean");
                         /* ); */
                     }
                     break;
                 case 'cache':
                     if ($value === null) {
                         parent::$_cache = null;
                     } else {
                         if (!$value instanceof \Zend\Cache\Frontend) {
                             throw new Exception\InvalidArgumentException("Instance of Zend_Cache expected");
                         }
                         parent::$_cache = $value;
                         parent::$_cacheTags = Zend_Date_DateObject::hasCacheTagSupport();
                         Cldr::setCache($value);
                     }
                     break;
                 case 'timesync':
                     if ($value === null) {
                         parent::$_defaultOffset = 0;
                     } else {
                         if (!$value instanceof TimeSync\Protocol) {
                             throw new Exception\InvalidArgumentException("Instance of Zend_TimeSync expected for option timesync");
                         }
                         $date = $value->getInfo();
                         parent::$_defaultOffset = $date['offset'];
                     }
                     break;
             }
             self::$_options[$name] = $value;
         } else {
             throw new Exception\InvalidArgumentException("Unknown option: {$name} = {$value}");
         }
     }
 }
Exemple #4
0
 /**
  * Sets a cache
  *
  * @param  CacheAdapter $cache Cache to set
  * @return void
  */
 public static function setCache(CacheAdapter $cache)
 {
     Data\Cldr::setCache($cache);
 }
Exemple #5
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 = Zend_Locale | locale string, precision = whole number between -1 and 30
  * @throws \Zend\Locale\Exception\InvalidArgumentException
  * @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 == self::STANDARD) {
                     $locale = self::$_options['locale'];
                     if (isset($options['locale'])) {
                         $locale = $options['locale'];
                     }
                     $options['number_format'] = Cldr::getContent($locale, 'decimalnumber');
                 } else {
                     if (gettype($value) !== 'string' and $value !== NULL) {
                         throw new Exception\InvalidArgumentException("Unknown number format type '" . gettype($value) . "'. " . "Format '{$value}' must be a valid number format string.");
                     }
                 }
                 break;
             case 'date_format':
                 if ($value == self::STANDARD) {
                     $locale = self::$_options['locale'];
                     if (isset($options['locale'])) {
                         $locale = $options['locale'];
                     }
                     $options['date_format'] = self::getDateFormat($locale);
                 } else {
                     if (gettype($value) !== 'string' and $value !== NULL) {
                         throw new Exception\InvalidArgumentException("Unknown dateformat type '" . gettype($value) . "'. " . "Format '{$value}' 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'] = self::convertPhpToIsoFormat($value);
                         }
                     }
                 }
                 break;
             case 'format_type':
                 if ($value != 'php' && $value != 'iso') {
                     throw new Exception\InvalidArgumentException("Unknown date format type '{$value}'. Only 'iso' and 'php'" . " are supported.");
                 }
                 break;
             case 'fix_date':
                 if ($value !== true && $value !== false) {
                     throw new Exception\InvalidArgumentException("Enabling correction of dates must be either true or false" . "(fix_date='{$value}').");
                 }
                 break;
             case 'locale':
                 $options['locale'] = Locale::findLocale($value);
                 break;
             case 'cache':
                 if ($value instanceof \Zend\Cache\Core) {
                     Cldr::setCache($value);
                 }
                 break;
             case 'disablecache':
                 Cldr::disableCache($value);
                 break;
             case 'precision':
                 if ($value === NULL) {
                     $value = -1;
                 }
                 if ($value < -1 || $value > 30) {
                     throw new Exception\InvalidArgumentException("'{$value}' precision is not a whole number less than 30.");
                 }
                 break;
             default:
                 throw new Exception\InvalidArgumentException("Unknown option: '{$name}' = '{$value}'");
                 break;
         }
     }
     return $options;
 }
Exemple #6
0
 /**
  * Sets a cache for Zend_Currency
  *
  * @param  Zend\Cache\Frontend $cache Cache to set
  * @return void
  */
 public static function setCache(Frontend $cache)
 {
     Cldr::setCache($cache);
 }
Exemple #7
0
 public function setUp()
 {
     $this->_cache = CacheFactory::adapterFactory('memory', array('memory_limit' => 0));
     Cldr::setCache($this->_cache);
 }
Exemple #8
0
 /**
  * Sets a cache
  *
  * @param  \Zend\Cache\Frontend $cache Cache to set
  * @return void
  */
 public static function setCache(\Zend\Cache\Frontend $cache)
 {
     Data\Cldr::setCache($cache);
 }