@param mixed|null $data
@param bool       $compressed

@return string|null
345908
public static function pack($data, bool $compressed = false)
    {
        if (null === $data) {
            return $data;
        }

        $packedData = serialize($data);

        if ($compressed) {
            $packedData = gzencode($packedData, 9, FORCE_GZIP);
        }

        return $packedData;
    }
593971
private function decode($data, $raw)
    {
        if (is_array($data)) {
            foreach ($data as $k => &$v) {
                $v = $this->decode($v, $raw[$k]);
            }
            return $data;
        }

        $data = $this->decodeBoolean($data, $raw);
        $data = $this->decodeNull($data, $raw);

        if (is_numeric($data) && ((string)($data + 0) === $data))
            return $data + 0;

        if (is_string($raw) && empty($raw))
            return "";

        return $data;
    }
545646
private function encodeDict(array $data = null)
    {
        $data = is_null($data) ? $this->data : $data;
        ksort($data); // bencode spec requires dicts to be sorted alphabetically

        $dict = "";
        foreach ($data as $key => $value) {
            $dict .= $this->encodeString($key) . $this->doEncode($value);
        }

        return "d{$dict}e";
    }
1107865
public function update($data = null)
    {
        $fields = $this->getFields();
        $sql1 = '';
        $args = array();
        foreach ($fields as $field) {
            if (in_array($field, $this->updated_at_fileds)) {
                $this->{$field} = now();
            }
            $value = $this->getFieldValue($field, $data);
            if (isset($value) && !$this->isIndex($field)) {
                $args[] = $value;
                $sql1 .= "`$field` = ?, ";
            }
        }
        if (!empty($sql1)) {
            $sql1 = substr($sql1, 0, -2);
            $index = $this->getIndex();
            $indexValue = $this->db->escape_string($this->getFieldValue($index, $data));
            if (!$indexValue) {
                return false;
            }
            $args[] = $indexValue;
            return $this->db->exec("UPDATE `{$this->table_name}` SET $sql1 WHERE `$index` = ?", $args, $this->getCacheId($indexValue));
        }
        return false;
    }
535982
public static function fromArray(array $data)
    {
        $result = '';
        foreach ($data as $name => $value) {
            $value = StringHelper::toString($value, "'", Serialize::SERIALIZE_JSON);
            $result .= "$name=$value; ";
        }

        return $result === '' ? null : rtrim($result);
    }
885523
protected function _value($data)
    {
        static $compress;

        if (!isset($compress)) {
            $compress = new Horde_Compress_Fast();
        }

        return ($data instanceof MongoBinData)
            ? @unserialize($compress->decompress($data->bin))
            : new MongoBinData(
                $compress->compress(serialize($data)), MongoBinData::BYTE_ARRAY
            );
    }
653470
private function getDataType($data)
    {
        if (is_string($data)) {
            return "'".$data."'";
        }

        if (is_numeric($data)) {
            return $data;
        }

        if (is_array($data)) {
            return 'Array';
        }

        if (is_bool($data)) {
            return $data ? 'true' : 'false';
        }

        if (is_object($data)) {
            return get_class($data);
        }

        if (is_null($data)) {
            return 'null';
        }

        return 'unknown';
    }
78089
protected function convert_to_bool( $data, $key ) {
		return ! empty( $data[ $key ] ) && $data[ $key ] !== '0' && $data[ $key ] !== 'false';
	}
486882
private static function encodeUTF16($string, $compressed = '')
    {
        if ($compressed) {
            $string = self::uncompressByteString($string);
        }

        return PHPExcel_Shared_String::ConvertEncoding($string, 'UTF-8', 'UTF-16LE');
    }
759166
public static function decode($data)
    {
        $rData = strtr($data, '-_', '+/');
        $rMod4 = strlen($rData) % 4;
        if ($rMod4) {
            $rData .= substr('====', $rMod4);
        }
        return base64_decode($rData);
    }
684569
public function set($key, $data, $expire = 0, $compress=false) {
		$expire = intval($expire);
		return $this->cache->set($this->prefix.$key, $data, $compress ? MEMCACHE_COMPRESSED : 0, $expire);
	}
438856
public function data(string $key, array $data = null)
    {
        $this->tryLoad($key);

        if (!\array_key_exists($key, $this->data))
        {
            $this->data[$key] = $this->get($key, $data);
        }

        return $this->data[$key];
    }
458888
public function xml($data)
    {
        if (isset($data['url']) && ! empty($data['url'])) {
            $result = @file_get_contents($data['url']);
            $result = XmlFormatter::encode($result);
        }
        return isset($result) ? $result : null;
    }
647881
protected function unserializeData($data)
    {
        $value = null;
        // if we're not deserialised yet, do so
        if (is_string($data) && strlen($data) > 1) {
            // are we json encoded?
            if ($data{1} === ':') {
                $value = \unserialize($data);
            } else {
                $value = \json_decode($data, true);
            }
        }
        return $value;
    }
917928
public static function encode($data)
    {
        switch (gettype($data)) {
            case 'array':
                return self::encodeArray($data);
            case 'object':
                return self::encodeObject($data);
            case 'string':
                return self::encodeString($data);
            case 'integer':
                return self::encodeInteger($data);
            case 'boolean':
                return self::encodeBoolean($data);
            case 'double':
                return self::encodeDouble($data);
            case 'NULL':
                return self::encodeNull($data);
            case 'resource':
                // TODO
                break;
            default:
                throw new UnencodeableException('Contains unencodeable type', 3);
        }
    }
149411
public function findToolFrom($data)
    {
        $tools = $this->getAvailableTools();
        foreach ($tools as $tool) {
            if (in_array($data, $tool, true)) {
                return $tool;
            }
        }
        return null;
    }
841054
public function solveResolutions(array $data)
    {
        return null !== $this->resolutionManager
            ? $this->resolutionManager->solveResolutions($data)
            : $data;
    }