FluentDOM\Element::append PHP Метод

append() публичный Метод

The value can be: - a node (automatically imported and cloned) - an object implementing FluentDOM\Appendable (method appendTo()) - a scalar or object castable to string (adds a text node) - an array (sets attributes)
public append ( mixed $value )
$value mixed
    public function append($value)
    {
        if ($value instanceof \DOMAttr) {
            $this->setAttributeNode($value->ownerDocument === $this->ownerDocument ? $value : $this->ownerDocument->importNode($value));
        } elseif ($value instanceof Appendable) {
            $namespaces = $this->ownerDocument->namespaces();
            $value->appendTo($this);
            $this->ownerDocument->namespaces($namespaces);
        } elseif ($value instanceof \Closure && !$value instanceof \DOMNode) {
            $this->append($value());
        } elseif (is_array($value)) {
            $nodes = [];
            foreach ($value as $name => $data) {
                if (QualifiedName::validate($name)) {
                    $this->setAttribute($name, (string) $data);
                } else {
                    $nodes[] = $data;
                }
            }
            $this->appendToParentNode($nodes);
        } else {
            $this->appendToParentNode($value);
        }
        return $this;
    }

Usage Example

Пример #1
0
 /**
  * @param Element $parent
  * @return Element
  */
 public function appendTo(Element $parent)
 {
     foreach ($this as $item) {
         $parent->append($item);
     }
     return $parent;
 }