Process the response

@return array
@throws \GameQ\Exception\Protocol
324855
public function processResponse()
    {
        // Will hold the packets after sorting
        $packets = [];

        // We need to pre-sort these for split packets so we can do extra work where needed
        foreach ($this->packets_response as $response) {
            $buffer = new Buffer($response);

            // Pull out the header
            $header = $buffer->read(5);

            // Add the packet to the proper section, we will combine later
            $packets[$header][] = $buffer->getBuffer();
        }

        unset($buffer);

        $results = [];

        // Now let's iterate and process
        foreach ($packets as $header => $packetGroup) {
            // Figure out which packet response this is
            if (!array_key_exists($header, $this->responses)) {
                throw new Exception(__METHOD__ . " response type '{$header}' is not valid");
            }

            // Now we need to call the proper method
            $results = array_merge(
                $results,
                call_user_func_array([$this, $this->responses[$header]], [new Buffer(implode($packetGroup))])
            );
        }

        unset($packets);

        return $results;
    }
837774
private function request_response()
    {
        // Must not block while reading
        stream_set_blocking($this->stream, false);
        
        $response = '';
        while (true) {
            $buffer = fgets($this->stream);
            $response .= $buffer;
            if (strstr($buffer, "\n")) {
                break;
            } else {
                usleep(1000);
            }
        }

        $data = '';
        if (!$response) {
            $this->close();
            $desc = $this->request_description();
            throw new ProtocolException("Unable to read response from server ({$desc})");
        } else if (null === ($data = json_decode(trim($response), true))) {
            $desc = $this->request_description();
            throw new ProtocolException("Unable to parse response from server ({$desc}): {$response}");
        } else if (!is_array($data)) {
            $desc = $this->request_description();
            throw new ProtocolException("Invalid response from server ({$desc}): ".json_encode($data));
        }

        if (isset($data['$error'])) {
            throw new ServerException((string)$data['$error']);
        }
        if (isset($data['$end'])) {
            $this->close();
        }

        return $data;
    }
150908
public function process()
	{
		$view = $this->getView();

		try
		{
			parent::process();

			$basketCntl = Controller_Frontend_Factory::createController( $this->_getContext(), 'basket' );

			// Test if addresses are available
			$addresses = $basketCntl->get()->getAddresses();
			if( !isset( $view->standardStepActive ) && count( $addresses ) === 0 )
			{
				$view->standardStepActive = 'address';
				return false;
			}
		}
		catch( Exception $e )
		{
			$this->getView()->standardStepActive = 'address';
			throw $e;
		}

	}
466809
public function send() {

        $protocol = $this->getProtocol();

        $content_type = $protocol == self::XMLRPC ? "text/xml" : "application/json";

        $processor = $this->getProcessor();

        try {

            $payload = $this->getPayload($processor);

            $response = $this->getTransport()
                ->performCall(
                    $this->logger,
                    $payload,
                    $content_type,
                    $this->getEncryption()
                );

            $result = $processor->decode($response);

        } catch (HttpException $he) {

            throw $he;

        } catch (RpcException $re) {

            throw $re;

        } catch (XmlrpcException $xe) {

            throw $xe;

        } catch (Exception $e) {

            throw $e;

        }

        if ( $this->getAutoclean() ) $this->getRequest()->clean();

        return $result;

    }
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;
    }
186789
public function process()
    {
        if ($this->cache !== null) {
            return $this->cache;
        } else {
            return ($this->cache = UriTemplate::expand($this->template, $this->data));
        }
    }
173387
public function processRequest()
    {
        try {
            $router = new Router($this->api, $this->class, $this->normalize, $this->cacheInstance);

            // check if url is set via the initRest method
            if (!empty(self::$url)) {
                $router->setUrl(self::$url);
            }

            // check if the method vas set via initRest method
            if (!empty(self::$method)) {
                $router->setHttpMethod(self::$method);
            }

            return $router->processRequest();
        } catch (\Exception $e) {
            $exception = new RestException('Unable to process request for class "' . $this->class . '". ' . $e->getMessage());
            $exception->setRequestedClass($this->class);
            throw $exception;
        }
    }
