refac: DTO 구조 변경
- Converter - Constructor 관련 경고 수정 - JsonString 관련 의존성 제거, jsonFlag 지정 - DateTimeConveter에서 time format 지정
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user