Takes responses for this field type and aggregates them into data suitable for stats/charting

@param  array $aResponses The array of responses from ResponseAnswer

@return array
431781
public function getStatsChartData($aResponses)
    {
        $aOut = [
            'columns' => [
                ['string', 'Label'],
                ['number', 'Responses'],
            ],
            'rows'    => [],
        ];

        if (!static::SUPPORTS_OPTIONS) {
            return $aOut;
        }

        //  Work out all the options and assign a value
        $aRows = [];
        foreach ($aResponses as $oResponse) {
            if (!empty($oResponse->option)) {
                if (!array_key_exists($oResponse->option->label, $aRows)) {
                    $aRows[$oResponse->option->label] = 0;
                }
                $aRows[$oResponse->option->label]++;
            }
        }

        foreach ($aRows as $sLabel => $iValue) {
            $aOut['rows'][] = [
                $sLabel,
                $iValue,
            ];
        }

        //  Return the details for a single chart (i.e only 1 item in this array)
        return [$aOut];
    }
1060074
public function generateDefaultResponse(array $params): Response
    {
        $response = [
            'took' => 0,
            'timed_out' => false,
            '_shards' => [
                'total' => 0,
                'successful' => 0,
                'failed' => 0,
            ],
            'hits' => [
                'total' => 0,
                'max_score' => null,
                'hits' => [],
            ],
            'params' => $params,
        ];

        return new Response(JSON::stringify($response));
    }
1182440
function getResponseHeaders($options = array()){
		$options = array_merge(array(
			"as_hash" => false,
			"lowerize_keys" => false
		),$options);

		$this->fetchContent();

		$out = $this->_ResponseHeaders;

		if($options["as_hash"]){
			$headers = explode("\n",$out);
			$out = array();
			foreach($headers as $h){
				if(preg_match("/^([^ ]+):(.*)/",trim($h),$matches)){
					$key = $options["lowerize_keys"] ? strtolower($matches[1]) : $matches[1];
					$out[$key] = trim($matches[2]);
				}
			}
		}

		return $out;
	}
231921
public function getResponseHeaders()
    {
        if ($this->offsetExists('headers') && is_array($this->headers)) {
            $headers = $this->headers;
        } else {
            $headers = [];
        }
        if (!array_key_exists('X-UA-Compatible', $headers)) {
            $headers['X-UA-Compatible'] = 'IE=edge,chrome=1';
        }

        // Remove null/empty values, this allow you to remove the X-UA-Compatible by making it empty.
        return array_filter($headers);
    }
965443
protected function responseToArray($rawResponse)
    {
        $body = (string) $rawResponse->getBody();
        $code = $rawResponse->getStatusCode();

        if ($code !== 204) {
            $response = json_decode($body, true);
            if (json_last_error() !== JSON_ERROR_NONE) {
                $response = ['body' => trim($body)];
            }
        } else {
            $response = '';
        }

        return (200 <= $code && $code <= 299 ? $response : ($response ?: $this->jsonError($rawResponse)))
            ?: [];
    }
973700
public function getHttpResponse(array $headers = [])
    {
        $client = new Client();
        $urls = $this->getUrl();

        return $client->request('GET', $urls[0], ['stream' => true, 'headers' => $headers]);
    }
93979
public function convertResponse($response, $serviceResource)
    {
        $resourceName = substr($serviceResource, 0, -2);
        return $this->_convertResponseToModel($response, $resourceName);
    }
976209
private function parseForecastResponseHeaders($headers)
    {
        $responseHeaders = [
            'cache' => [
                'maxAge' => null,
                'expires' => null
            ],
            'responseTime' => null,
            'apiCalls' => null
        ];
        foreach ($headers as $header) {
            switch (true) {
                case (substr($header, 0, 14) === 'Cache-Control:'):
                    $responseHeaders['cache']['maxAge'] = trim(substr($header, strrpos($header, '=') + 1));
                    break;
                case (substr($header, 0, 8) === 'Expires:'):
                    $responseHeaders['cache']['expires'] = trim(substr($header, 8));
                    break;
                case (substr($header, 0, 21) === 'X-Forecast-API-Calls:'):
                    $responseHeaders['apiCalls'] = trim(substr($header, 21));
                    break;
                case (substr($header, 0, 16) === 'X-Response-Time:'):
                    $responseHeaders['responseTime'] = (int)trim(substr($header, 16));
                    break;
                default:
                    break;
            }
        }
        return $responseHeaders;
    }
