转换Ret结构为response

@param array $ret
@return Response
@throws \Exception
974139
protected function handleRet(array $ret)
    {
        if ($this->request->acceptJson() || php_sapi_name() == 'cli' || $this->isApi()) {
            return $this->response->json($ret);
        } else {
            $type = isset($ret['retType']) ? $ret['retType'] : ($ret['code'] === 1 ? 'success' : 'warning');
            $content = $this->view->render('@plugin/ret/ret.php', $ret + ['type' => $type]);

            return $this->response->setContent($content);
        }
    }
698712
public function handle(Exception $exception): Response
    {
        foreach ($this->handlers as $hint => $handler) {
            if (!$exception instanceof $hint) {
                continue;
            }

            if ($response = $handler($exception)) {
                if (!$response instanceof BaseResponse) {
                    $response = new Response($response, $this->getExceptionStatusCode($exception));
                }

                return $response;
            }
        }

        return $this->genericResponse($exception);
    }
1177787
protected function genericResponse(Exception $exception): Response
    {
        $replacements = $this->prepareReplacements($exception);

        return new Response($replacements, $this->getHttpStatusCode($exception), $this->getHeaders($exception));
    }
1030722
protected function request($send, $retObj)
    {
        $retObj->send = $send;
        $this->beforeRequest($retObj);

        $retObj->index = $this->requestIndex++;
        connect_to_server:
        if ($this->connectToServer($retObj) === false)
        {
            $retObj->code = RPC_Result::ERR_CONNECT;
            return false;
        }
        //请求串号
        $retObj->requestId = self::getRequestId();
        //打包格式
        $encodeType = $this->encode_type;
        if ($this->encode_gzip)
        {
            $encodeType |= RPCServer::DECODE_GZIP;
        }
        //发送失败了
        if ($retObj->socket->send(RPCServer::encode($retObj->send, $encodeType, 0, $retObj->requestId)) === false)
        {
            $this->closeConnection($retObj->server_host, $retObj->server_port);
            //连接被重置了，重现连接到服务器
            if ($this->haveSwoole and $retObj->socket->errCode == 104)
            {
                goto connect_to_server;
            }
            $retObj->code = RPC_Result::ERR_SEND;
            unset($retObj->socket);
            return false;
        }
        $retObj->code = RPC_Result::ERR_RECV;
        //加入wait_list
        $this->waitList[$retObj->requestId] = $retObj;
        return true;
    }
1206978
private function getRemoteData(string $url): ResponseInterface
    {
        $this->init($url);
        $version = '1.1';

        $response = curl_exec($this->resource);

        if (false === $response) {
            throw new Exception('could not initialize the connection to load the data');
        }

        $httpCode   = curl_getinfo($this->resource, CURLINFO_HTTP_CODE);
        $headerSize = curl_getinfo($this->resource, CURLINFO_HEADER_SIZE);

        $this->close();

        $rawHeaders = explode("\r\n", trim(mb_substr($response, 0, $headerSize)));
        $headers    = [];

        foreach ($rawHeaders as $rawHeader) {
            $parts  = explode(':', $rawHeader, 2);
            $header = $parts[0];

            if (isset($parts[1])) {
                $value = trim($parts[1]);
            } else {
                $value = '';
            }

            $headers[$header] = $value;
        }

        $body = mb_substr($response, $headerSize);

        return new Response($httpCode, $headers, $body, $version);
    }
671429
private function _list($ret)
    {
        if(!isset($ret['var'])) return '';
        $v = $this->getVar($ret['var']);
        if(!$v || !is_array($v)) return '';

        $tag = isset($ret['tag']) ? $ret['tag'] : 'li';
        $ret = $this->clearData($ret);

        //Tag UL and params. (class, id, etc)
        $o = '<ul';
        foreach($ret as $k=>$val){
            $o .= ' '.trim($k).'="'.trim($val).'"';
        }
        $o .= '>';
        //create list
        foreach ($v as $k=>$val){
            $o .= '<'.$tag.'>'.$val.'</'.$tag.'>';
        }
        return $o . '</ul>';
    }
1156468
public function jsonResponse(Exception $exception)
    {
        $this->exception = $exception;
        $this->jsonApiResponse = new JsonApiResponse;

        if ($this->exceptionIsTreated()) {
            $this->callExceptionHandler();
        } else {
            $this->setDefaultResponse();
        }

        return response()->json(
            $this->jsonApiResponse->toArray(),
            $this->jsonApiResponse->getStatus()
        );
    }