1321306
public function process()
    {
        synapse()->brain->topic()->triggers()->each(function ($data, $trigger) {
            $this->searchTriggers($trigger);

            if ($this->output !== 'Error: Response could not be determined.') {
                return false;
            }
        });

        return $this->output;
    }
917108
public function processResponse()
    {

        // Create a new buffer
        $buffer = new Buffer(implode('', $this->packets_response));

        // Burn the header
        $buffer->skip(4);

        // Create a new result
        $result = new Result();

        // Variables
        $result->add('gamename', $buffer->readPascalString(1, true));
        $result->add('port', $buffer->readPascalString(1, true));
        $result->add('servername', $buffer->readPascalString(1, true));
        $result->add('gametype', $buffer->readPascalString(1, true));
        $result->add('map', $buffer->readPascalString(1, true));
        $result->add('version', $buffer->readPascalString(1, true));
        $result->add('password', $buffer->readPascalString(1, true));
        $result->add('num_players', $buffer->readPascalString(1, true));
        $result->add('max_players', $buffer->readPascalString(1, true));
        $result->add('dedicated', 1);

        // Offload the key/value pair processing
        $this->processKeyValuePairs($buffer, $result);

        // Offload processing player and team info
        $this->processPlayersAndTeams($buffer, $result);

        unset($buffer);

        return $result->fetch();
    }
1018888
public function processResponse()
    {

        //print_r($this->packets_response);

        // Holds the results sent back
        $results = [];

        // Iterate over the response packets
        // @todo: This protocol has no packet ordering, ids or anyway to identify which packet coming back belongs to which initial call.
        foreach ($this->packets_response as $i => $packet) {
            // Create a new buffer
            $buffer = new Buffer($packet);

            // Burn first 4 bytes, same across all packets
            $buffer->skip(4);

            // Get the packet length
            $packetLength = $buffer->getLength();

            // Check to make sure the expected length matches the real length
            // Subtract 4 for the header burn
            if ($packetLength != ($buffer->readInt32() - 4)) {
                throw new Exception(__METHOD__ . " packet length does not match expected length!");
            }

            // We assume the packets are coming back in the same order as sent, this maybe incorrect...
            $results = array_merge(
                $results,
                call_user_func_array([$this, $this->responses[$i]], [$buffer])
            );
        }

        unset($buffer, $packetLength);

        return $results;
    }
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;
    }
647304
private function process()
    {
        $this->processor->post($this->url, $this->requestJson);

        if (!$this->processor->error) {
            return $this->processor->response;
        }
        $error_message = null;
        $error_code    = null;
        if ($this->processor->error_code) {
            $error_message = $this->processor->error_message;
            $error_code    = $this->processor->error_code;
        }
        throw new AuthnetCurlException(sprintf('Connection error: %s (%s)', $error_message, $error_code));
    }
602091
public function processResponse()
    {
        // Holds the processed packets so we can sort them in case they come in an unordered
        $processed = [];

        // Iterate over the packets
        foreach ($this->packets_response as $response) {
            // Check to see if we had a preg_match error
            if (($match = preg_match("#^(.*)\\\\queryid\\\\([^\\\\]+)(\\\\|$)#", $response, $matches)) === false
                || $match != 1
            ) {
                throw new Exception(__METHOD__ . " An error occurred while parsing the packets for 'queryid'");
            }

            // Multiply so we move the decimal point out of the way, if there is one
            $key = (int)(floatval($matches[2]) * 1000);

            // Add this packet to the processed
            $processed[$key] = $matches[1];
        }

        // Sort the new array to make sure the keys (query ids) are in the proper order
        ksort($processed, SORT_NUMERIC);

        // Create buffer and offload processing
        return $this->processStatus(new Buffer(implode('', $processed)));
    }
