Skip to content

Instantly share code, notes, and snippets.

@TheFrozenFire
Created August 24, 2013 03:58
Show Gist options
  • Save TheFrozenFire/6325971 to your computer and use it in GitHub Desktop.
Save TheFrozenFire/6325971 to your computer and use it in GitHub Desktop.
protected function transmuteTags(DOMNode $contextNode = null)
{
$xpath = new DOMXPath($this);
$tagList = $this->getTagList();
if(!$contextNode) {
$contextNode = $this->documentElement;
}
if($contextNode->hasChildNodes()) {
foreach($contextNode->childNodes as $tag) {
if($tagName = array_search($tag->nodeName, $tagList)) {
$tagClass = Dialplan::ns().'\\'.$tagName;
$newTag = new $tagClass;
$contextNode->replaceChild($newTag, $tag);
static::transmuteTag($tag, $newTag);
$this->transmuteTags($newTag);
} else {
$this->transmuteTags($tag);
}
}
}
}
protected static function transmuteTag(DOMNode $tag, DOMNode $newTag)
{
foreach($tag->attributes as $attribute) {
$newTag->setAttributeNode($attribute);
}
foreach($tag->childNodes as $child) {
$newTag->appendChild($child);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment