内部方法，发送异步请求
@param BaseRequest $request
@param BaseResponse $response
@param AsyncCallback|null $callback
@return \GuzzleHttp\Promise\PromiseInterface
357986
private function sendRequestAsyncInternal(BaseRequest &$request, BaseResponse &$response, AsyncCallback $callback = null)
    {
        $options = ['exceptions' => false, 'http_errors' => false];
        $options['form_params'] = $this->buildRequestBody($request);
        $options['timeout'] = $this->requestTimeout;
        $options['connect_timeout'] = $this->connectTimeout;
        $request = new Request($this->requestMethod, $this->requestPath);
        try {
            if ($callback != null) {
                return $this->client->sendAsync($request, $options)->then(
                    function (ResponseInterface $res) use (&$response, $callback) {
                        try {
                            $response->unwrapResponse($res);
                            $callback->onSucceed($response);
                        } catch (CMQException $e) {
                            $callback->onFailed($e);
                        }
                    }
                );
            } else {
                return $this->client->sendAsync($request, $options);
            }
        } catch (TransferException $e) {
            $message = $e->getMessage();
            if ($e->hasResponse()) {
                $message = $e->getResponse()->getBody();
            }
            throw new CMQException($message, $e->getCode());
        }
    }
1249129
public static function for($baseQuery, ?Request $request = null): self
    {
        if (is_string($baseQuery)) {
            $baseQuery = ($baseQuery)::query();
        }

        return new static($baseQuery, $request ?? request());
    }
757952
public function joinClosure(string $table, \Closure $callback): BaseQueryRelateContract
    {
        $this->query->join($table, $callback);

        return $this;
    }
731932
private function defaultErrorHandler(
        ServerRequestInterface $request,
        ResponseInterface $response
    ) {
        $response = $response->withStatus(422, 'Unprocessable Entity')
            ->withHeader('Content-Type', 'application/json');

        $middlewareAttribute = $request->getAttribute(Middleware::KEY, []);

        if (isset($middlewareAttribute[self::KEY])) {
            /** @var ResponseInterface $response */
            $stream = $response->getBody();
            $stream->write(json_encode($middlewareAttribute[self::KEY], JSON_UNESCAPED_SLASHES));
        }

        return $response;
    }
784205
function(args) {
    var baseUrl = this.baseUrl + this.basePath;
    var authToken = this.authToken;
    var qs = this._buildQueryString(args.params);

    return new Promise(function(resolve, reject) {
      var req = new XMLHttpRequest();

      req.onreadystatechange = function() {
        if (req.readyState === 4) {
          try {
            var response = JSON.parse(req.responseText);
            var status = req.status;

            if (status >= 200 && status < 400) {
              return resolve(
                addShadowProperty({
                  target: response,
                  property: 'httpRequest',
                  value: req
                })
              );
            }

            return reject(
              createApiError(
                merge(response, {
                  status: status,
                  httpRequest: req
                })
              )
            );
          } catch (err) {
            reject(err);
          }
        }
      };

      req.open(args.method, baseUrl + args.path + qs, true);
      req.setRequestHeader('Authorization', 'Bearer ' + authToken);
      req.setRequestHeader('Accept', 'application/json');
      req.setRequestHeader('Content-type', 'application/json; charset=utf-8');
      req.send(args.payload ? JSON.stringify(args.payload) : null);
    });
  }
261077
public function createHttpClient($baseUri, array $middlewares = [], array $options = [])
    {
        $stack = HandlerStack::create();

        foreach ($middlewares as $middleware) {
            $stack->push($middleware);
        }

        return new Client(array_merge([
            'base_uri' => $baseUri,
            'handler' => $stack,
        ], $options));
    }