764081
private function getResult($response)
    {
        $status = $response->getStatusCode();
        if ($status == 200) {
            return json_decode($response->getBody(), JSON_PRETTY_PRINT);
        } else {
            return [$status => $response->getReasonPhrase()];
        }
    }
716463
public function getDeclinationDataFromResponse()
    {
        $aDeclinationData = array();
        $aResponse        = $this->getResponse();
        $aExpectedKeys    = array('paymentMethod_name', 'paymentMethod_status', 'paymentMethod_declineType');

        foreach ( $aExpectedKeys as $sKey ) {
            if ( array_key_exists( $sKey, $aResponse ) ) {
                $aDeclinationData[$sKey] = $aResponse[$sKey];
            }
        }

        return $aDeclinationData;
    }
1361039
public function getResults($response)
    {
        $results = array('rows' => array());

        for ($report_index = 0; $report_index < count($response); $report_index++) {

            $report = $response[$report_index];
            $header = $report->getColumnHeader();

            $dimension_headers = $header->getDimensions();
            $metric_headers = $header->getMetricHeader()->getMetricHeaderEntries();
            $rows = $report->getData()->getRows();

            for ($row_index = 0; $row_index < count($rows); $row_index++) {

                $row = $rows[$row_index];
                $dimensions = $row->getDimensions();
                $metrics = $row->getMetrics();

                for ($i = 0; $i < count($dimension_headers) && $i < count($dimensions); $i++) {
                    $results['rows'][$row_index][$dimension_headers[$i]] = $dimensions[$i];
                }

                for ($j = 0; $j < count($metrics); $j++) {
                    $values = $metrics[$j]->getValues();
                    for ($k = 0; $k < count($values); $k++) {
                        $entry = $metric_headers[$k];
                        $results['rows'][$row_index][$entry->getName()] = $values[$k];
                    }
                }
            }
        }

        return $results;
    }
496220
public function getAnswer(array $queries): array
    {
        $answer = [];
        foreach ($queries as $query) {
            $answer = array_merge($answer, $this->getRecordsRecursively($query));
        }

        return $answer;
    }
808342
protected function getBatchResponses(ResponseInterface $response)
    {
        $results = JsonRpc\json_decode((string) $response->getBody(), true);

        return array_map(function (array $result) use ($response) {
            return $this->messageFactory->createResponse(
                $response->getStatusCode(),
                $response->getHeaders(),
                $result
            );
        }, $results);
    }
836372
protected function parseResponse(array $responseRaw = [])
    {
        $result = [];

        if (count($responseRaw) === 0) {
            return $result;
        } elseif (strpos($responseRaw[0], '%PDF-') !== false) {
            return ['rawResponse' => base64_encode(implode("\n", array_values($responseRaw)))];
        }

        foreach ($responseRaw as $key => $line) {
            $pos = strpos($line, '=');

            if ($pos === false) {
                if (strlen($line) > 0) {
                    $result[$key] = $line;
                }
                continue;
            }

            $lineArray = explode('=', $line);
            $resultKey = array_shift($lineArray);
            $result[$resultKey] = implode('=', $lineArray);
        }

        return $result;
    }
684042
public static function normalizeResponse(DataTablesResponseInterface $response) {

        $output = [];

        $output["data"]            = $response->getData();
        $output["draw"]            = $response->getDraw();
        $output["recordsFiltered"] = $response->getRecordsFiltered();
        $output["recordsTotal"]    = $response->getRecordsTotal();

        return $output;
    }
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();
    }
73667
public function getResponseMap()
    {
        $mappedFields = [];
        foreach (['headers', 'body'] as $type) {
            if (isset($this->responseExpected->{$type}) && isset($this->responseActual[$type])) {
                foreach ($this->responseExpected->{$type} as $value) {
                    if (!empty($value->destination) && !empty($value->key) && !empty($this->responseActual[$type][$value->key])) {
                        // We have a non-empty value with a mapped destination.
                        $mappedFields[$value->destination] = $this->responseActual[$type][$value->key];
                    }
                }
            }
        }

        return $mappedFields;
    }