예제 #1
-1
 public function testThatCurrentCultureCanBeChanged()
 {
     $this->languageManager->addCulture('en-US-Super', new TestLanguage_enUS());
     $firstValue = $this->languageManager->currentCulture();
     $this->languageManager->setCulture('en-US-Super');
     $secondValue = $this->languageManager->currentCulture();
     $this->assertNotSame($firstValue, $secondValue);
     $this->assertInstanceOf(Language_enUS::class, $firstValue);
     $this->assertInstanceOf(TestLanguage_enUS::class, $secondValue);
 }
예제 #2
-1
 /**
  * Converts a string-based number into a usable number.
  *
  * @param $string
  *
  * @return float|int|null|number
  */
 public function unformat($string)
 {
     $originalString = $this->decode($string);
     $string = $this->decode($string);
     if (is_numeric($string)) {
         return $string;
     }
     if ($this->stringContains($string, ':')) {
         return $this->unformatTime($string);
     } else {
         if ($this->isZero($string)) {
             return 0;
         } else {
             $string = $this->normalizeDecimalSymbol($string);
             $bytesMultiplier = null;
             $abbreviations = $this->languageManager->currentCulture()->getAbbreviations();
             $currencySymbol = $this->languageManager->currentCulture()->getCurrency()['symbol'];
             // This seems to get rid of an error that appears. The error message is
             // \k is not followed by a braced, angle-bracketed, or quoted name at offset x
             $regexCurrencySymbol = implode('\\', str_split($currencySymbol));
             if ($this->stringStartsWith($regexCurrencySymbol, 'k')) {
                 $regexCurrencySymbol = '\\' . $regexCurrencySymbol;
             }
             for ($power = 0; $power < count($this->binarySuffixes) && !$bytesMultiplier; $power++) {
                 if ($this->stringContains($string, $this->binarySuffixes[$power])) {
                     $bytesMultiplier = pow(1024, $power + 1);
                 } else {
                     if ($this->stringContains($string, $this->suffixes[$power])) {
                         $bytesMultiplier = pow(1000, $power + 1);
                     }
                 }
             }
             // Remove currency symbol from the original format.
             $originalString = strtr($originalString, [$currencySymbol => '']);
             $value = $bytesMultiplier ? $bytesMultiplier : 1;
             // We want to sort the abbreviations by most specific first and then
             // do the abbreviations check. For a language use-case, see the
             // unformat tests for pt-BR.
             uasort($abbreviations, function ($a, $b) {
                 return mb_strlen($b) - mb_strlen($a);
             });
             foreach ($abbreviations as $name => $abbreviation) {
                 $regex = '/[^a-zA-Z]' . $abbreviation . '(?:\\)|(\\' . $regexCurrencySymbol . ')?(?:\\))?)?/';
                 if (preg_match($regex, $originalString)) {
                     switch ($name) {
                         case 'thousand':
                             $value *= pow(10, 3);
                             break;
                         case 'million':
                             $value *= pow(10, 6);
                             break;
                         case 'billion':
                             $value *= pow(10, 9);
                             break;
                         case 'trillion':
                             $value *= pow(10, 12);
                             break;
                     }
                     break;
                 }
             }
             $value *= ($this->stringContains($originalString, '%') ? 0.01 : 1) * ($this->isNegativeNumber($string) ? -1 : 1) * $this->toFloat(preg_replace('/[^0-9\\.]/', '', $string));
             $value = $bytesMultiplier ? ceil($value) : $value;
             return $value;
         }
     }
 }