示例#1
0
文件: Set.php 项目: volux/dom
 /**
  * @param mixed $value
  *
  * @return $this
  */
 public function append($value)
 {
     if (is_scalar($value)) {
         $value = $this->ownerDocument->createText($value);
     }
     parent::append($value);
     return $this;
 }
示例#2
0
文件: Element.php 项目: volux/dom
 /**
  * @param null|string $newText
  * @param bool $replace
  *
  * @return $this|Element|Tag|Field|Set|Text
  */
 public function text($newText = null, $replace = true)
 {
     if (!is_null($newText)) {
         if ($replace) {
             $this->children()->remove();
             if ($newText instanceof Set) {
                 foreach ($newText as $node) {
                     $this->nodeValue .= $node->nodeValue;
                 }
                 return $this;
             }
             if ($newText instanceof \DOMNode) {
                 $this->nodeValue = $newText->nodeValue;
                 return $this;
             }
             $this->nodeValue = (string) $newText;
             return $this;
         }
         if ($newText instanceof Set) {
             foreach ($newText as $entry) {
                 /** @var $entry Element|Attr|Text|Cdata|Comment */
                 $this->text($entry->text());
             }
             return $this;
         }
         if ($newText instanceof \DOMNode) {
             $newTextNode = $this->ownerDocument->createText($newText->nodeValue);
         } else {
             $newTextNode = $this->ownerDocument->createText($newText);
         }
         $this->appendChild($newTextNode);
         return $this;
     }
     return $this->nodeValue;
 }