From acccb74b4ebe7d04134f963d063a4914a418e9c7 Mon Sep 17 00:00:00 2001 From: Hide_D Date: Sat, 4 Jun 2022 20:58:25 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20DTO=EC=97=90=20toArrayExcept=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/sammo/DTO/DTO.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/sammo/DTO/DTO.php b/src/sammo/DTO/DTO.php index 1dfb3dd2..45cae1ca 100644 --- a/src/sammo/DTO/DTO.php +++ b/src/sammo/DTO/DTO.php @@ -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; + } }