diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d49142..1f265f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [0.17.3] - 2020-02-17 +### Added +- Add Trait `PlatformDtoTrait` +- Add Functions `importFromRequest` and `importFromArray` in `PlatformDtoTrait` + ## [0.17.2] - 2020-02-13 ### Added - Add Function `getValuesByKey` and `getValuesByKeys` in `RequestUtils` diff --git a/lib/Base/AdminBaseDto.php b/lib/Base/AdminBaseDto.php index e4eff35..f0b66c9 100644 --- a/lib/Base/AdminBaseDto.php +++ b/lib/Base/AdminBaseDto.php @@ -8,6 +8,7 @@ /** * 이 클래스는 "상속받은 클래스가 DTO" 임을 의미하고, 이와 관련된 최소한의 정보만 다룬다. + * @deprecated AdminBaseDto */ class AdminBaseDto { diff --git a/lib/Base/PlatformDtoTrait.php b/lib/Base/PlatformDtoTrait.php new file mode 100644 index 0000000..d5b4877 --- /dev/null +++ b/lib/Base/PlatformDtoTrait.php @@ -0,0 +1,42 @@ +getProperties(ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED); + foreach ($properties as $property) { + $property->setValue($this, $request->get($property->getName())); + } + } + + /** + * 배열을 이용하여 클래스를 초기화한다 + * @param array $array + * + * @throws \Exception + */ + public function importFromArray(array $array): void + { + $reflect = new ReflectionClass(get_called_class()); + $properties = $reflect->getDefaultProperties(); + foreach ($properties as $key => $value) { + if (array_key_exists($key, $array)) { + $this->{$key} = $array[$key]; + } + } + } +}