Добавил форматер даты

This commit is contained in:
Rinsvent 2021-11-06 15:22:28 +07:00
parent 88303bb058
commit eb128bda28
2 changed files with 32 additions and 0 deletions

View File

@ -0,0 +1,14 @@
<?php
namespace Rinsvent\DTO2Data\Transformer;
#[\Attribute(\Attribute::TARGET_ALL|\Attribute::IS_REPEATABLE)]
class DateTimeFormat extends Meta
{
public function __construct(
public array $tags = ['default'],
public string $format = \DateTimeInterface::ATOM
) {
parent::__construct(...func_get_args());
}
}

View File

@ -0,0 +1,18 @@
<?php
namespace Rinsvent\DTO2Data\Transformer;
class DateTimeFormatTransformer implements TransformerInterface
{
/**
* @param \DateTimeImmutable|\DateTime|null $data
* @param DateTimeFormat $meta
*/
public function transform(&$data, Meta $meta): void
{
if ($data === null) {
return;
}
$data = $data->format($meta->format);
}
}