Neos\Flow\I18n\Cldr\Reader\DatesReader::parseFormatFromCldr PHP Метод

parseFormatFromCldr() публичный Метод

When third parameter ($formatLength) equals 'default', default format for a locale will be used.
public parseFormatFromCldr ( Locale $locale, string $formatType, string $formatLength ) : 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)
Результат array An array representing parsed format
    public function parseFormatFromCldr(Locale $locale, $formatType, $formatLength)
    {
        self::validateFormatType($formatType);
        self::validateFormatLength($formatLength);
        if (isset($this->parsedFormatsIndices[(string) $locale][$formatType][$formatLength])) {
            return $this->parsedFormats[$this->parsedFormatsIndices[(string) $locale][$formatType][$formatLength]];
        }
        $model = $this->cldrRepository->getModelForLocale($locale);
        if ($formatLength === 'default') {
            // the default thing only has an attribute. ugly fetch code. was a nice three-liner before 2011-11-21
            $formats = $model->getRawArray('dates/calendars/calendar[@type="gregorian"]/' . $formatType . 'Formats');
            foreach (array_keys($formats) as $k) {
                $realFormatLength = CldrModel::getAttributeValue($k, 'choice');
                if ($realFormatLength !== false) {
                    break;
                }
            }
        } else {
            $realFormatLength = $formatLength;
        }
        $format = $model->getElement('dates/calendars/calendar[@type="gregorian"]/' . $formatType . 'Formats/' . $formatType . 'FormatLength[@type="' . $realFormatLength . '"]/' . $formatType . 'Format/pattern');
        if (empty($format)) {
            throw new Exception\UnableToFindFormatException('Date / time format was not found. Please check whether CLDR repository is valid.', 1280218994);
        }
        if ($formatType === 'dateTime') {
            // DateTime is a simple format like this: '{0} {1}' which denotes where to insert date and time
            $parsedFormat = $this->prepareDateAndTimeFormat($format, $locale, $formatLength);
        } else {
            $parsedFormat = $this->parseFormat($format);
        }
        $this->parsedFormatsIndices[(string) $locale][$formatType][$formatLength] = $format;
        return $this->parsedFormats[$format] = $parsedFormat;
    }

Usage Example

 /**
  * Formats dateTime with format string for date and time defined in CLDR for
  * particular locale.
  *
  * First date and time are formatted separately, and then dateTime format
  * from CLDR is used to place date and time in correct order.
  *
  * @param \DateTimeInterface $dateTime PHP object representing particular point in time
  * @param Locale $locale
  * @param string $formatLength One of DatesReader FORMAT_LENGTH constants
  * @return string Formatted date and time
  * @api
  */
 public function formatDateTime(\DateTimeInterface $dateTime, Locale $locale, $formatLength = DatesReader::FORMAT_LENGTH_DEFAULT)
 {
     DatesReader::validateFormatLength($formatLength);
     return $this->doFormattingWithParsedFormat($dateTime, $this->datesReader->parseFormatFromCldr($locale, DatesReader::FORMAT_TYPE_DATETIME, $formatLength), $this->datesReader->getLocalizedLiteralsForLocale($locale));
 }
All Usage Examples Of Neos\Flow\I18n\Cldr\Reader\DatesReader::parseFormatFromCldr