设置编码类型
@param $type
@param $gzip
@throws \Exception
422696
function setEncodeType($type, $gzip)
    {
        //兼容老版本，老版本true代表用json false代表serialize
        if ($type === true)
        {
            $type = RPCServer::DECODE_JSON;
        }
        if ($type === false)
        {
            $type = RPCServer::DECODE_PHP;
        }
        
        if ($type === RPCServer::DECODE_SWOOLE and (substr(PHP_VERSION, 0, 1) != '7'))
        {
            throw new \Exception("swoole_serialize only use in phpng");
        }
        else
        {
            $this->encode_type = $type;
        }
        if ($gzip)
        {
            $this->encode_gzip = true;
        }
    }
318891
public function create($domain, $type, $protocol)
    {
        $sock = @socket_create($domain, $type, $protocol);
        if ($sock === false) {
            throw Exception::createFromGlobalSocketOperation('Unable to create socket');
        }
        return new Socket($sock);
    }
6306
protected function do_log($message, $type='exception in code') {
		$this->debugLogs[] = array('project'=>$this->projectName,'upgradeFile'=>$this->upgradeConfigFile,'message'=>$message,'type'=>$type);
		if($this->internalUpgradeInProgress === true) {
			$this->storedLogs[] = func_get_args();
		}
		else {
			if(is_object($this->logsObj)) {
				$this->logsObj->log_by_class($message, $type);
			}
		}
	}
315629
public static function createDate(String $file, String $type = 'd.m.Y G:i:s') : String
    {
        $file = self::rpath($file);

        if( ! file_exists($file) )
        {
            throw new Exception\FileNotFoundException(NULL, $file);
        }

        $date = filectime($file);

        return date($type, $date);
    }
65934
public function onFrame($data, $type)
    {
        foreach (explode("\n", $data) as $pct) {
            if ($pct === '') {
                continue;
            }
            $pct = json_decode($pct, true);
            if (isset($pct[0])) {
                foreach ($pct as $i) {
                    $this->onPacket(rtrim($i, "\n"), $type);
                }
            } else {
                $this->onPacket($pct, $type);
            }
        }
    }
565911
public static FileUtils.FileCopyResult gzip(final File inFile, final File outFile)
  {
    return gzip(inFile, outFile, FileUtils.IS_EXCEPTION);
  }
605075
public function setByType($type)
    {
        if (isset(self::$typeList[$type])) {
            $this->value = self::$typeList[$type];
        } else {
            throw new Exception("undefined index $type");
        }
    }
1173699
protected function sendGzipContent($event, $req, $res, $path, $filesize)
    {
        if(!$this->gzip || !$req->gzipSupport() || $filesize < $this->gzip_min_bytes || $filesize >$this->gzip_max_bytes) {
            return false;
        }
        
        $res->headers->set('Content-Encoding', 'gzip');
        $res->body = gzencode(file_get_contents($path), $this->gzip_level);
        $res->headers->set('Content-Length', strlen($res->body));
        return $res;
    }
82456
public function open($path, $type = null, $password = null)
    {
        if (null === $type) {
            $type = $this->guessAdapterExtension($path);
        }

        try {
            $adapter = $this->getAdapterFor($this->sanitizeExtension($type));
            if (method_exists($adapter, 'setPassword') && $password){
                $adapter->setPassword($password);
            }
            return $adapter->open($path);
        } catch (ExceptionInterface $e) {
            throw new RuntimeException('Unable to open archive', $e->getCode(), $e);
        }
    }
164715
public static function log($type, $source): void
    {
        if (
            (!($source instanceof \stdClass) && $type === self::TYPE_EXCEPTION) ||
            (!($source instanceof JsonRpcRequest) && \in_array($type, [self::TYPE_REQUEST, self::TYPE_RESPONSE], true))
        ) {
            return;
        }

        /** @var JsonRpcRequest $jsonRpcRequest */
        $jsonRpcRequest = app('JsonRpcRequest');
        $hideIndices = !empty($jsonRpcRequest->controller->hideDataLog) ? $jsonRpcRequest->controller->hideDataLog : false;
        $method = !empty($jsonRpcRequest->method) ? $jsonRpcRequest->method : 'Unknown';

        switch ($type) {
            case self::TYPE_REQUEST:
                $logLevel = 'info';
                $message = 'Request';
                $context = !empty($source->call) ? (array)$source->call : [];
                break;

            case self::TYPE_RESPONSE:
                $logLevel = 'info';
                $message = sprintf('Successful request to method "%s" (id-%s) with params: ', $source->method, $source->id);
                $context = !empty($source->call) ? (array)$source->call : [];
                break;

            case self::TYPE_EXCEPTION:
                $logLevel = 'error';
                $message = sprintf('JsonRpcException %d: %s',
                    isset($source->code) ? $source->code : 0,
                    !empty($source->message) ? $source->message : '');
                $context = !empty($jsonRpcRequest->call) ? (array)$jsonRpcRequest->call : [];
                break;

            default:
                $logLevel = 'info';
                $message = 'No log type specified';
                $context['params'] = [];
                break;
        }

        $hideDataRules = !empty($hideIndices[$type][$method])
            ? $hideIndices[$type][$method]
            : false;

        $hideData = function (&$item, $key, $rules) {
            if (\in_array($key, $rules, true)) {
                $item = '****';
            }
        };

        if ($hideDataRules && !empty($context['params'])) {
            array_walk($context['params'], $hideData, $hideDataRules);
        }

        Log::channel(config('jsonrpc.log_channel'))
            ->$logLevel($message, $context);

    }
