Returns a wrapper to the user-provided callback used to handle response
chunks streamed by replies to commands such as MONITOR, SUBSCRIBE, etc.

@return mixed
161857
protected function getStreamingWrapperCreator()
    {
        return function ($connection, $callback) {
            return function ($state, $response) use ($connection, $callback) {
                \call_user_func($callback, $response, $connection, null);
            };
        };
    }
121153
public function getClient() {
		if (!$this->client) {
			// Create custom handler stack with middlewares
			$stack = HandlerStack::create();

			$context = $this;
			$stack->push(Middleware::mapResponse(function (ResponseInterface $response) use ($context) {
   				// If a new version of this accessor is available, store its COID
				if ($response->hasHeader('C-Accessor-Latest-Version'))
      				$context->setLatestAccessorVersionCOID(
						new IRI($response->getHeaderLine('C-Accessor-Latest-Version')));
    			return $response;
			}));

			// Prepare client options
			$options = [
				'base_uri' => str_replace('{aauid}', AAUIDParser::getAAUID($this->getAAUID()), $this->agwBaseUrl),
				'headers' => [
					'Authorization' => 'Bearer '.$this->getAccessToken()
				],
				'handler' => $stack
			];
			if (isset($this->request) && $this->request->hasHeader('X-Forwarded-For')) {
				$options['headers']['X-Forwarded-For'] = $this->request->getHeaderLine('X-Forwarded-For');				
			}

			// Create client
			$this->client = new Client($options);
		}
		return $this->client;
	}
126125
public function getResponse() {
        $class = $this->getResponseClassName();
        /** @var $response ResponseAbstract */
        $response = new $class;
        $response->setServiceLocator($this->getServiceLocator());
        $response->setException($this->exception)
            ->setHttpCode($this->returnHttpCode)
            ->trace();

        return $response;
    }
18050
public function respond()
    {
        $response = array();

        foreach ($this->queue as $object) {
            $response[] = $object->render();
        }

        return array('ajaxcom' => $response);
    }
108738
private function call()
    {
        // Process the signature
        $this->processSignature($this->client);

        try {
            // Make the request using guzzle
            $response = $this->client->send($this->request);
        } catch (\Exception $ex) {
            return $ex->getResponse();
        }

        return $response;
    }
768665
private function outputBufferingHandlerMiddleware()
    {
        return function (ServerRequestInterface $request, DelegateInterface $delegate) {
            ob_start();
            try {
                $response = $delegate->process($request);
            } finally {
                ob_end_clean();
            }
            return $response;
        };
    }
343339
private function createCommandHandler()
    {
        return function (CommandInterface $command) {
            return Promise\coroutine(function () use ($command) {
                // Prepare the HTTP options.
                $opts = $command['@http'] ?: [];
                unset($command['@http']);

                try {
                    // Prepare the request from the command and send it.
                    $request = $this->transformCommandToRequest($command);
                    $promise = $this->httpClient->sendAsync($request, $opts);

                    // Create a result from the response.
                    $response = (yield $promise);
                    yield $this->transformResponseToResult($response, $request, $command);
                } catch (\Exception $e) {
                    throw CommandException::fromPrevious($command, $e);
                }
            });
        };
    }
1284640
protected function getStatusResponse()
    {
        $request = new Request(
            'PUT',
            $this->resumeUri,
            ['Content-Range' => 'bytes */*']
        );

        return $this->requestWrapper->send($request, $this->requestOptions);
    }
