Добавил форматер даты
This commit is contained in:
parent
88303bb058
commit
eb128bda28
14
src/Transformer/DateTimeFormat.php
Normal file
14
src/Transformer/DateTimeFormat.php
Normal 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());
|
||||
}
|
||||
}
|
18
src/Transformer/DateTimeFormatTransformer.php
Normal file
18
src/Transformer/DateTimeFormatTransformer.php
Normal 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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user