真正反序列化

@param string $data 待反序列化数据
@return mixed|string
425425
private function realUnserialize($data)
    {
        //get
        if (is_string($data) && $this->redisSerialize) {
            switch ($this->redisSerialize) {
                case Macro::SERIALIZE_PHP:
                    if ($this->canUnserialize($data)) {
                        $data = unserialize($data);
                    }
                    break;
                case Macro::SERIALIZE_IGBINARY:
                    $data = @igbinary_unserialize($data);
                    break;
            }
        }

        if (is_string($data) && $this->phpSerialize) {
            switch ($this->phpSerialize) {
                case Macro::SERIALIZE_PHP:
                    if ($this->canUnserialize($data)) {
                        $data = unserialize($data);
                    }
                    break;
                case Macro::SERIALIZE_IGBINARY:
                    $data = @igbinary_unserialize($data);
                    break;
            }

            //兼容yii逻辑
            if (is_array($data) && count($data) === 2 && array_key_exists(1, $data) && $data[1] === null) {
                $data = $data[0];
            }
        }
        return $data;
    }
497147
public function match($data)
    {
        $match = false;
        $operator = $this->getOperator();

        foreach ($this->getFilters() as $filter) {
            $match = $filter->match($data);

            if ((!$match && $operator === self::LOGICAL_AND)
                || ($match && $operator === self::LOGICAL_OR)
            ) {
                break;
            }
        }

        return $match;
    }
990114
public function create($data='') {
        // 如果没有传值默认取POST数据
        if(empty($data)) {
            $data   =   I('post.');
        }elseif(is_object($data)){
            $data   =   get_object_vars($data);
        }
        // 验证数据
        if(empty($data) || !is_array($data)) {
            $this->error = L('_DATA_TYPE_INVALID_');
            return false;
        }

        // 检测提交字段的合法性
        if(isset($this->options['field'])) { // $this->field('field1,field2...')->create()
            $fields =   $this->options['field'];
            unset($this->options['field']);
        }
        if(isset($fields)) {
            if(is_string($fields)) {
                $fields =   explode(',',$fields);
            }
        }

        // 验证完成生成数据对象
        if($this->autoCheckFields) { // 开启字段检测 则过滤非法字段数据
            $fields =   $this->getDbFields();
            foreach ($data as $key=>$val){
                if(!in_array($key,$fields)) {
                    unset($data[$key]);
                }elseif(MAGIC_QUOTES_GPC && is_string($val)){
                    $data[$key] =   stripslashes($val);
                }
            }
        }

        // 赋值当前数据对象
        $this->data =   $data;
        // 返回创建的数据以供其他调用
        return $data;
     }
583146
private function normalizeFloat($data) {
		if (is_infinite($data)) {
			$postfix = 'INF';
			if ($data < 0) {
				$postfix = '-' . $postfix;
			}
			$data = $postfix;
		} else {
			if (is_nan($data)) {
				$data = 'NaN';
			}
		}

		return $data;
	}
754833
public function automaticAuthenticator($data)
	{
		$alias = $data['authenticator'];
		$alias = strip_tags($alias);
		$alias = trim($alias);
		if (strlen($alias) > 255)
		{
			$alias = substr($alias . ' ', 0, 255);
			$alias = substr($alias, 0, strrpos($alias, ' '));
		}

		return preg_replace("/[^a-zA-Z0-9]/", '', strtolower($alias));
	}
896142
public function find($data = null)
    {
        if ($data instanceof Query) {
            return $data->find();
        } elseif ($data instanceof \Closure) {
            call_user_func_array($data, [ & $this]);
            $data = null;
        }
        // 分析查询表达式
        $options = $this->parseExpress();
        $pk      = $this->getPk($options);
        if (!is_null($data)) {
            // AR模式分析主键条件
            $this->parsePkWhere($data, $options);
        }

        $options['limit'] = 1;

        $key = '';
        // 生成查询SQL
        $sql = $this->builder->select($options);
        // 获取参数绑定
        $bind = $this->getBind();
        if ($options['fetch_sql']) {
            // 获取实际执行的SQL语句
            return $this->connection->getRealSql($sql, $bind);
        }
        if (is_string($pk)) {
            if (!is_array($data)) {
                if (isset($key) && strpos($key, '|')) {
                    list($a, $val) = explode('|', $key);
                    unset($a);
                    $item[$pk]     = $val;
                } else {
                    $item[$pk] = $data;
                }
                $data = $item;
            }
        }
        $options['data'] = $data;
        // 事件回调
        if ($result = $this->trigger('before_find', $options)) {
        } else {
            // 执行查询
            $resultSet = $this->query($sql, $bind, $options['master'], $options['fetch_pdo']);

            if ($resultSet instanceof \PDOStatement) {
                // 返回PDOStatement对象
                return $resultSet;
            }
            $result = isset($resultSet[0]) ? $resultSet[0] : null;
        }

        if (!empty($options['fail'])) {
            $this->throwNotFound($options);
        }
        return $result;
    }
