Example #1
0
File: Set.php Project: 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;
 }
Example #2
0
 /**
  * @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;
 }