502623
public function handleResponse(array $request)
    {
        foreach ($this->paymentAdapters as $adapter) {
            $response = new Response($request, $adapter);
            if ($adapter->enabled && $adapter->canHandlePaymentResponse($response)) {
                $adapter->handlePaymentResponse($response);

                $transaction = new Transaction();
                $adapter->loadTransactionFromResponse($response, $transaction);
                $response->setTransaction($transaction);
                return $response;
            }
        }
        throw new Exception("No adapters found that could handle the payment response");
    }
507135
public function onKernelException(GetResponseForExceptionEvent $event) :? Response
    {
        // You get the exception object from the received event
        $exception = $event->getException();
        $request = $event->getRequest();

        // If the event already has a response, do not override it.
        if ($event->hasResponse()) {
            return $event->getResponse();
        }

        $format = $request->getRequestFormat($this->defaultFormat);

        // If the request format is not supported, nothing more can be done
        // without the serializer throwing an exception.
        if (!$this->encoder->supportsEncoding($format)) {
            return null;
        }

        // If the normalizer cannot normalize the result, then there is nothing
        // more than can be done without the serializer throwing an exception.
        if (!$this->normalizer->supportsNormalization($exception, $format)) {
            return null;
        }

        $status = 500;
        $headers = [];
        if ($exception instanceof HttpExceptionInterface) {
            $status = $exception->getStatusCode();
            $headers = $exception->getHeaders();
        }

        $context = [
            'enable_max_depth' => true,
        ];

        $serializeEvent = new SerializeEvent($exception, $format, $context, $request);

        $this->eventDispatcher->dispatch(SerializeEvent::NAME, $serializeEvent);

        $response = new Response(
            $this->serializer->serialize(
                $serializeEvent->getData(),
                $serializeEvent->getFormat(),
                $serializeEvent->getContext()
            ),
            $status,
            $headers
        );

        // Add the default content type headers.
        if ($format !== $request->getRequestFormat() && !$response->headers->has('Content-Type')) {
            if ($mimeType = $request->getMimeType($format)) {
                $response->headers->set('Content-Type', $mimeType);
            }
        }

        $event->setResponse($response);

        return $response;
    }
1226672
public function builder($ret, $data, $msg = '', $format = 'json')
    {
        @header('Content-type: application/json; charset=utf-8');
        $this->ret  = strval($ret);
        $this->time = time();
        $this->msg  = $msg;
        $this->data = $data;
        $this->format = $format;
    }
31363
protected function getRemoteContent($url)
    {
        $response = (new Client())
            ->createRequest()
            ->setMethod('GET')
            ->setUrl($url)
            ->send();
        if (!$response->isOk) {
            throw new Exception("URL {$url} doesn't exist");
        }

        return $response->content;
    }
286336
public function createAction($req)
    {
        // 1. 调用注册接口
        $user = wei()->user();
        $ret = $user->register($req);
        if ($ret['code'] !== 1) {
            return $this->ret($ret);
        }

        // 2. 登录用户
        $loginRet = wei()->curUser->loginById($user['id']);
        if ($loginRet['code'] !== 1) {
            return $loginRet;
        }

        return $this->ret($ret);
    }
425123
public function execute(array $input = [])
    {
        $this->input = $input;
        $data = $this->run();

        return new Response($data ?: []);
    }
1080933
public function handleStatus($ret)
    {
        if ($ret === self::EVENT_CONFIG_UPDATED) {
            $this->onConfigUpdated();
            return true;
        } elseif ($ret === self::EVENT_GRACEFUL_SHUTDOWN) {
            return $this->onShutdown(true);
        } elseif ($ret === self::EVENT_SHUTDOWN) {
            return $this->onShutdown();
        }
        return false;
    }
971851
public function updateIndexOne(array $data)
    {
        if (!is_array($data)) {
            throw new \Exception('你的索引参数不是一个数组');
        }

        if (count($data) == count($data, 1)) {
            // 一维数组
            $this->getIndex()->update(new \XSDocument($data));
        }

        //索引是否立即生效
        if ($this->flush_index) {
            $this->getIndex()->flushIndex();
        }

        return $this->getIndex();
    }
1133405
public function checkResponse($response) {
    if (!is_array($response)) {
      return FALSE;
    }

    $responseParams = array();
    foreach ($this->responseFields as $k => $mandatory) {
      if (isset($response[$k])) {
        $responseParams[$k] = $response[$k];
      }
      elseif (!isset($response[$k]) && $mandatory) {
        throw new \Exception('expected response field ' . $k . ' is missing');
      }
    }

    return $responseParams;
  }
757568
public function response(array $errors)
    {
        if ($this->ajax() || $this->wantsJson()) {
            return new JsonResponse($errors, 422);
        }

        return $this->redirector->to($this->getRedirectUrl())
            ->withInput($this->except($this->dontFlash))
            ->withErrors($errors, $this->errorBag);
    }