Parse the body based on the content type.

@return mixed
@throws \RuntimeException if parsing isn't supported for the content-type
340889
protected function parseBody()
    {
        $data = null;
        
        switch ($this->getContentType()) {
            case 'application/x-www-form-urlencoded':
                $data = $this->parseUrlEncodedBody();
                break;
            case 'application/json':
                $data = $this->parseJsonBody();
                break;
            case 'text/xml':
            case 'application/xml':
                $data = $this->parseXmlBody();
                break;
            case 'multipart/form-data':
                throw new \RuntimeException("Parsing multipart/form-data isn't supported");
        }
        
        return $data;
    }
494028
public function getRawContent()
    {
        if ($this->size == 0) {
            return '';
        }

        if ($this->encoding === 'base64') {
            $raw = base64_decode($this->content, true);
            if ($raw === false) {
                throw new \RuntimeException('Failed to decode content');
            }

            return $raw;
        }

        throw new \RuntimeException('Unrecognised blob encoding: ' . $this->encoding);
    }
157012
protected function parseDataFromResponse()
    {
        $content = $this->rawResponse->body;
        $config = new WebsiteConfig();
        $config->parseFromXml($content);
        return $config;
    }
769096
public function getParsedBody()
    {
        if ($this->parsedBody !== false) {
            return $this->parsedBody;
        }

        $mediaType = $this->getMediaType();

        $parts = explode('+', $mediaType);
        if (count($parts) >= 2) {
            $mediaType = 'application/' . $parts[count($parts) - 1];
        }
        unset($parts);

        if (isset($this->bodyParsers[$mediaType])) {
            $body = (string) $this->getBody();
            $parsed = $this->bodyParsers[$mediaType]($body);

            $this->parsedBody = $parsed;

            unset($parsed, $body, $mediaType);

            return $this->parsedBody;
        }

        return null;
    }
1297672
public function getBody()
    {
        $streamResource = fopen('php://memory', 'r+');
        if (is_resource($this->content)) {
            stream_copy_to_stream($this->content, $streamResource);
        } else {
            fwrite($streamResource, $this->content);
        }
        rewind($streamResource);

        return new ContentStream($streamResource);
    }
858478
protected function parse(): void
    {
        // add the root node
        $this->root = new HtmlNode('root');
        $activeNode = $this->root;
        while ( ! is_null($activeNode)) {
            $str = $this->content->copyUntil('<');
            if ($str == '') {
                $info = $this->parseTag();
                if ( ! $info['status']) {
                    // we are done here
                    $activeNode = null;
                    continue;
                }

                // check if it was a closing tag
                if ($info['closing']) {
                    $foundOpeningTag  = true;
                    $originalNode     = $activeNode;
                    while ($activeNode->getTag()->name() != $info['tag']) {
                        $activeNode = $activeNode->getParent();
                        if (is_null($activeNode)) {
                            // we could not find opening tag
                            $activeNode = $originalNode;
                            $foundOpeningTag = false;
                            break;
                        }
                    }
                    if ($foundOpeningTag) {
                        $activeNode = $activeNode->getParent();
                    }
                    continue;
                }

                if ( ! isset($info['node'])) {
                    continue;
                }

                /** @var AbstractNode $node */
                $node = $info['node'];
                $activeNode->addChild($node);

                // check if node is self closing
                if ( ! $node->getTag()->isSelfClosing()) {
                    $activeNode = $node;
                }
            } else if ($this->options->whitespaceTextNode ||
                trim($str) != ''
            ) {
                // we found text we care about
                $textNode = new TextNode($str, $this->options->removeDoubleSpace);
                $activeNode->addChild($textNode);
            }
        }
    }
1279255
public function getBody(): Parameters
	{
		if($this->parsedBody === null)
		{
			$this->parsedBody = new Body($this->getRawBody(), $this->getContentType());
		}

		return $this->parsedBody;
	}
761814
protected function parseDataFromResponse()
    {
        $content = $this->rawResponse->body;
        if (empty($content)) {
            throw new OssException("body is null");
        }
        $xml = simplexml_load_string($content);
        if (isset($xml->StorageCapacity)) {
            return intval($xml->StorageCapacity);
        } else {
            throw new OssException("xml format exception");
        }
    }
1042331
private function parse() {
        $data = json_decode($this->httpResponse->getBody(), true);

        foreach ($data['messages'] as $message) {
            $msg = new Message($message);
            $this->messages[] = $msg;

            if ($message['type'] === 'error' || $message['type'] === 'non-document-error') {
                $this->errors[] = $msg;
            } else if ($message['type'] === 'warning') {
                $this->warnings[] = $msg;
            }
        }
    }
