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

Commit

Permalink
## [0.17.2] - 2020-02-12
Browse files Browse the repository at this point in the history
### Added
- Add Function `getValuesByKey` and `getValuesByKeys` in `RequestUtils`
  • Loading branch information
문정기 committed Feb 13, 2020
1 parent aed431a commit f2fe672
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ 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.2] - 2020-02-13
### Added
- Add Function `getValuesByKey` and `getValuesByKeys` in `RequestUtils`

## [0.17.1] - 2020-02-12
### Fixed
- Fix Function Params to be more flexible in `SsmService`
Expand Down
42 changes: 42 additions & 0 deletions lib/Util/RequestUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,46 @@ public static function getAllParams(Request $request): array
// Request::get 의 검색 순서대로 merge 하기 위해 역순으로 배치
return array_merge($request->request->all(), $request->attributes->all(), $request->query->all());
}

public static function getValuesByKey(Request $request, string $key): array
{
$request_params = self::getContent($request);

return self::getValuesFromContent($request_params, $key);
}

public static function getValuesByKeys(Request $request, array $keys): array
{
$request_params = self::getContent($request);

$result = [];

foreach ($keys as $key) {
$result[$key] = self::getValuesFromContent($request_params, $key);
}

return $result;
}

private static function getValuesFromContent(array $request_params, string $key): array
{
$values = [];
if (isset($request_params[$key])) {
$values = $request_params[$key];
if (is_string($values) && !StringUtils::isEmpty($values)) {
// , 구분 일 경우
$values = str_replace(['"', "'", ' '], '', $values);
$values = explode(',', $values);
} elseif (is_array($values) && !empty($values)) {
// array 로 넘어왔을 경우
$values = collect($values)
->map(function ($value) {
return str_replace(['"', "'", ' '], '', $value);
})
->all();
}
}

return $values;
}
}

0 comments on commit f2fe672

Please sign in to comment.