1044093
protected function _handleCallbackAction(ServerRequest $request, Response $response)
    {
        $this->_setupModelInstances();

        $config = $this->getConfig();
        $providerName = $request->getParam('provider');

        $profile = $this->_getProfile($providerName, $request);
        if (!$profile) {
            return $response->withLocation(
                Router::url($config['loginUrl'], true) . '?error=' . $this->_error
            );
        }

        $user = $this->_getUser($profile);
        if (!$user) {
            return $response->withLocation(
                Router::url($config['loginUrl'], true) . '?error=' . $this->_error
            );
        }

        $user->unsetProperty($config['fields']['password']);

        if (!$config['userEntity']) {
            $user = $user->toArray();
        }

        $event = $this->dispatchEvent(self::EVENT_AFTER_IDENTIFY, ['user' => $user]);
        $result = $event->getResult();
        if ($result !== null) {
            $user = $event->getResult();
        }

        $request->getSession()->write($config['sessionKey'], $user);

        return $response->withLocation(
            Router::url($this->_getRedirectUrl($request), true)
        );
    }
375906
public function deleteById($callbackId, array $queryParams = [])
    {
        $response = $this->api->callbacks()->deleteById($callbackId, $queryParams);

        return new BaseResponse($response);
    }
565405
public function handleException(ServerRequestInterface $request, ResponseInterface $response, BaseException $exception)
    {
        return $this
            ->getContentTypeHandler($request)
            ->handleException($request, $response, $exception);
    }
1088137
public function authenticateResponse(BaseUser $user, Response $response)
    {
        return $this->setCookieForResponse($response, $this->createResponseAuthModel($user));
    }
999324
public function callbackAction()
    {
        try {
            $response = $this->getPaymentHandler()->getPaymentCallbackResponse($this->getCurrentRequest());
        } catch (EntityNotFoundException $ex) {
            throw new NotFoundHttpException($ex->getMessage());
        } catch (InvalidTransactionException $ex) {
            throw new UnauthorizedHttpException($ex->getMessage());
        }

        return $response;
    }
688338
public static void executeAsync(Executor executor, HttpRequestBase request, FutureCallback<HttpResponse> callback) {

		try {
			executor.execute(new AsyncHttpCall(request, callback));
		}
		catch (Exception e) {
			log.error("Failed to execute asynchronously: " + request.getMethod() + " " + request.getURI().toString());
		}
	}
874199
public function create(ServerRequestInterface $request) : CallbackInterface
    {
        $callbacks = [
            XmlCallback::class,
            FormCallback::class,
            RedirectCallback::class
        ];

        foreach ($callbacks as $callback) {
            if (call_user_func([$callback, 'initable'], $request)) {
                return new $callback($request);
            }
        }

        throw new \InvalidArgumentException('A callback could not be instantiated');
    }
91056
function promisedRequest(params, callback) {
  var deferred = Promise.defer();
  var req;
  var createRequest = function() {
    if (!req) {
      req = request(params, function(err, response) {
        if (err) {
          deferred.reject(err);
        } else {
          deferred.resolve(response);
        }
      });
    }
    return req;
  };
  return streamify(deferred.promise, createRequest).thenCall(callback);
}
728180
public function requestAsync($method, $url, $body = [], $query = [], $headers = [])
    {
        if (!empty($body)) {
            $body = encode($body);
            $headers['Content-Type'] = 'application/json';
        } else {
            $body = null;
        }

        $headers = array_merge($this->global_headers, $headers);

        return $this->client->requestAsync($method, $url, [
            'query'   => $query,
            'body'    => $body,
            'headers' => $headers,
        ]);
    }
