Skip to content
This repository has been archived by the owner on Nov 29, 2022. It is now read-only.

Commit

Permalink
## [0.17.3] - 2020-02-17
Browse files Browse the repository at this point in the history
### Added
- Add Trait `PlatformDtoTrait`
- Add Functions `importFromRequest` and `importFromArray` in `PlatformDtoTrait`
  • Loading branch information
문정기 committed Feb 17, 2020
1 parent f2fe672 commit c28e17d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
1 change: 1 addition & 0 deletions lib/Base/AdminBaseDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/**
* 이 클래스는 "상속받은 클래스가 DTO" 임을 의미하고, 이와 관련된 최소한의 정보만 다룬다.
* @deprecated AdminBaseDto
*/
class AdminBaseDto
{
Expand Down
42 changes: 42 additions & 0 deletions lib/Base/PlatformDtoTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Ridibooks\Platform\Common\Base;

use ReflectionClass;
use ReflectionProperty;
use Symfony\Component\HttpFoundation\Request;

trait PlatformDtoTrait
{
/**
* Request class를 이용하여 클래스를 초기화한다.
* @param Request $request
*
* @throws \ReflectionException
*/
public function importFromRequest(Request $request): void
{
$reflect = new ReflectionClass(get_called_class());
$properties = $reflect->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];
}
}
}
}

0 comments on commit c28e17d

Please sign in to comment.