src/Leevel/Http/Bag.php
protected function filterValueWithFunc($value, string $filter)
    {
        list($filter, $extend) = explode('=', $filter);

        if ('default' === $filter) {
            if (!is_numeric($extend) && !preg_match('/^[A-Z\_]+$/', $extend)) {
                $extend = "'".$extend."'";
            }

            $evals = "\$value = '".($value ? '1' : '')."' ?: ".$extend.';';
        } elseif ($extend) {
            if (false !== strpos($extend, ',')) {
                $tmp = explode(',', $extend);
                $result = [];

                foreach ($tmp as $v) {
                    $v = trim($v);

                    if ('**' === $v || is_numeric($v) || preg_match('/^[A-Z\_]+$/', $v)) {
                        $result[] = $v;
                    } else {
                        $result[] = "'".$v."'";
                    }
                }

                $extend = implode(',', $result);
            }

            if (strstr($extend, '**')) {
                $extend = str_replace('**', '$value', $extend);
                $evals = "\$value = {$filter}({$extend});";
            } else {
                $evals = "\$value = {$filter}(\$value, {$extend});";
            }
        }

        eval($evals);

        return $value;
    }
protected function filterValueWithFunc($value, string $filter)
    {
        list($filter, $extend) = explode('=', $filter);

        if ('default' === $filter) {
            if (!is_numeric($extend) && !preg_match('/^[A-Z\_]+$/', $extend)) {
                $extend = "'".$extend."'";
            }

            $evals = "\$value = '".($value ? '1' : '')."' ?: ".$extend.';';
        } elseif ($extend) {
            if (false !== strpos($extend, ',')) {
                $tmp = explode(',', $extend);
                $result = [];

                foreach ($tmp as $v) {
                    $v = trim($v);

                    if ('**' === $v || is_numeric($v) || preg_match('/^[A-Z\_]+$/', $v)) {
                        $result[] = $v;
                    } else {
                        $result[] = "'".$v."'";
                    }
                }

                $extend = implode(',', $result);
            }

            if (strstr($extend, '**')) {
                $extend = str_replace('**', '$value', $extend);
                $evals = "\$value = {$filter}({$extend});";
            } else {
                $evals = "\$value = {$filter}(\$value, {$extend});";
            }
        }

        eval($evals);

        return $value;
    }
使用函数过滤值

@param mixed  $value
@param string $filter

@return mixed