Exemple #1
0
 /**
  * Return content
  *
  * @return string
  *
  * @throws \Mekras\Atom\Exception\MalformedNodeException If there is no required element.
  *
  * @since 1.0
  *
  * @link  https://tools.ietf.org/html/rfc4287#section-4.1.3.3
  */
 public function getContent()
 {
     return $this->getCachedProperty('content', function () {
         $type = $this->getType();
         if ('text' === $type || 'html' === $type) {
             return $this->getDomElement()->textContent;
         } elseif ('xhtml' === $type) {
             /** @var \DOMElement $xhtml */
             $xhtml = $this->query('xhtml:div', Node::SINGLE | Node::REQUIRED);
             return Xhtml::extract($xhtml);
         } elseif ($this->isXmlMimeType($type)) {
             /** @var \DOMElement $xml */
             $xml = $this->query('*', Node::SINGLE | Node::REQUIRED);
             return $this->getDomElement()->ownerDocument->saveXML($xml);
         } elseif (stripos($type, 'text/') === 0) {
             return $this->getDomElement()->textContent;
         }
         return base64_decode($this->getDomElement()->textContent);
     });
 }
Exemple #2
0
 /**
  * Return string value.
  *
  * @return string
  */
 private function parseContent()
 {
     if ($this->getType() === 'xhtml') {
         try {
             /** @var \DOMElement $xhtml */
             $xhtml = $this->query('xhtml:div', Node::SINGLE | Node::REQUIRED);
         } catch (MalformedNodeException $e) {
             return '';
         }
         return Xhtml::extract($xhtml);
     }
     return $this->getDomElement()->textContent;
 }