コード例 #1
0
ファイル: Text.php プロジェクト: mekras/atom
 /**
  * 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;
 }
コード例 #2
0
ファイル: Content.php プロジェクト: mekras/atom
 /**
  * Set new content.
  *
  * For "text" and "html" $type values $content should be a string.
  *
  * For "xhtml" and all XML-based $type values $content should be an instance of
  * @{link DOMElement}.
  *
  * In all other cases $content should be a binary string and it will be base64 encoded.
  *
  * When $type is "xhtml" child nodes of $content will be moved to "xhtml:div" container.
  *
  * @param string|\DOMElement $content
  * @param string             $type
  *
  * @throws \InvalidArgumentException If $content type does not match given $type.
  *
  * @since 1.0
  */
 public function setContent($content, $type = 'text')
 {
     $type = (string) $type;
     $this->setType($type);
     $document = $this->getDomElement()->ownerDocument;
     if ('text' === $type || 'html' === $type) {
         $this->getDomElement()->nodeValue = (string) $content;
     } elseif ('xhtml' === $type) {
         if (!$content instanceof \DOMElement) {
             throw new \InvalidArgumentException('Content should be an instance of DOMElement');
         }
         Xhtml::import($content, $this->getDomElement());
     } elseif ($this->isXmlMimeType($type)) {
         if (!$content instanceof \DOMElement) {
             throw new \InvalidArgumentException('Content should be an instance of DOMElement');
         }
         $this->getDomElement()->appendChild($document->importNode($content, true));
     } elseif (stripos($type, 'text/') === 0) {
         $this->getDomElement()->nodeValue = (string) $content;
     } else {
         $this->getDomElement()->nodeValue = base64_encode($content);
     }
     $this->setCachedProperty('content', $content);
 }