Httpful\Response::_parse PHP Method

_parse() public method

Parse the response into a clean data structure (most often an associative array) based on the expected Mime type.
public _parse ( $body ) : array | string | object
return array | string | object the response parse accordingly
    public function _parse($body)
    {
        // If the user decided to forgo the automatic
        // smart parsing, short circuit.
        if (!$this->request->auto_parse) {
            return $body;
        }
        // If provided, use custom parsing callback
        if (isset($this->request->parse_callback)) {
            return call_user_func($this->request->parse_callback, $body);
        }
        // Decide how to parse the body of the response in the following order
        //  1. If provided, use the mime type specifically set as part of the `Request`
        //  2. If a MimeHandler is registered for the content type, use it
        //  3. If provided, use the "parent type" of the mime type from the response
        //  4. Default to the content-type provided in the response
        $parse_with = $this->request->expected_type;
        if (empty($this->request->expected_type)) {
            $parse_with = Httpful::hasParserRegistered($this->content_type) ? $this->content_type : $this->parent_type;
        }
        return Httpful::get($parse_with)->parse($body);
    }