250355
protected function getBody()
    {
        $objNew = new \stdClass();
        $i = 1;
        $subType = new SubtypeBody();
        foreach ($this->getSections(self::SECTION_BODY) as $section) {
            $obj = $this->getSection($section, array('class' => $subType));
            $subtype = strtolower($obj->__get('structure')->subtype);
            if (!isset($objNew->$subtype)) {
                $objNew->$subtype = $obj;
            } else {
                $subtype = $subtype.'_'.$i;
                $objNew->$subtype = $obj;
                $i++;
            }
            $objNew->info[] = $obj;
            $objNew->types[] = $subtype;
            /*
             * Set charset
             */
            foreach ($objNew->$subtype->__get('structure')->parameters as $parameter) {
                $attribute = strtolower($parameter->attribute);
                if ($attribute === 'charset') {
                    $value = strtolower($parameter->value);
                    /*
                     * Here must be array, but
                     */
                    //$objNew->$subtype->charset[] = $value;
                    $objNew->$subtype->charset = $value;
                }
            }
        }
        if (isset($objNew->plain)) {
            switch ($objNew->plain->structure->encoding) {
                case 3:
                    $objNew->text = imap_base64(mb_convert_encoding( $objNew->plain, "utf-8", $objNew->plain->charset ));
                    break;
                default:
                    $objNew->text = quoted_printable_decode(mb_convert_encoding( $objNew->plain, "utf-8", $objNew->plain->charset ));
                    break;
            }
            $objNew->types[] = 'text';
        } else {
            $objNew->text = null;
        }
        $this->message = $objNew;
    }
900995
function parseBody()
    {
        $request = $this->getMessageObject();

        $reqID   = spl_object_hash($request);
        if ( isset(self::$_parsed[$reqID]) )
            // parse from cached
            return self::$_parsed[$reqID];

        if ($request->headers()->has('content-type')) {
            $contentType = \Poirot\Http\Header\renderHeaderValue($request, 'content-type');
            $contentType = strtolower($contentType);

        } else {
            // No Any Data Sent .....
            return array();
        }


        // Content-Type May be in form of:
        // application/x-www-form-urlencoded; charset=utf-8
        // when we call from jquery/ajax in exm.
        if ( false !== $pos = strpos($contentType, ';') )
            $contentType = substr($contentType, 0, $pos);


        switch ( $contentType )
        {
            case 'application/json':
                $parsedData = $this->_parseJsonDataFromRequest($request);
                break;

            case 'application/x-www-form-urlencoded':
                $parsedData = $this->_parseUrlEncodeDataFromRequest($request);
                break;
            case strpos($contentType, 'multipart') !== false:
                $parsedData = $this->_parseMultipartDataFromRequest($request);
                break;

            default:
                throw new \Exception(sprintf(
                    'Request Body Contains No Data or Unknown Content-Type (%s).'
                    , $contentType
                ));
        }


        return self::$_parsed[$reqID] = $parsedData;
    }
991453
public function returnBody()
    {
        $body = $this->getBody();
        $text = '';

        if ($body->hasChildNodes()) {
            foreach ($body->childNodes as $child) {
                $text .= $this->dom->saveXML($child);
            }
        }

        return Horde_String::convertCharset($text, 'UTF-8', $this->_origCharset);
    }
1247242
public function getHtmlBody(){
        $bodies = $this->parent->getBodies();
        if (!isset($bodies['html'])) {
            return null;
        }

        return $bodies['html']->content;
    }
291098
private function parseInput()
    {
        $result = null;
        try {
            $rawBody = file_get_contents('php://input');
            $obj = json_decode($rawBody);
            if ($obj) {
                $type = $this->getInDataType();
                $result = $this->inputProcessor->convertValue($obj, $type);
            }
        } catch (\Throwable $t) {
            $this->logger->error("Cannot parse input data: " . $t->getMessage());
        }
        return $result;
    }
768706
protected function prepareParsedBody()
    {
        if ($this->method == self::METHOD_POST &&
            in_array($this->getMediaType(), ['application/x-www-form-urlencoded', 'multipart/form-data'])
        ) {
            return $_POST;
        } else {
            $body = (string)$this->getBody();

            switch ($this->getMediaType()) {
                case 'application/json':
                    return json_decode($body, true);

                case 'application/xml':
                    return simplexml_load_string($body);

                default:
                    parse_str($body, $output);

                    return $output;
            }
        }
    }
914938
protected function parseContent()
    {
        $contentString = strtok($this->query, '/');

        $content = [];
        $delim = '(),';
        $tok = strtok($contentString, $delim);
        while ($tok !== false) {
            $content[] = $tok;
            $tok = strtok($delim);
        }

        $this->contentTypes = $content;
    }
1215716
public final function getContents(): string
   {
       if (!$this->isReadable()) {
           throw new RuntimeException(
               "Can't getContents: stream is not readable");
       }
       $this->meta["eof"] = true;
       return (string) stream_get_contents($this->stream);
   }