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

validateFormatType() публичный статический Метод

Validates provided format type and throws exception if value is not allowed.
public static validateFormatType ( string $formatType ) : void
$formatType string
Результат void
    public static function validateFormatType($formatType)
    {
        if (!in_array($formatType, [self::FORMAT_TYPE_DATE, self::FORMAT_TYPE_TIME, self::FORMAT_TYPE_DATETIME])) {
            throw new Exception\InvalidFormatTypeException('Provided formatType, "' . $formatType . '", is not one of allowed values.', 1281442590);
        }
    }

Usage Example

 /**
  * Formats provided value using optional style properties
  *
  * @param mixed $value Formatter-specific variable to format (can be integer, \DateTime, etc)
  * @param Locale $locale Locale to use
  * @param array $styleProperties Integer-indexed array of formatter-specific style properties (can be empty)
  * @return string String representation of $value provided, or (string)$value
  * @api
  */
 public function format($value, Locale $locale, array $styleProperties = [])
 {
     if (isset($styleProperties[0])) {
         $formatType = $styleProperties[0];
         DatesReader::validateFormatType($formatType);
     } else {
         $formatType = DatesReader::FORMAT_TYPE_DATETIME;
     }
     if (isset($styleProperties[1])) {
         $formatLength = $styleProperties[1];
         DatesReader::validateFormatLength($formatLength);
     } else {
         $formatLength = DatesReader::FORMAT_LENGTH_DEFAULT;
     }
     switch ($formatType) {
         case DatesReader::FORMAT_TYPE_DATE:
             return $this->formatDate($value, $locale, $formatLength);
         case DatesReader::FORMAT_TYPE_TIME:
             return $this->formatTime($value, $locale, $formatLength);
         default:
             return $this->formatDateTime($value, $locale, $formatLength);
     }
 }