You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
payment/app/Helper/Param.php

57 lines
1.4 KiB
PHTML

2 years ago
<?php
declare(strict_types=1);
namespace App\Helper;
class Param
{
public const EMPTY_VALUES = ['', null];
public const ZERO_VALUES = [0, '0', '', null];
/**
* params是否存在key键若key对应的值存在于emptyValues中则也认为不存在
*/
public static function has(array $params, $key, array $emptyValues = self::EMPTY_VALUES): bool
{
if (isset($params[$key])) {
foreach ($emptyValues as $value) {
if ($params[$key] === $value) {
return false;
}
}
return true;
}
return false;
}
public static function require(array $params, array $requireKeys): array
{
$requireParams = [];
foreach ($requireKeys as $key) {
$requireParams[$key] = $params[$key] ?? null;
}
return $requireParams;
}
public static function default(array $params, array $defaults): array
{
foreach ($defaults as $key => $value) {
if (!isset($params[$key])) {
$params[$key] = $value;
}
}
return $params;
}
public static function remove(array $params, array $removeKeys): array
{
foreach ($removeKeys as $key) {
if (isset($params[$key])) {
unset($params[$key]);
}
}
return $params;
}
}