866303
public function setOutputType($type)
    {
        if (preg_match('/(png|gif|jpe?g|tif?f|webp)/i', $type)) {
            $this->outputType = sprintf('image/%s', strtolower($type));
            return;
        } else {
            throw new \InvalidArgumentException(sprintf('Invalid output format %s', $type));
        }
    }
416961
public function buildForBroadcastPreview($type)
    {
        if (!method_exists($this, 'toStaff')) {
            throw new \Exception(__CLASS__.'未实现此方法：toStaff()');
        }

        $base = array(
            $type => $this->to,
            'msgtype' => $this->getDefaultMessageType(),
        );

        return array_merge($base, $this->toStaff());
    }
201148
private function load($type)
    {
        $index = $this->$type;
        if ($index) {
            return;
        }

        $cache = $this->di->get("cache");
        $key = $cache->createKey(__CLASS__, $type);
        $index = $cache->get($key);

        if (is_null($index) || $this->ignoreCache) {
            $createMethod = "create$type";
            $index = $this->$createMethod();
            $cache->put($key, $index);
        }

        $this->$type = $index;
    }
29810
public function setByType($type)
    {
        if (isset(self::$sourceList[$type])) {
            $this->value = self::$sourceList[$type];
        } else {
            throw new Exception("undefined index $type");
        }
    }
725127
public function exceptionError($exception, $type = 'Exception')
    {
        $errorMsg = $exception->getMessage();
        $trace = $exception->getTrace();
        krsort($trace);
        $trace[] = ['file' => $exception->getFile(), 'line' => $exception->getLine(), 'function' => 'break'];
        $phpMsg = [];
        foreach ($trace as $error) {
            if (!empty($error['function'])) {
                $fun = '';
                if (!empty($error['class'])) {
                    $fun .= $error['class'] . $error['type'];
                }
                $fun .= $error['function'] . '(';
                if (!empty($error['args'])) {
                    $mark = '';
                    foreach ($error['args'] as $arg) {
                        $fun .= $mark;
                        if (is_array($arg)) {
                            $fun .= 'Array';
                        } elseif (is_bool($arg)) {
                            $fun .= $arg ? 'true' : 'false';
                        } elseif (is_int($arg)) {
                            $fun .= $arg;
                        } elseif (is_float($arg)) {
                            $fun .= $arg;
                        } else {
                            $fun .= $this->clear($arg);
                        }
                        $mark = ', ';
                    }
                }
                $fun .= ')';
                $error['function'] = $fun;
            }
            if (!isset($error['line'])) {
                continue;
            }
            $phpMsg[] = ['file' => $error['file'], 'line' => $error['line'], 'function' => $error['function']];
        }
        $this->showError($type, $errorMsg, $phpMsg);
    }
634641
public function read($type = 'debug') {
        $path = TMP . 'logs/' . $type . '.log';
        $logs = array();
        $exceptions = array();
        $message = null;

        if (!in_array($type, CakeLog::configured())) {
            throw new NotFoundException(__d('admin', '%s Log Not Found', Inflector::humanize($type)));
        }

        if (file_exists($path)) {
            if (filesize($path) > 2097152) {
                throw new BadRequestException(__d('admin', 'Can not read %s as it exceeds 2MB', basename($path)));
            }

            if ($file = file($path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES)) {
                $log = array();

                foreach ($file as $line) {
                    // Exception message
                    if (preg_match('/^([0-9\-:\s]+)\s([a-z]+:)\s(?:\[([a-z]+)\])?\s?(.*?)$/i', $line, $matches)) {
                        $exception = $matches[3];

                        // Save the previous log
                        if ($log) {
                            $key = md5($log['url'] . $log['message']);

                            if (isset($logs[$key])) {
                                $logs[$key]['count']++;
                            } else {
                                $logs[$key] = $log;
                            }
                        }

                        // Start a new log
                        $log = array(
                            'line' => $line,
                            'exception' => $exception,
                            'message' => $matches[4],
                            'stack' => array(),
                            'count' => 1,
                            'date' => $matches[1],
                            'url' => null
                        );

                        if ($exception) {
                            $exceptions[$exception][] = $matches[1];
                        }
                    // Request URL
                    } else if (preg_match('/^Request URL: (.*?)$/i', $line, $matches)) {
                        $log['url'] = $matches[1];

                    // Stack trace
                    } else if ($line[0] === '#') {
                        $log['stack'][] = $line . PHP_EOL;
                    }
                }
            }

            // Sort by count
            usort($logs, function($a, $b) {
                return $b['count'] - $a['count'];
            });
        }

        $this->set('type', $type);
        $this->set('logs', $logs);
        $this->set('exceptions', $exceptions);
    }
69588
public function random($length = 32, $type = 'alnum')
    {
        switch ($type) {

            case 'alpha':
                $pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
                break;

            case 'alnum':
            case 'alphanum':
                $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
                break;

            case 'num':
            case 'numeric':
                $pool = '0123456789';
                break;

            case 'md5':
                return md5(uniqid(mt_rand()));
                break;

            default:
                throw new \Exception("Invalid random string type [{$type}].");
        }

        return substr(str_shuffle(str_repeat($pool, 5)), 0, $length);
    }