281275
function(input, callback, context, remoteData)
  {
    var db = this;
    var promise = new Promise();

    promise.success( callback, context || db );

    function checkModel()
    {
      var result = db.parseModel( input, remoteData );

      if ( result !== false && !promise.isComplete() && db.initialized )
      {
        var remoteLoaded = db.remoteLoaded || !db.hasLoad( Load.All );
        var missingModel = (result === null || !result.$isSaved());
        var lazyLoad = db.hasLoad( Load.Lazy );

        if ( lazyLoad && remoteLoaded && missingModel )
        {
          if ( !result )
          {
            result = db.keyHandler.buildObjectFromKey( db.keyHandler.buildKeyFromInput( input ) );
          }

          result.$once( Model.Events.RemoteGets, function()
          {
            if ( !promise.isComplete() )
            {
              if ( isObject( input ) )
              {
                result.$set( input );
              }

              promise.resolve( result.$isSaved() ? result : null );
            }
          });

          result.$refresh( Cascade.All, db.fetchOptions );
        }
        else
        {
          promise.resolve( result );
        }
      }

      return promise.isComplete() ? false : true;
    }

    if ( checkModel() )
    {
      db.ready( checkModel, db, true );
    }

    return promise;
  }
507482
public function run(RequestInterface $request, ResponseInterface $response)
    {
        $previousId    = $request->getParam('widget_id');
        $widgetType    = $request->getParam('widget_type');
        $widgetOptions = $request->getParam('widget_options');
        $withData      = $request->getParam('with_data');

        if ($previousId) {
            $failMessage = $this->translator()->translation('Failed to reload widget');
        } else {
            $failMessage = $this->translator()->translation('Failed to load widget');
        }
        $errorThrown = strtr($this->translator()->translation('{{ errorMessage }}: {{ errorThrown }}'), [
            '{{ errorMessage }}' => $failMessage
        ]);
        $reqMessage  = $this->translator()->translation(
            '{{ parameter }} required, must be a {{ expectedType }}, received {{ actualType }}'
        );
        $typeMessage = $this->translator()->translation(
            '{{ parameter }} must be a {{ expectedType }}, received {{ actualType }}'
        );

        try {
            if (!$widgetType) {
                $actualType = is_object($widgetType) ? get_class($widgetType) : gettype($widgetType);
                $this->addFeedback('error', strtr($reqMessage, [
                    '{{ parameter }}'    => '"obj_type"',
                    '{{ expectedType }}' => 'string',
                    '{{ actualType }}'   => $actualType,
                ]));
                $this->setSuccess(false);

                return $response->withStatus(400);
            }

            $widget = $this->widgetFactory()->create($widgetType);
            $widget->setView($this->widgetView());

            if (isset($widgetOptions)) {
                if (!is_array($widgetOptions)) {
                    $actualType = is_object($widgetOptions) ? get_class($widgetOptions) : gettype($widgetOptions);
                    $this->addFeedback('error', strtr($typeMessage, [
                        '{{ parameter }}'    => '"widget_options"',
                        '{{ expectedType }}' => 'array',
                        '{{ actualType }}'   => $actualType,
                    ]));
                    $this->setSuccess(false);

                    return $response->withStatus(400);
                }

                if (!isset($widgetOptions['type'])) {
                    $widgetOptions['type'] = $widgetType;
                }

                $widget->setData($widgetOptions);
            }


            $widgetHtml = $widget->renderTemplate($widget->template());
            $jsRequirements = $widget->renderTemplate('{{&jsRequirements}}');
            $js = $widget->renderTemplate('{{&js}}');
            $widgetId   = $widget->widgetId();

            $this->setWidgetHtml($jsRequirements.$widgetHtml.$js);
            $this->setWidgetId($widgetId);

            if ($withData) {
                $widgetData = $widget->widgetDataForJs();
                $this->setWidgetData($widgetData);
            }

            if ($previousId) {
                $doneMessage = $this->translator()->translation('Widget Reloaded');
            } else {
                $doneMessage = $this->translator()->translation('Widget Loaded');
            }
            $this->addFeedback('success', $doneMessage);
            $this->setSuccess(true);

            return $response;
        } catch (Exception $e) {
            $this->addFeedback('error', strtr($errorThrown, [
                '{{ errorThrown }}' => $e->getMessage()
            ]));
            $this->setSuccess(false);

            return $response->withStatus(500);
        }
    }