Neos\Flow\I18n\Cldr\Reader\NumbersReader::parseFormatFromCldr PHP Method

parseFormatFromCldr() public method

When third parameter ($formatLength) equals 'default', default format for a locale will be used.
public parseFormatFromCldr ( Locale $locale, string $formatType, string $formatLength = self::FORMAT_LENGTH_DEFAULT ) : array
$locale Neos\Flow\I18n\Locale
$formatType string A type of format (one of constant values)
$formatLength string A length of format (one of constant values)
return array An array representing parsed format
    public function parseFormatFromCldr(Locale $locale, $formatType, $formatLength = self::FORMAT_LENGTH_DEFAULT)
    {
        self::validateFormatType($formatType);
        self::validateFormatLength($formatLength);
        if (isset($this->parsedFormatsIndices[(string) $locale][$formatType][$formatLength])) {
            return $this->parsedFormats[$this->parsedFormatsIndices[(string) $locale][$formatType][$formatLength]];
        }
        if ($formatLength === self::FORMAT_LENGTH_DEFAULT) {
            $formatPath = 'numbers/' . $formatType . 'Formats/' . $formatType . 'FormatLength/' . $formatType . 'Format/pattern';
        } else {
            $formatPath = 'numbers/' . $formatType . 'Formats/' . $formatType . 'FormatLength[@type="' . $formatLength . '"]/' . $formatType . 'Format/pattern';
        }
        $model = $this->cldrRepository->getModelForLocale($locale);
        $format = $model->getElement($formatPath);
        if (empty($format)) {
            throw new Exception\UnableToFindFormatException('Number format was not found. Please check whether CLDR repository is valid.', 1280218995);
        }
        $parsedFormat = $this->parseFormat($format);
        $this->parsedFormatsIndices[(string) $locale][$formatType][$formatLength] = $format;
        return $this->parsedFormats[$format] = $parsedFormat;
    }

Usage Example

 /**
  * Formats number with format string for currency defined in CLDR for
  * particular locale.
  *
  * Currency symbol provided will be inserted into formatted number string.
  *
  * Note: currently length is not used in currencyFormats from CLDR.
  * But it's defined in the specification, so we support it here.
  *
  * @param mixed $number Float or int, can be negative, can be NaN or infinite
  * @param Locale $locale
  * @param string $currency Currency symbol (or name)
  * @param string $formatLength One of NumbersReader FORMAT_LENGTH constants
  * @return string Formatted number. Will return string-casted version of $number if there is no pattern for given $locale / $formatLength
  * @api
  */
 public function formatCurrencyNumber($number, Locale $locale, $currency, $formatLength = NumbersReader::FORMAT_LENGTH_DEFAULT)
 {
     NumbersReader::validateFormatLength($formatLength);
     return $this->doFormattingWithParsedFormat($number, $this->numbersReader->parseFormatFromCldr($locale, NumbersReader::FORMAT_TYPE_CURRENCY, $formatLength), $this->numbersReader->getLocalizedSymbolsForLocale($locale), $currency);
 }
All Usage Examples Of Neos\Flow\I18n\Cldr\Reader\NumbersReader::parseFormatFromCldr