Parse response

@return array Parsed response
190620
public function parse()
    {
        if ($this->body === false) {
            return null;
        }

        $result = [];
        $key = null;
        foreach ($this->body as $value) {
            if (!is_null($key)) {
                $result[$key] = $value;
                $key = null;
            } else {
                $key = $value;
            }
        }

        return $result;
    }
1072670
protected function parseAutodiscoverResponse()
    {
        // Content-type isn't trustworthy, unfortunately. Shame on Microsoft.
        if (substr($this->last_response, 0, 5) !== '<?xml') {
            return false;
        }

        $response = $this->responseToArray($this->last_response);

        if (isset($response['Error'])) {
            $this->error = $response['Error'];
            return false;
        }

        // Check the account action for redirect.
        switch ($response['Account']['Action']) {
            case 'redirectUrl':
                $this->redirect = array(
                    'redirectUrl' => $response['Account']['RedirectUrl']
                );
                return false;
            case 'redirectAddr':
                $this->redirect = array(
                    'redirectAddr' => $response['Account']['RedirectAddr']
                );
                return false;
            case 'settings':
            default:
                $this->discovered = $response;
                return true;
        }
    }
632711
public function parseToken()
    {
        foreach ($this->chain as $parser) {
            if ($response = $parser->parse($this->request)) {
                return $response;
            }
        }
    }
925059
public function getResponse()
    {
        $this->execute();
        
        switch ($this->def['dataType']) {
            case 'array':
                $result = static::toArray();
                break;
            case 'object':
            case 'json':
                $result = static::toJson();
                break;
            default:
                $result = $this->getErrorString() ? : $this->responseText;
        }
        
        return $result;
    }
1280779
public function getArray()
  {
    $errors = empty($this->errors) ? null : $this->errors;

    $response = array(
        'status' => $this->getStatus(),
        'data'   => $this->data,
        'errors' => $errors,
    );

    if (!is_null($this->code)) {
      $response['code'] = $this->code;
    }

    if (!is_null($this->message)) {
      $response['message'] = $this->message;
    }

    return $response;
  }
985598
public function parse()
    {
        $input = $this->queryString;

        // Parse string if it's not already parsed into an array
        if (is_string($this->queryString)) {
            $input = [];
            parse_str($this->queryString, $input);
        }

        $this->query = new Query($input);

        $this->parseQ();
        $this->parseEmbeds();
        $this->parseIncludes();
        $this->parseExcludes();
        $this->parseSorts();

        return $this->query;
    }
1089269
function response()
    {
        if (!$this->response) {
            $settings = new DataParseResponsePhp;
            $response = new HttpResponse(
                new BuildHttpResponse( BuildHttpResponse::parseWith($settings) )
            );

            $this->response = $response;
        }

        return $this->response;
    }
401068
private function parse($response_xml)
  {
      $xml = simplexml_load_string($response_xml);
      $response = array();

      $response['error_code'] = (string) $xml->ERRORCODE;
      $response['message'] = (string) $xml->ERRORMESSAGE;
      $response['reference'] = (string) $xml->REFERENCE;
      $response['proxypay_ref'] = (string) $xml->PROXYPAYREF;
      $response['sequence'] = (string) $xml->SEQUENCE;

      return $response;
  }
147445
public static function parse(string $response) : Response
    {
        $responseObject = new Response();

        if (preg_match('/^HTTP\/([0-9]\.[0-9]) ([0-9]{3}) .*\r\n/', $response, $matches) !== 1) {
            throw new \RuntimeException('Could not parse response (error 1).');
        }

        [$line, $protocolVersion, $statusCode] = $matches;

        $responseObject->setProtocolVersion($protocolVersion);
        $responseObject->setStatusCode((int) $statusCode);

        $response = substr($response, strlen($line));

        for (;;) {
            $pos = strpos($response, Message::CRLF);
            if ($pos === false) {
                throw new \RuntimeException('Could not parse response (error 2).');
            }

            if ($pos === 0) {
                break;
            }

            $header = substr($response, 0, $pos);

            if (preg_match('/^(\S+):\s*(.*)$/', $header, $matches) !== 1) {
                throw new \RuntimeException('Could not parse response (error 3).');
            }

            [$line, $name, $value] = $matches;

            if (strtolower($name) === 'set-cookie') {
                $responseObject->setCookie(Cookie::parse($value));
            } else {
                $responseObject->addHeader($name, $value);
            }

            $response = substr($response, strlen($line) + 2);
        }

        $body = substr($response, 2);

        $responseObject->setContent($body);

        return $responseObject;
    }
