feat: 직접 작성한 DTO

This commit was merged in pull request #220.
This commit is contained in:
2022-05-22 16:53:56 +09:00
parent cb5cb68bf4
commit 43a5162a15
11 changed files with 800 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
<?php
namespace sammo\DTO\Attr;
use sammo\DTO\Converter\Converter;
#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_CLASS)]
class Convert
{
public Converter $converter;
public function __construct(
public readonly array $targetTypes,
public readonly string $converterType,
array ...$args
) {
if(!is_subclass_of($converterType, \sammo\DTO\Converter\Converter::class)){
throw new \Exception("$converterType is not a subclass of \sammo\DTO\Converter\Converter");
}
$this->converter = new $converterType($targetTypes, ...$args);
}
public function convertFrom(string|array|int|float|bool|null $raw): mixed
{
return $this->converter->convertFrom($raw);
}
public function convertTo(mixed $target): string|array|int|float|bool|null {
return $this->converter->convertTo($target);
}
}