1249061
private function getResponse()
    {
        $success = $this->handler->recv();
        $this->result = new Response((string)$this->handler->body, $this->handler->statusCode);
        if($success)
        {
            // headers
            foreach($this->handler->headers as $name => $value)
            {
                $this->result = $this->result->withHeader($name, $value);
            }

            // cookies
            $cookies = [];
            if(isset($this->handler->set_cookie_headers))
            {
                foreach($this->handler->set_cookie_headers as $value)
                {
                    $list = explode(';', $value);
                    $count2 = count($list);
                    if(isset($list[0]))
                    {
                        list($cookieName, $value) = explode('=', $list[0], 2);
                        $cookieName = trim($cookieName);
                        $cookies[$cookieName] = array('value'=>$value);
                        for($j = 1; $j < $count2; ++$j)
                        {
                            $kv = explode('=', $list[$j], 2);
                            $cookies[$cookieName][trim($kv[0])] = isset($kv[1]) ? $kv[1] : true;
                        }
                    }
                }
            }
            foreach($this->handler->cookies as $name => $value)
            {
                if(!isset($cookies[$name]))
                {
                    $cookies[$name] = ['value'=>$value];
                }
            }
            $this->result = $this->result->withCookieOriginParams($cookies);
        }
        $this->result = $this->result->withError($this->getErrorString($this->handler->errCode))
                                     ->withErrno($this->handler->errCode);
        $this->handler->close();
        return $this->result;
    }
372764
protected function heartbeat(): DisposableInterface
    {
        return $this->readBuffer
            ->timeout($this->heartBeatRate)
            ->filter(
                function (SocketMessage $message) {
                    return $message->getMessageType()->getType() === MessageType::HEARTBEAT_REQUEST_COMMAND;
                }
            )
            ->subscribe(
                new CallbackObserver(
                    function (SocketMessage $message) {
                        $this->writer->composeAndWrite(MessageType::HEARTBEAT_RESPONSE_COMMAND, null, $message->getCorrelationID());
                    },
                    [$this->connectionSubject, 'onError']
                )
            );
    }
1104137
protected function callback()
	{
		// fetch the response and decode it
		$this->response = \Input::get('opauth', false) and $this->response = unserialize(base64_decode($this->response));

		// did we receive a response at all?
		if ( ! $this->response)
		{
			throw new \OpauthException('no valid response received in the callback');
		}

		// did we receive one, but was it an error
		if (array_key_exists('error', $this->response))
		{
			throw new \OpauthException('Authentication error: the callback returned an error auth response');
		}

		// validate the response
		if ($this->get('auth') === null or $this->get('timestamp') === null or
			$this->get('signature') === null or $this->get('auth.provider') === null or $this->get('auth.uid') === null)
		{
			throw new \OpauthException('Invalid auth response: Missing key auth response components');
		}
		elseif ( ! $this->opauth->validate(sha1(print_r($this->get('auth'), true)), $this->get('timestamp'), $this->get('signature'), $reason))
		{
			throw new \OpauthException('Invalid auth response: '.$reason);
		}
	}
1172362
function newService()
    {
        $callable = $this->callable;
        if ($callable === null)
            ## no callable provided but rather not throw exception
            throw new \Exception('No Factory Callable Provided.');
        
        // ..
        // DO_LEAST_PHPVER_SUPPORT 5.4 Closure Bind
        if ($callable instanceof \Closure && version_compare(phpversion(), '5.4.0') > 0)
            $callable = $callable->bindTo($this);

        return call_user_func( $callable, $this->services() );
    }
741094
public function process() {
        $this->promise = new Promise(function($r, $c, $n) {
            $this->resolve = $r;
            $this->createRejectFunction($c);
            $this->notify = $n;
            $this->executionCallback(null, true);
        });

        return $this->promise;
    }
723138
public function notify() : ResponseHelper {
        $this->notified = true;

        app('antares.messages')->add($this->type, $this->message);

        return $this;
    }
1148180
public function getResponse(){
        if($this->httpCore != NULL){
            return $this->httpCore->httpResponse;
        }else{
            return $this->cronCore->cronResponse;
        }
    }
1264366
public static function handleRequest()
    {
        // save static class
        static::$calledClass = get_called_class();

        // handle JSON requests
        if (static::peekPath() == 'json') {
            // check access for API response modes
            static::$responseMode = static::shiftPath();
            if (in_array(static::$responseMode, ['json','jsonp'])) {
                if (!static::checkAPIAccess()) {
                    return static::throwAPIUnAuthorizedError();
                }
            }
        }

        return static::handleRecordsRequest();
    }
420728
private static function getStreamHandler()
    {
        if(!is_object(self::$stream))
        {
            self::$stream = new StreamHandler(self::$logFilePath, self::$minimumLevel);
        }
        return self::$stream;
    }