Goetas\Twital\Helper\DOMHelper::replaceWithSet PHP Method

replaceWithSet() public static method

public static replaceWithSet ( DOMNode $node, array $newNodes )
$node DOMNode
$newNodes array
    public static function replaceWithSet(\DOMNode $node, array $newNodes)
    {
        self::insertAfterSet($node, $newNodes);
        $node->parentNode->removeChild($node);
    }

Usage Example

Beispiel #1
0
 public function visit(\DOMElement $node, Compiler $context)
 {
     if ($node->hasAttribute("from-exp")) {
         $filename = $node->getAttribute("from-exp");
     } elseif ($node->hasAttribute("from")) {
         $filename = '"' . $node->getAttribute("from") . '"';
     } else {
         throw new Exception("The 'from' or 'from-exp' attribute is required");
     }
     // remove any non-element node
     foreach (iterator_to_array($node->childNodes) as $child) {
         if (!$child instanceof \DOMElement) {
             $child->parentNode->removeChild($child);
         }
     }
     $context->compileChilds($node);
     $code = "embed {$filename}";
     if ($node->hasAttribute("ignore-missing") && $node->hasAttribute("ignore-missing") !== false) {
         $code .= " ignore missing";
     }
     if ($node->hasAttribute("with")) {
         $code .= " with " . $node->getAttribute("with");
     }
     if ($node->hasAttribute("only") && $node->getAttribute("only") !== "false") {
         $code .= " only";
     }
     $ext = $context->createControlNode($code);
     $set = iterator_to_array($node->childNodes);
     $n = $node->ownerDocument->createTextNode("\n");
     array_unshift($set, $n);
     array_unshift($set, $ext);
     $set[] = $context->createControlNode("endembed");
     DOMHelper::replaceWithSet($node, $set);
 }
All Usage Examples Of Goetas\Twital\Helper\DOMHelper::replaceWithSet