Symfony\Component\Validator\ConstraintValidator::formatValue PHP Метод

formatValue() защищенный Метод

This method returns the equivalent PHP tokens for most scalar types (i.e. "false" for false, "1" for 1 etc.). Strings are always wrapped in double quotes ("). Objects, arrays and resources are formatted as "object", "array" and "resource". If the $format bitmask contains the PRETTY_DATE bit, then {@link \DateTime} objects will be formatted as RFC-3339 dates ("Y-m-d H:i:s"). Be careful when passing message parameters to a constraint violation that (may) contain objects, arrays or resources. These parameters should only be displayed for technical users. Non-technical users won't know what an "object", "array" or "resource" is and will be confused by the violation message.
protected formatValue ( mixed $value, integer $format ) : string
$value mixed The value to format as string
$format integer A bitwise combination of the format constants in this class
Результат string The string representation of the passed value
    protected function formatValue($value, $format = 0)
    {
        $isDateTime = $value instanceof \DateTimeInterface;
        if ($format & self::PRETTY_DATE && $isDateTime) {
            if (class_exists('IntlDateFormatter')) {
                $locale = \Locale::getDefault();
                $formatter = new \IntlDateFormatter($locale, \IntlDateFormatter::MEDIUM, \IntlDateFormatter::SHORT);
                // neither the native nor the stub IntlDateFormatter support
                // DateTimeImmutable as of yet
                if (!$value instanceof \DateTime) {
                    $value = new \DateTime($value->format('Y-m-d H:i:s.u e'), $value->getTimezone());
                }
                return $formatter->format($value);
            }
            return $value->format('Y-m-d H:i:s');
        }
        if (is_object($value)) {
            if ($format & self::OBJECT_TO_STRING && method_exists($value, '__toString')) {
                return $value->__toString();
            }
            return 'object';
        }
        if (is_array($value)) {
            return 'array';
        }
        if (is_string($value)) {
            return '"' . $value . '"';
        }
        if (is_resource($value)) {
            return 'resource';
        }
        if (null === $value) {
            return 'null';
        }
        if (false === $value) {
            return 'false';
        }
        if (true === $value) {
            return 'true';
        }
        return (string) $value;
    }