/
githubmirror
/
symfony
Обзор
Документация
Войти
/
githubmirror
/
symfony
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
8.2
src/Symfony/Component/JsonStreamer/ValueTransformer/DateTimeToStringValueTransformer.php
49 строк
2 KB
Mathias Arlaud
[JsonStreamer] Handle value objects
06 мар 2026, 17:50
06 мар 2026, 17:50
8cf1714
Код
Авторство
О чём код?
<?php /* * This file is part of the Symfony package. * * (c) Fabien Potencier <fabien@symfony.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\JsonStreamer\ValueTransformer; use Symfony\Component\JsonStreamer\Exception\InvalidArgumentException; use Symfony\Component\JsonStreamer\Transformer\DateTimeValueObjectTransformer; use Symfony\Component\TypeInfo\Type; use Symfony\Component\TypeInfo\Type\BuiltinType; use Symfony\Component\TypeInfo\TypeIdentifier; trigger_deprecation('symfony/json-streamer', '8.1', 'The "%s" class is deprecated. Date times will be transformed thanks to "%s" instead.', DateTimeToStringValueTransformer::class, DateTimeValueObjectTransformer::class); /** * Transforms DateTimeInterface to string during stream writing. * * @author Mathias Arlaud <mathias.arlaud@gmail.com> * * @deprecated since Symfony 8.1, date times will be transformed thanks to DateTimeValueObjectTransformer instead */ final class DateTimeToStringValueTransformer implements ValueTransformerInterface { public const FORMAT_KEY = 'date_time_format'; public function transform(mixed $value, array $options = []): string { if (!$value instanceof \DateTimeInterface) { throw new InvalidArgumentException('The native value must implement the "\DateTimeInterface".'); } return $value->format($options[self::FORMAT_KEY] ?? \DateTimeInterface::RFC3339); } /** * @return BuiltinType<TypeIdentifier::STRING> */ public static function getStreamValueType(): BuiltinType { return Type::string(); } }