514239
public function processResponse()
    {
        // Init results
        $results = [];

        foreach ($this->packets_response as $response) {
            $buffer = new Buffer($response);

            // Figure out what packet response this is for
            $response_type = $buffer->read(6);

            // Figure out which packet response this is
            if (!array_key_exists($response_type, $this->responses)) {
                throw new Exception(__METHOD__ . " response type '" . bin2hex($response_type) . "' is not valid");
            }

            // Now we need to call the proper method
            $results = array_merge(
                $results,
                call_user_func_array([$this, $this->responses[$response_type]], [$buffer])
            );

            unset($buffer);
        }

        return $results;
    }
112058
public function processResponse()
    {
        // No response, assume offline
        if (empty($this->packets_response)) {
            return [
                'gq_address'    => $this->realIp,
                'gq_port_query' => $this->realPortQuery,
            ];
        }

        // Implode and rip out the JSON
        preg_match('/\{(.*)\}/ms', implode('', $this->packets_response), $matches);

        // Return should be JSON, let's validate
        if (!isset($matches[0]) || ($json = json_decode($matches[0])) === null) {
            throw new Exception("JSON response from Gtan protocol is invalid.");
        }

        $result = new Result();

        // Server is always dedicated
        $result->add('dedicated', 1);

        $result->add('gq_address', $this->realIp);
        $result->add('gq_port_query', $this->realPortQuery);

        // Add server items
        $result->add('hostname', $json->ServerName);
        $result->add('serverversion', $json->ServerVersion);
        $result->add('map', ((!empty($json->Map)) ? $json->Map : 'Los Santos/Blaine Country'));
        $result->add('mod', $json->Gamemode);
        $result->add('password', (int)$json->Passworded);
        $result->add('numplayers', $json->CurrentPlayers);
        $result->add('maxplayers', $json->MaxPlayers);

        return $result->fetch();
    }
229667
public function processResponse()
    {
        $rawResponse = $this->rawResponse;

        if (empty($rawResponse)) {
            return;
        }

        $responseData = unpack("Ccommand/Cstatus/Nidentifier", $rawResponse);

        $this->validateResponse($responseData);

        $statusCode = $responseData['status'];
        $errorDescription = self::$responseDescription[$statusCode];

        if (
               $statusCode == self::ERROR_INVALID_TOKEN_SIZE
            || $statusCode == self::ERROR_INVALID_TOKEN
        ) {
            $recipients = $this->recipients;
            $recipients->current()->setIdentifierStatus(RecipientDevice::DEVICE_NOT_REGISTERED);

            throw new InvalidRecipientException($errorDescription, $recipients);
        }

        throw new DispatchMessageException($errorDescription, $statusCode);
    }
777757
public function process()
    {
        // Check if we should verify the request
        if ($this->configuration->getUseAuthorization()) {
            if (
                $this->uri != '/token' &&
                $this->uri != '/authorize' &&
                !$this->tokenServer->verifyResourceRequest(\OAuth2\Request::createFromGlobals())
            ) {
                // Get the data as json and convert it to an array,
                // - so we can set our own response type.
                $data = $this->tokenServer->getResponse()->getResponseBody('json');
                $data = json_decode($data, true);

                // Set the response, status code and output content setting final output to true
                $this->response = $data;
                $this->statusCode = $this->tokenServer->getResponse()->getStatusCode();
                $this->output(true);
                return $this;
            }
        }

        try {
            // Handle OPTIONS requests
            if ($this->method == 'options') {
                $this->handleOptionsRequest();
            } else {
                // Execute the router
                $this->router->execute();
            }
        } catch (\Exception $e) {
            // Set the response and status code to error
            $this->response = ['error' => 1, 'message' => $e->getMessage()];
            $this->statusCode = 500;
        }

        // Output the response
        $this->output();
    }