protected function parseComponent(dom\element $el) { if (!$this->allowComponent()) { $this->throwException(sprintf('Component building not allowed with %s', $el->asToken())); } return $this->loadComponent('component/' . $el->getName(), $el, $this); }
public function parseRoot(dom\element $el) { if ($el->getName() !== 'classes') { $this->throwException(sprintf('Bad root %s', $el->asToken())); } $aResult = $this->reflectClasses($el); $doc = $this->createArgument($aResult, $this->getParent()->getNamespace())->asDOM(); //$this->dsp($doc); $result = $this->getParent()->parseFromChild($doc->getRoot()); //$this->dsp($result); return $result; }
protected function parseElementUnknown(dom\element $el) { $this->throwException(sprintf('Uknown %s not allowed', $el->asToken())); }
protected function parseID(dom\element $el) { if ($el->isComplex()) { if ($el->countChildren() > 1) { $this->throwException(sprintf('Only one child expected in %s', $el->asToken())); } $mResult = $this->parseElement($el->getFirst()); } else { $mResult = $el->read(); } $this->setID($mResult); }
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); } }
protected function addSchemaType(dom\element $el, $sNamespace) { $sName = $el->readx('@name'); if (!isset($this->aTypesNodes[$sNamespace])) { $this->aTypesNodes[$sNamespace] = array(); } if (isset($this->aTypesNodes[$sNamespace][$sName])) { $this->throwException(sprintf('Type "%s" already exists', $sNamespace . ':' . $sName), $el->asToken()); } $this->aTypesNodes[$sNamespace][$sName] = $this->getDocument()->add($el); }
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()); } }