示例#1
0
 /**
  * Internal method for checking the options array
  *
  * @param  array $options Options to check
  * @throws Zend\Currency\Exception On unknown position
  * @throws Zend\Currency\Exception On unknown locale
  * @throws Zend\Currency\Exception On unknown display
  * @throws Zend\Currency\Exception On precision not between -1 and 30
  * @throws Zend\Currency\Exception On problem with script conversion
  * @throws Zend\Currency\Exception On unknown options
  * @return array
  */
 protected function _checkOptions(array $options = array())
 {
     if (count($options) === 0) {
         return $this->_options;
     }
     foreach ($options as $name => $value) {
         $name = strtolower($name);
         if ($name !== 'format') {
             if (gettype($value) === 'string') {
                 $value = strtolower($value);
             }
         }
         switch ($name) {
             case 'position':
                 if ($value !== self::STANDARD and $value !== self::RIGHT and $value !== self::LEFT) {
                     throw new Exception\InvalidArgumentException("Unknown position '" . $value . "'");
                 }
                 break;
             case 'format':
                 if (empty($value) === false and Locale\Locale::isLocale($value) === false) {
                     if (!is_string($value) || strpos($value, '0') === false) {
                         throw new Exception\InvalidArgumentException('\'' . (gettype($value) === 'object' ? get_class($value) : $value) . '\' is no format token');
                     }
                 }
                 break;
             case 'display':
                 if (is_numeric($value) and $value !== self::NO_SYMBOL and $value !== self::USE_SYMBOL and $value !== self::USE_SHORTNAME and $value !== self::USE_NAME) {
                     throw new Exception\InvalidArgumentException("Unknown display '{$value}'");
                 }
                 break;
             case 'precision':
                 if ($value === null) {
                     $value = -1;
                 }
                 if ($value < -1 or $value > 30) {
                     throw new Exception\InvalidArgumentException("'{$value}' precision has to be between -1 and 30.");
                 }
                 break;
             case 'script':
                 try {
                     Locale\Format::convertNumerals(0, $options['script']);
                 } catch (Locale\Exception $e) {
                     throw new Exception\InvalidArgumentException($e->getMessage());
                 }
                 break;
             default:
                 break;
         }
     }
     return $options;
 }
示例#2
0
 /**
  * test toNumberSystem
  * expected string
  */
 public function testToNumberSystem()
 {
     try {
         $value = Format::convertNumerals('١١٠', 'xxxx');
         $this->fail("no conversion expected");
     } catch (InvalidArgumentException $e) {
         // success
     }
     try {
         $value = Format::convertNumerals('١١٠', 'Arab', 'xxxx');
         $this->fail("no conversion expected");
     } catch (InvalidArgumentException $e) {
         // success
     }
     $this->assertEquals('110', Format::convertNumerals('١١٠', 'Arab'));
     $this->assertEquals('११०', Format::convertNumerals('١١٠', 'Arab', 'Deva'));
     $this->assertEquals('११०', Format::convertNumerals('١١٠', 'arab', 'dEVa'));
     $this->assertEquals('١١٠', Format::convertNumerals('110', 'Latn', 'Arab'));
     $this->assertEquals('١١٠', Format::convertNumerals('110', 'latn', 'Arab'));
 }