612397
public function decode($data)
    {
        if ($data !== null) {
            $data = gzdecode((string) $data, $this->options['length']);
            if ($data === false) {
                $data = null;
                $this->error = error_get_last()['message'] ?? 'Unknown';
            }
        }

        return $data;
    }
1191790
public function compileData($data)
    {
        $setFragment    = [];
        $arguments      = [];
        foreach ($data as $key => $value) {
            $operator   = '=';
            if (isset($value['operator'])) {
                $operator = $value['operator'];
                unset($value['operator']);
            }
            $field      = $key;
            if (isset($value['field'])) {
                $field = $value['field'];
                unset($value['field']);
            }
            $value      = $value;
            if (isset($value['value'])) {
                $value = $value['value'];
                unset($value['value']);
            }
            //设置自定义set
            if (!isset($value['raw'])) {
                $setFragment[]  = "`{$field}` {$operator} ?";
                $arguments[]    = $value;
            } else {
                $setFragment[]  = "`{$field}` {$operator} {$value['raw']}";
                unset($value['raw']);
                is_array($value) ? null : $value = [$value];
                $arguments = ArrayLib::array_add($arguments, $value);
            }

        }
        $this->setString = implode(',', $setFragment);
        $this->arguments = $arguments;
        return [$setFragment, $arguments];
    }
