芝麻web文件管理V1.00
编辑当前文件:/home/fambnfli/www/tr/wp-content/plugins/duplicator/src/Utils/UsageStatistics/StatsUtil.php
$data Data * @param array
$rules Rules * * @return array
*/ public static function sanitizeFields($data, $rules) { foreach ($data as $key => $val) { if (!isset($rules[$key])) { continue; } $matches = null; if (preg_match('/(\??)(int|float|bool|string)(?:\|max:(\d+))?/', $rules[$key], $matches) !== 1) { throw new Exception("Invalid sanitize rule: {$rules[$key]}"); } $nullable = $matches[1] === '?'; $type = $matches[2]; $max = isset($matches[3]) ? (int) $matches[3] : PHP_INT_MAX; if ($nullable && $val === null) { continue; } switch ($type) { case 'int': $data[$key] = (int) $val; break; case 'float': $data[$key] = (float) $val; break; case 'bool': $data[$key] = (bool) $val; break; case 'string': $data[$key] = substr((string) $val, 0, $max); break; default: throw new Exception("Unknown sanitize rule: {$rules[$key]}"); } } return $data; } }