refac: DTO 구조 변경

- Converter - Constructor 관련 경고 수정
- JsonString 관련 의존성 제거, jsonFlag 지정
- DateTimeConveter에서 time format 지정
This commit is contained in:
2022-05-29 00:44:28 +09:00
parent 7464629597
commit 35b178fe3c
10 changed files with 96 additions and 98 deletions
+17 -3
View File
@@ -8,23 +8,37 @@ use sammo\DTO\Converter\Converter;
class Convert
{
public Converter $converter;
public array $targetTypes;
public readonly array $args;
public function __construct(
public readonly array $targetTypes,
public readonly string $converterType,
...$args
) {
if(!is_subclass_of($converterType, \sammo\DTO\Converter\Converter::class)){
throw new \Exception("$converterType is not a subclass of \sammo\DTO\Converter\Converter");
throw new \Exception("$converterType is not a subclass of DTO\Converter\Converter");
}
$this->converter = new $converterType($targetTypes, ...$args);
$this->args = $args;
}
public function setType(array $targetTypes): self{
$this->targetTypes = $targetTypes;
$converterType = $this->converterType;
$this->converter = new $converterType($targetTypes, ...$this->args);
return $this;
}
public function convertFrom(string|array|int|float|bool|null $raw): mixed
{
if($this->converter === null){
throw new \Exception('converter is not set');
}
return $this->converter->convertFrom($raw);
}
public function convertTo(mixed $target): string|array|int|float|bool|null {
if($this->converter === null){
throw new \Exception('converter is not set');
}
return $this->converter->convertTo($target);
}
}