1003335
protected function formatCallback($data)
    {
        if (\count($data) < 2) {
            return $data[0];
        }

        // simple auto or explicit placeholder
        if ($this->mode == self::MODE_INDEXED && $this->hasKey($data[1])) {
            $this->evaluateParam($data[1] || $this->pointer);
            return $this->getParam($data[1]);
        }

        // simple named, explicit placeholder
        elseif ($this->mode == self::MODE_NAMED && \strlen($data[1]) > 0 && $this->hasKey($data[1])) {
            $this->evaluateParam($data[1]);
            return $this->getParam($data[1]);
        }

        // keywords
        elseif (\preg_match('
            /
            ^
                @
                (class|classLong|method|methodLong|function|file|fileLong|dir|dirLong|line)
            $
            /x', $data[1], $match)
        ) {
            switch ($match[1]) {
                case 'classLong':
                    if (!$this->traceClass || !isset($this->traceClass['class'])) {
                        $msg = "Bad usage of @classLong keyword in {$this->traceFile['file']} on " .
                            "line {$this->traceFile['line']} (by m36\\StringFormatter)";
                        \trigger_error($msg, E_USER_WARNING);

                        return '';
                    }

                    return $this->traceClass['class'];
                case 'class':
                    if (!$this->traceClass || !isset($this->traceClass['class'])) {
                        $msg = "Bad usage of @class keyword in {$this->traceFile['file']} on " .
                            "line {$this->traceFile['line']} (by m36\\StringFormatter)";
                        \trigger_error($msg, E_USER_WARNING);

                        return '';
                    }

                    $cls = \explode('\\', $this->traceClass['class']);

                    return end($cls);
                case 'method':
                    if (!$this->traceClass || !isset($this->traceClass['class'])) {
                        $msg = "Bad usage of @method keyword in {$this->traceFile['file']} on " .
                            "line {$this->traceFile['line']} (by m36\\StringFormatter)";
                        \trigger_error($msg, E_USER_WARNING);

                        return '';
                    }

                    $cls = \explode('\\', $this->traceClass['class']);
                    $cls = \end($cls);

                    return $cls . '::' . $this->traceClass['function'];
                case 'methodLong':
                    if (!$this->traceClass || !isset($this->traceClass['class'])) {
                        $msg = "Bad usage of @methodLong keyword in {$this->traceFile['file']} on " .
                            "line {$this->traceFile['line']} (by m36\\StringFormatter)";
                        \trigger_error($msg, E_USER_WARNING);

                        return '';
                    }

                    return $this->traceClass['class'] . '::' . $this->traceClass['function'];
                case 'function':
                    if (!$this->traceClass || !isset($this->traceClass['function'])) {
                        $msg = "Bad usage of @function keyword in {$this->traceFile['file']} on " .
                            "line {$this->traceFile['line']} (by m36\\StringFormatter)";
                        \trigger_error($msg, E_USER_WARNING);

                        return '';
                    }

                    return $this->traceClass['function'];
                case 'file':
                    return \basename($this->traceFile['file']);
                case 'fileLong':
                    return $this->traceFile['file'];
                case 'dir':
                    return \basename(\dirname($this->traceFile['file']));
                case 'dirLong':
                    return \dirname($this->traceFile['file']);
                case 'line':
                    return $this->traceFile['line'];
            }
        }

        // text alignment
        elseif (\preg_match('
            /
            ^
                (' . self::$rxp_keys[$this->mode] . ')  # placeholder
                :                                       # explicit colon
                (.)?                                    # pad character
                ([<>^])                                 # alignment
                (\d+)                                   # pad length
            $
            /x', $data[1], $match) &&
            $this->hasKey($match[1])
        ) {
            $this->evaluateParam($match[1]);
            return \str_pad(
                $this->getParam($match[1]),
                $match[4],
                (\strlen($match[2]) > 0 ? $match[2] : ' '),
                static::$matrix__str_pad[$match[3]]
            );
        }

        // sprintf pattern
        elseif (\preg_match('
            /
            ^
                (' . self::$rxp_keys[$this->mode] . ')  # placeholder
                %                                       # explicit percent
                (.*)                                    # sprintf pattern
            $
            /x', $data[1], $match) &&
            $this->hasKey($match[1])
        ) {
            $this->evaluateParam($match[1]);
            return \vsprintf($match[2], $this->getParam($match[1]));
        }

        // call object method or get object property
        elseif (\preg_match('
            /
            ^
                (' . self::$rxp_keys[$this->mode] . ')  # placeholder
                ->                                      # explicit arrow
                (\w+)                                   # keyword (field or method name)
            $
            /x', $data[1], $match) &&
            $this->hasKey($match[1])
        ) {
            $this->evaluateParam($match[1]);
            $param = $this->getParam($match[1]);
            if (\method_exists($param, $match[2])) {
                return \call_user_func(array($param, $match[2]));
            } elseif (\property_exists($param, $match[2])) {
                return $param->{$match[2]};
            } elseif (\in_array('__call', \get_class_methods($param))) {
                return \call_user_func(array($param, $match[2]));
            } elseif (\in_array('__get', \get_class_methods($param))) {
                return $param->{$match[2]};
            } else {
                return $data[0];
            }
        }

        // converting int to other base
        elseif (\preg_match('
            /
            ^
            (' . self::$rxp_keys[$this->mode] . ')  # placeholder
            [#]                                     # explicit hash
            (?:
                (\d+)                               # source base
                [#]                                 # explicit hash
            )?
            ([dxXob]|\d\d?)                         # destination base
            $
            /x', $data[1], $match) &&
            $this->hasKey($match[1])
        ) {
            $this->evaluateParam($match[1]);
            $ret = \base_convert(
                $this->getParam($match[1]),                     // value to convert
                ($match[2] ? $match[2] : 10),                   // source base (defaults to 10)
                (
                \is_numeric($match[3])                          // destination base is:
                    ? $match[3]                                 // - numeric
                    : self::$matrix__base_convert[$match[3]]    // - or named
                )
            );
            if ($match[3] == 'X') {
                $ret = \strtoupper($ret);
            }

            return $ret;
        }

        // array index
        elseif (\preg_match('
            /
            ^
                (' . self::$rxp_keys[$this->mode] . ')  # placeholder
                \[                                      # opening square bracket
                    (\w+)                               # key
                \]                                      # closing square bracket
            $
            /x', $data[1], $match) &&
            $this->hasKey($match[1]) &&
            \is_array($ret = $this->getParam($match[1])) &&
            isset($ret[$match[2]])
        ) {
            $this->evaluateParam($match[1]);
            return $ret[$match[2]];
        }

        // unknown token
        else {
            $msg = "Unknown token found in format: {$data[0]} in {$this->traceFile['file']} on " .
                "line {$this->traceFile['line']} (by m36\\StringFormatter)";
            \trigger_error($msg, E_USER_WARNING);

            return $data[0];
        }
    }
1008245
protected function _normalizeData($data)
    {
        $data += [
            'name' => '',
            'empty' => false,
            'disabled' => null,
            'val' => null,
            'year' => [],
            'month' => [],
            'day' => [],
            'hour' => [],
            'minute' => [],
            'second' => [],
            'meridian' => null,
            'templateVars' => [],
        ];

        $timeFormat = isset($data['hour']['format']) ? $data['hour']['format'] : null;
        if ($timeFormat === 12 && !isset($data['meridian'])) {
            $data['meridian'] = [];
        }
        if ($timeFormat === 24) {
            $data['meridian'] = false;
        }

        return $data;
    }
839586
public static function validate($data) {
        if ( ! is_array($data) ) return '$data must be an array';
        $id = U::get($data, 'id');
        if ( $id ) {
            if ( ! is_int($id) ) return "id must be an an integer";
        }
        $uk1 = U::get($data, 'uk1');
        if ( $uk1 ) {
            if ( ! is_string($uk1) ) return "uk1 must be a string";
            if ( strlen($uk1) < 1 || strlen($uk1) > 150 ) return "uk1 must be no more than 150 characters";
        }
        $sk1 = U::get($data, 'sk1');
        if ( $sk1 ) {
            if ( ! is_string($sk1) ) return "sk1 must be a string";
            if ( strlen($sk1) < 1 || strlen($sk1) > 75 ) return "sk1 must be no more than 75 characters";
        }
        $tk1 = U::get($data, 'tk1');
        if ( $tk1 ) {
            if ( ! is_string($tk1) ) return "tk1 must be a string";
            if ( strlen($tk1) < 1 ) return "tk1 cannot be empty";
        }
        $co1 = U::get($data, 'co1');
        if ( $co1 ) {
            if ( ! is_string($co1) ) return "co1 must be a string";
            if ( strlen($co1) < 1 || strlen($co1) > 150 ) return "co1 must be no more than 150 characters";
        }
        $co2 = U::get($data, 'co2');
        if ( $co2 ) {
            if ( ! is_string($co2) ) return "co2 must be a string";
            if ( strlen($co2) < 1 || strlen($co2) > 150 ) return "co2 must be no more than 150 characters";
        }
        return true;
    }
77746
public function name($data) {
		if (is_object($data) && isset($data->type)) {
			return $data->value;
		}
		if ($data === '*') {
			return '*';
		}
		if (is_array($data)) {
			foreach ($data as $i => $dataItem) {
				$data[$i] = $this->name($dataItem);
			}
			return $data;
		}
		return (string)$data;
	}
754436
public function autoCheckToken($data) {
        // 支持使用token(false) 关闭令牌验证
        if(isset($this->options['token']) && !$this->options['token']) return true;
        if(C('TOKEN_ON')){
            $name   = C('TOKEN_NAME', null, '__hash__');
            if(!isset($data[$name]) || !isset($_SESSION[$name])) { // 令牌数据无效
                return false;
            }

            // 令牌验证
            list($key,$value)  =  explode('_',$data[$name]);
            if(isset($_SESSION[$name][$key]) && $value && $_SESSION[$name][$key] === $value) { // 防止重复提交
                unset($_SESSION[$name][$key]); // 验证完成销毁session
                return true;
            }
            // 开启TOKEN重置
            if(C('TOKEN_RESET')) unset($_SESSION[$name][$key]);
            return false;
        }
        return true;
    }
1174519
public function automaticUuid($data)
	{
		return sprintf(
			'%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
			mt_rand(0, 0xffff), mt_rand(0, 0xffff),
			mt_rand(0, 0xffff),
			mt_rand(0, 0x0fff) | 0x4000,
			mt_rand(0, 0x3fff) | 0x8000,
			mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
		);
	}
1010349
static function parseHeader($data)
    {
        $header = array();
        $header[0] = array();
        $meta = &$header[0];
        $parts = explode("\r\n\r\n", $data, 2);

        // parts[0] = HTTP头;
        // parts[1] = HTTP主体，GET请求没有body
        $headerLines = explode("\r\n", $parts[0]);

        // HTTP协议头,方法，路径，协议[RFC-2616 5.1]
        list($meta['method'], $meta['uri'], $meta['protocol']) = explode(' ', $headerLines[0], 3);

        //错误的HTTP请求
        if (empty($meta['method']) or empty($meta['uri']) or empty($meta['protocol']))
        {
            return false;
        }
        unset($headerLines[0]);
        //解析Header
        $header = array_merge($header, self::parseHeaderLine($headerLines));
        return $header;
    }
168976
public static function toDb($data) {

        $d = static::toInt($data);

        $d .= '';

        $minus = false;
        if (strlen($d) && $d[0] === '-') {
            $minus = true;
        }

        $d = trim($d, '-');

        $d = str_pad($d, 2, '0', STR_PAD_LEFT);

        $one = substr($d, 0, -2);

        $one = str_pad($one, 1, '0');

        $two = substr($d, -2);

        $two = str_pad($two, 2, '0', STR_PAD_RIGHT);

        return ($minus ? '-' : '') . "$one.$two";
    }
5591
public static function getHeaders(string $data): string
    {
        $pos = strpos($data, "\r\n\r\n");

        return $pos === false ? '' : substr($data, 0, $pos);
    }