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

master
Rinsvent 3 years ago
parent 88303bb058
commit eb128bda28
  1. 14
      src/Transformer/DateTimeFormat.php
  2. 18
      src/Transformer/DateTimeFormatTransformer.php

@ -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());
}
}

@ -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);
}
}
Loading…
Cancel
Save