Example #1
0
 public function parseRoot(dom\element $el)
 {
     $this->setDirectory(__FILE__);
     $this->setNamespace($el->getNamespace(), self::PREFIX);
     $el = $this->setNode($el);
     $this->allowForeign(true);
     //$this->parseSource();
     return $this;
 }
Example #2
0
 public function loadElementForeignKnown(dom\element $el, reflector\elemented $parser)
 {
     switch ($this->getMode()) {
         case 'insert':
         case 'update':
             if ($el->getNamespace() == self::BINDER_NS) {
                 $result = null;
                 break;
             }
         default:
             $result = parent::loadElementForeignKnown($el, $parser);
     }
     return $result;
 }
Example #3
0
 protected function loadElementForeign(dom\element $el)
 {
     if ($parser = $this->getParser($el->getNamespace())) {
         $mResult = $parser->parseFromParent($el);
     } else {
         if ($parser = $this->lookupParserForeign($el->getNamespace())) {
             $mResult = $parser->parseFromChild($el);
         } else {
             if ($parser = $this->createParser($el->getNamespace())) {
                 $mResult = $parser->parseRoot($el);
             } else {
                 $mResult = $this->parseElementUnknown($el);
             }
         }
     }
     return $mResult;
 }
Example #4
0
 protected function parseChildrenElement(dom\element $el, array &$aResult, $bRoot = false)
 {
     try {
         if ($this->useNamespace($el->getNamespace())) {
             $this->parseChildrenElementSelf($el, $aResult);
         } else {
             $this->parseChildrenElementForeign($el, $aResult);
         }
     } catch (core\exception $e) {
         $e->addPath($el->asToken());
         throw $e;
     }
 }
Example #5
0
 public function parseRoot(dom\element $el)
 {
     $this->setDirectory(__FILE__);
     $this->setNamespace($el->getNamespace(), self::PREFIX);
     return $this->parseElement($el);
 }
Example #6
0
 /**
  * Build a new element from the source element, cannot copy cause of following steps
  *
  * - Check for foreign attributes.
  *   They define result if exists with @method parseAttributesForeign([new element]) (1st pass)
  * - Add parsed children to new element.
  * - Inform foreign attributes parser that element has been parsed with @method $parser->onClose
  *   This allow parsers to edit new element (2nd pass)
  *
  * These steps give the ability to attribute parsers to return element into new container
  *
  * @param dom\element $el
  * @return dom\element|mixed The new element or, if foreign attributes exists, result of parsing, so if result
  *         is changed on 1st pass and changes happened to new element on 2nd pass, they will we be ignored.
  */
 protected function loadElementUnknown(dom\element $el)
 {
     $newElement = $this->createElement($el->getName(), null, array(), $el->getNamespace());
     if ($this->useForeignAttributes($el)) {
         $aForeigns = $this->getForeignAttributes($el, $newElement);
         $mResult = $this->parseAttributesForeign($el, $newElement, $aForeigns);
     } else {
         foreach ($el->getAttributes() as $attr) {
             $newElement->add($this->parseAttribute($attr));
         }
         $mResult = $newElement;
     }
     $aParsers = $this->getAttributeParsers();
     $this->setAttributeParsers();
     //$this->startElement($newElement);
     if ($aChildren = $this->parseChildren($el->getChildren())) {
         $newElement->add($aChildren);
     }
     //$this->stopElement();
     return $mResult;
 }
Example #7
0
 protected function mergeElement(dom\element $current, dom\element $import, $bCheckNS = true)
 {
     if ($bCheckNS && $current->getNamespace() !== $import->getNamespace()) {
         $this->throwException(sprintf('Cannot merge elements with same name but different namespaces %s and %s', $current->asToken(), $import->asToken()));
     }
     if ($current->isComplex()) {
         if (!$import->isComplex()) {
             $this->throwException(sprintf('Cannot merge simple type %s on complex type %s', $import->asToken(), $current->asToken()));
         }
         $this->mergeElementComplex($current, $import);
     } else {
         if ($import->isComplex()) {
             $this->throwException(sprintf('Cannot merge complex type %s on simple type %s', $import->asToken(), $current->asToken()));
         }
         $this->mergeElementSimple($current, $import);
     }
 }
Example #8
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());
     }
 }
Example #9
0
 protected function simpleAsArray(dom\element $el)
 {
     $aResult = array();
     $sName = $this->buildName($el->getName(), $el->getNamespace());
     if (!$this->getRoot()->getCurrentElement(false)) {
         $this->buildNamespaces();
     }
     $aResult[] = '<' . $sName;
     $aResult[] = $this->parseAttributes();
     $aResult[] = '/>';
     return $aResult;
 }