floor를 intdiv로 변경
This commit is contained in:
+26
-27
@@ -3,40 +3,40 @@ namespace sammo;
|
||||
|
||||
class Util extends \utilphp\util
|
||||
{
|
||||
|
||||
private static function _parseReq($value, string $type){
|
||||
if(is_array($value)){
|
||||
if($type === 'array_int'){
|
||||
private static function _parseReq($value, string $type)
|
||||
{
|
||||
if (is_array($value)) {
|
||||
if ($type === 'array_int') {
|
||||
return array_map('intval', $value);
|
||||
}
|
||||
|
||||
if($type === 'array_string'){
|
||||
return array_map(function($item){
|
||||
if ($type === 'array_string') {
|
||||
return array_map(function ($item) {
|
||||
return (string)$item;
|
||||
}, $value);
|
||||
}
|
||||
|
||||
if($type === 'array'){
|
||||
if ($type === 'array') {
|
||||
return $value;
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException('지원할 수 없는 type 지정. array 가 붙은 type이어야 합니다');
|
||||
}
|
||||
|
||||
if($type === 'bool'){
|
||||
if ($type === 'bool') {
|
||||
$value = strtolower($value);
|
||||
if($value === 'false' || $value === 'no' || $value === 'n' || $value === 'x' || $value === 'null'){
|
||||
if ($value === 'false' || $value === 'no' || $value === 'n' || $value === 'x' || $value === 'null') {
|
||||
return false;
|
||||
}
|
||||
return !!$value;
|
||||
}
|
||||
if($type === 'int'){
|
||||
if ($type === 'int') {
|
||||
return (int)$value;
|
||||
}
|
||||
if($type === 'float'){
|
||||
if ($type === 'float') {
|
||||
return (float)$value;
|
||||
}
|
||||
if($type === 'string'){
|
||||
if ($type === 'string') {
|
||||
return (string)$value;
|
||||
}
|
||||
|
||||
@@ -44,23 +44,22 @@ class Util extends \utilphp\util
|
||||
}
|
||||
|
||||
/**
|
||||
* $_GET, $_POST에서 값을 가져오는 함수. Util::array_get($_POST[$name])을 축약 가능.
|
||||
* $_POST, $_GET에서 값을 가져오는 함수. Util::array_get($_POST[$name])을 축약 가능.
|
||||
* 타입이 복잡해질 경우 이 함수를 통하지 않고 json으로 요청할 것을 권장.
|
||||
*
|
||||
*
|
||||
* @param string $name 가져오고자 하는 key 이름.
|
||||
* @param string $type 가져오고자 하는 type. [string, int, float, bool, array, array_string, array_int]
|
||||
* @param mixed $ifNotExists 만약 $_GET과 $_POST에 값이 없을 경우 반환하는 변수. 이 값은 $type을 검사하지 않음.
|
||||
* @param mixed $ifNotExists 만약 $_POST와 $_GET에 값이 없을 경우 반환하는 변수. 이 값은 $type을 검사하지 않음.
|
||||
* @return int|float|string|array|null
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public static function getReq(string $name, string $type = 'string', $ifNotExists = null){
|
||||
if(isset($_GET[$name])){
|
||||
$value = $_GET[$name];
|
||||
}
|
||||
else if(isset($_POST[$name])){
|
||||
public static function getReq(string $name, string $type = 'string', $ifNotExists = null)
|
||||
{
|
||||
if (isset($_POST[$name])) {
|
||||
$value = $_POST[$name];
|
||||
}
|
||||
else{
|
||||
} elseif (isset($_GET[$name])) {
|
||||
$value = $_GET[$name];
|
||||
} else {
|
||||
return $ifNotExists;
|
||||
}
|
||||
|
||||
@@ -70,18 +69,18 @@ class Util extends \utilphp\util
|
||||
/**
|
||||
* $_POST에서 값을 가져오는 함수. Util::array_get($_POST[$name])을 축약 가능. $_GET에서도 가져올 수 있다면 getReq 사용.
|
||||
* 타입이 복잡해질 경우 이 함수를 통하지 않고 json으로 요청할 것을 권장.
|
||||
*
|
||||
*
|
||||
* @param string $name 가져오고자 하는 key 이름.
|
||||
* @param string $type 가져오고자 하는 type. [string, int, float, bool, array, array_string, array_int]
|
||||
* @param mixed $ifNotExists 만약 $_GET과 $_POST에 값이 없을 경우 반환하는 변수. 이 값은 $type을 검사하지 않음.
|
||||
* @return int|float|string|array|null
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public static function getPost(string $name, string $type = 'string', $ifNotExists = null){
|
||||
if(isset($_POST[$name])){
|
||||
public static function getPost(string $name, string $type = 'string', $ifNotExists = null)
|
||||
{
|
||||
if (isset($_POST[$name])) {
|
||||
$value = $_POST[$name];
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
return $ifNotExists;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user