969423
public function parse()
    {
        try {
            $this->ensureFileIsReadable();
        } catch (InvalidPathException $e) {
            return [];
        }

        $filePath = $this->filePath;
        $lines = $this->readLinesFromFile($filePath);

        $data = [];
        foreach ($lines as $line) {
            if (!$this->isComment($line) && $this->looksLikeSetter($line)) {
                list($name, $value) = $this->processFilters($line, null);
                $data[$name] = $value;
            }
        }

        return $data;
    }
157012
protected function parseDataFromResponse()
    {
        $content = $this->rawResponse->body;
        $config = new WebsiteConfig();
        $config->parseFromXml($content);
        return $config;
    }
958786
protected function parse()
    {
        try {
            $data = app(Browscap::class)->getBrowser($this->userAgent);
        } catch (Exception $e) {
            return;
        }

        foreach ($data as $key => $value) {
            // Force lowercase on key
            $key = strtolower($key);

            // Remove whitespaces from value
            $value = trim($value);

            // Switch it up!
            switch ($key) {
                case 'ismobiledevice':
                    $this->isMobile = !empty($value);
                    break;
                case 'istablet':
                    $this->isTablet = !empty($value);
                    break;
                case 'crawler':
                    $this->isCrawler = !empty($value);
                    break;
                case 'majorver':
                    $this->majorVersion = (int) $value;
                    break;
                case 'minorver':
                    $this->minorVersion = (int) $value;
                    break;
                case 'device_type':
                    $this->device = $value;
                    break;
                case 'device_pointing_method':
                    $this->devicePointer = $value;
                    break;
                case 'browser_maker':
                    $this->publisher = $value;
                    break;
                case 'comment':
                    $this->browserWithVersion = $value;
                    break;
                case 'browser':
                case 'platform':
                    $this->{$key} = $value;
                    break;
            }
        }

        // Set version and if major and minor
        // wasn't present in the data array
        // we'll set them as well
        $this->setVersion($data->version);

        // Mark parsing as successful
        $this->successful = true;
    }
164807
protected function parseBody(): array
    {
        if ($this->getRequest()->headers->get('Content-Type') === 'application/json') {
            $dataCollection = json_decode($this->getRequest()->getContent(), true);
        } else {
            if ($this->getRequest()->isMethod('POST')) {
                $dataCollection = array_merge(
                    $this->getRequest()->request->all(),
                    $this->getRequest()->files->all()
                );
            } else {
                parse_str($this->getRequest()->getContent(), $dataCollection);
            }
        }

        return $dataCollection;
    }
17231
public function toArray()
    {
        $response = [
            'type' => $this->type,
            'className' => $this->className
        ];

        if (count($this->properties)) {
            $response['properties'] = [];

            foreach ($this->properties as $property) {
                $response['properties'][$property->getName()] = $property->toArray();
            }
        }

        return $response;
    }
808902
protected function parseResponseHeaders()
    {
        if ($this->responseHeader !== null) {
            $headers = explode("\n", $this->responseHeader);
            foreach ($headers as $header) {
                if (strpos($header, 'HTTP') !== false) {
                    $this->version = substr($header, 0, strpos($header, ' '));
                    $this->version = substr($this->version, (strpos($this->version, '/') + 1));
                    preg_match('/\d\d\d/', trim($header), $match);
                    $this->code = $match[0];
                    $this->message = trim(str_replace('HTTP/'.$this->version.' '.$this->code.' ', '', $header));
                } elseif (strpos($header, ':') !== false) {
                    $name = substr($header, 0, strpos($header, ':'));
                    $value = substr($header, strpos($header, ':') + 1);
                    $this->responseHeaders[trim($name)] = trim($value);
                }
            }
        }
    }
758145
public function getResponse()
    {
        $curl = curl_init();

        $this->addParameters()->addHeaders();
        $this->options[CURLOPT_RETURNTRANSFER] = true;
        curl_setopt_array($curl, $this->options);

        $response = curl_exec($curl);

        $this->meta = array(
            'info'             => curl_getinfo($curl, CURLINFO_HTTP_CODE),
            'error_message'    => curl_errno($curl),
            'error_code'    => curl_error($curl));

        curl_close($curl);
        unset($curl);

        return $response;
    }
362584
public function parseData()
    {
        $headers = $this->getHeaders();

        if (!in_array($this->httpRequest->getMethod(), ['PUT', 'POST'])) {
            return $this->emit('end');
        }

        $this->httpRequest->on('data', function($data) use ($headers, &$dataResult) {
            $dataResult .= $data;

            if (isset($headers["content-length"])) {
                if (strlen($dataResult) == $headers["content-length"][0]) {
                    $this->httpRequest->close();
                }
            } else {
                $this->httpRequest->close();
            }
        });

        $this->httpRequest->on('end', function() use (&$dataResult) {
            $this->onEnd($dataResult);
        });
    }