feat: DTO에 toArrayExcept 추가

This commit is contained in:
2022-06-04 21:29:47 +09:00
parent 39be8fa4b8
commit acccb74b4e
+14
View File
@@ -153,4 +153,18 @@ abstract class DTO
}
return $result;
}
public function toArrayExcept(string ...$keys): array{
$reflection = new \ReflectionClass($this::class);
$values = $this->toArray();
foreach($keys as $key){
if(!$reflection->hasProperty($key)){
throw new \Exception("Key {$key} does not exist");
}
if(key_exists($key, $values)){
unset($values[$key]);
}
}
return $values;
}
}