Example #1
0
 protected function mergeElementSimple(dom\element $current, dom\element $import)
 {
     $result = $import->replace($current);
     $current->remove();
     return $result;
 }
Example #2
0
 public function includeElement(dom\element $el, dom\element $ext = null)
 {
     $sPrefixes = 'extension-element-prefixes';
     if ($this->isEmpty()) {
         $this->throwException(sprintf('Cannot import in empty template'));
     }
     if ($sResult = $el->getAttribute($sPrefixes)) {
         if ($sTarget = $this->getAttribute($sPrefixes)) {
             $aTarget = explode(' ', $sTarget);
             $aResult = $aPrefixes = array_diff(explode(' ', $sResult), $aTarget);
         } else {
             $aTarget = array();
             $aResult = $aPrefixes = explode(' ', $sResult);
         }
         foreach ($aPrefixes as $iPrefix => $sPrefix) {
             if (!$this->getNamespace($sPrefix)) {
                 if ($sNamespace = $el->getNamespace($sPrefix)) {
                     // TODO to add a namespace
                     $this->setAttribute($sPrefix . ':ns', 'null', $sNamespace);
                     // $this->setAttribute('xmlns:'.$sPrefix, $sNamespace);
                 } else {
                     unset($aResult[$iPrefix]);
                 }
             }
         }
         $this->setAttribute($sPrefixes, implode(' ', array_merge($aResult, $aTarget)));
     }
     if ($ext) {
         switch ($ext->getName(true)) {
             case 'include':
                 $ext->replace($el->getChildren());
                 break;
             case 'import':
                 $this->add($el->getChildren());
                 break;
             default:
                 $this->throwException(sprintf('Cannot import document in empty template with %s', $ext->asToken()));
         }
     } else {
         $this->shift($el->getChildren());
     }
 }