Beispiel #1
0
 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);
 }
Beispiel #2
0
 public function parseRoot(dom\element $el)
 {
     if ($el->countChildren()) {
         $this->launchException('No content allowed');
     }
     $this->setNode($el);
 }
Beispiel #3
0
 protected function test(dom\element $test, $sExpected, $controler, dom\document $doc, fs\file $file)
 {
     if ($nodeResult = $test->getx('self:node', array(), false)) {
         $this->setArgument('node', $nodeResult->getFirst());
     }
     return parent::test($test, $sExpected, $controler, $doc, $file);
 }
Beispiel #4
0
 protected function loadParticles(dom\element $el)
 {
     foreach ($el->getChildren() as $child) {
         $particle = $this->parseComponent($child);
         $this->addParticle($particle);
     }
 }
Beispiel #5
0
 protected function parseElement(dom\element $el)
 {
     $sOwner = $el->readAttribute('owner', $this->getNamespace());
     $sGroup = $el->readAttribute('group', $this->getNamespace());
     $sMode = $el->readAttribute('mode', $this->getNamespace());
     return array('user' => $sOwner, 'group' => $sGroup, 'mode' => intval($sMode));
 }
Beispiel #6
0
 protected function parseResult(dom\element $test, fs\file $file, array $aArguments = array())
 {
     if ($test->readx('@profile', array(), false)) {
         $this->loadProfiler();
         $this->startProfile();
     }
     return parent::parseResult($test, $file, $aArguments);
 }
Beispiel #7
0
 public function parseRoot(dom\element $el)
 {
     $file = $this->getSourceFile($el->read());
     $this->setFile($file);
     $importer = $this->getParser()->getImporter();
     $call = $importer->call('import', array((string) $this->getFile()), '\\sylma\\core\\argument');
     $this->setCall($call);
 }
Beispiel #8
0
 protected function addParsedChild(dom\element $el, array &$aResult, $mContent)
 {
     $mContent = current($this->getWindow()->parseArrayables(array($mContent)));
     if ($sKey = $el->readx('@action:name', array(), false)) {
         $aResult[$sKey] = $mContent;
     } else {
         $aResult[] = $mContent;
     }
 }
Beispiel #9
0
 protected function addParsedChild(dom\element $el, array &$aResult, $mContent)
 {
     $mContent = $this->getWindow()->toString($mContent);
     if ($sKey = $el->readx('@action:name', array(), false)) {
         $aResult[$sKey] = $mContent;
     } else {
         $aResult[] = $mContent;
     }
 }
Beispiel #10
0
 protected function parseElementSelf(dom\element $el)
 {
     if ($el->getName() === 'resource') {
         $result = $this->reflectResource($el);
     } else {
         $result = parent::parseElementSelf($el);
     }
     return $result;
 }
Beispiel #11
0
 /**
  * @used by self::parseMatchValue() anonymous closure
  */
 public function buildMatchValue(dom\element $el, $sPrefix, $sName)
 {
     $sNamespace = '';
     if ($sPrefix and !($sNamespace = $el->lookupNamespace($sPrefix))) {
         $this->launchException('Cannot match value, namespace not found', get_defined_vars());
     }
     if (!$sName) {
         $this->launchException('Cannot match value, no name defined', get_defined_vars());
     }
     return array('name' => $sName, 'namespace' => $sNamespace);
 }
Beispiel #12
0
 protected function parseElementSelf(dom\element $el)
 {
     switch ($el->getName()) {
         case 'template':
             $result = $this->loadTemplate($el);
             break;
         default:
             $result = parent::parseElementSelf($el);
     }
     return $result;
 }
Beispiel #13
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;
 }
Beispiel #14
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;
 }
Beispiel #15
0
 protected function addNamespace($sValue, dom\element $el, dom\element $context)
 {
     list($sNamespace) = $this->parseName($sValue, null, $context);
     if (!$el->readAttribute('ns', $sNamespace, false)) {
         if ($sPrefix = $context->lookupPrefix($sNamespace)) {
             $el->createAttribute("{$sPrefix}:ns", 'ns', $sNamespace);
         }
     }
 }
Beispiel #16
0
 protected function test(dom\element $test, $sExpected, $controler, dom\document $doc, fs\file $file)
 {
     $bResult = false;
     $bReady = true;
     $this->resetCount();
     $sExpected = $test->readx('self:expected', array(), false);
     try {
         $this->prepareTest($test, $controler);
         if ($bReady) {
             if ($sExpected) {
                 if (is_null(eval('$closure = function($controler) { $manager = $controler; ' . $sExpected . '; };'))) {
                     $bResult = $this->evaluate($closure, $controler);
                 }
             } else {
                 $bResult = $this->testNode();
             }
         }
     } catch (core\exception $e) {
         $bResult = $this->catchException($test, $e, $file);
     }
     return $bResult;
 }
Beispiel #17
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());
     }
 }
Beispiel #18
0
 protected function loadResultNode(dom\element $test)
 {
     $this->setArgument('node', null);
     foreach ($test->queryx('self:node', array(), false) as $node) {
         if ($sName = $node->readx('@name', array(), false)) {
             $sName = "node/{$sName}";
         } else {
             $sName = 'node';
         }
         if ($node->countChildren() > 1) {
             $this->set($sName, $node->getChildren());
         } else {
             $this->set($sName, $node->getFirst());
         }
     }
 }
Beispiel #19
0
 public function parseAttributes(dom\element $el, $resultElement, $current)
 {
     $aResult = null;
     $bRoot = false;
     //$el = $this->setNode($el);
     $aResult[] = $this->init();
     $el->getHandler()->registerNamespaces($this->getNS());
     if ($this->elementIsTemplate($el)) {
         $aResult[] = $this->reflectTemplate($el, $resultElement);
     } else {
         if ($this->elementIsObject($el)) {
             if (!$this->bRoot) {
                 $this->bRoot = true;
                 $aResult[] = $this->getPHPWindow()->createInstruction($this->getContainer());
             }
             $aResult[] = $this->reflectObject($el, $resultElement);
         } else {
             if ($this->elementIsNode($el)) {
                 $aResult[] = $this->reflectNode($el, $resultElement);
             }
         }
     }
     return $aResult;
 }
Beispiel #20
0
 protected function reflectOccurs(dom\element $el)
 {
     if (!($sOccurs = $el->readx('@occurs', array(), false))) {
         $sOccurs = '1..1';
     }
     list($iMin, $iMax) = explode('..', $sOccurs);
     $this->setOccurs($iMin, $iMax);
 }
Beispiel #21
0
 protected function parseComponentRoot(dom\element $el, $bParse = false, $bDebug = true)
 {
     $children = $el->getChildren();
     if (!$children->length) {
         if ($bDebug) {
             $this->launchException('Empty component not allowed', get_defined_vars());
         }
         $mResult = null;
     } else {
         if ($children->length > 1) {
             $mResult = $this->parseChildren($children);
         } else {
             $mResult = $this->parseNode($el->getFirst());
         }
     }
     return $bParse ? $this->getWindow()->parse($mResult) : $mResult;
 }
Beispiel #22
0
 protected function readElement(dom\element $el)
 {
     if ($el->isComplex()) {
         $this->launchException('Cannot read complex element');
     }
     return $el->read();
 }
Beispiel #23
0
 protected function parseClassName(dom\element $el)
 {
     $sResult = '';
     if ($sName = $el->readx('@name', array(), false)) {
         if ($sName[0] == '\\') {
             $sResult = $sName;
         } else {
             $sResult = $this->getClassBase() . '\\' . $sName;
         }
     }
     return $sResult;
 }
Beispiel #24
0
 protected function useForeignAttributes(dom\element $el)
 {
     $bResult = false;
     foreach ($el->getAttributes() as $attr) {
         $sNamespace = $attr->getNamespace();
         if ($sNamespace && $sNamespace != $this->getNamespace(static::PREFIX) && $sNamespace !== self::BUILDER_NS) {
             $bResult = true;
             break;
         }
     }
     return $bResult;
 }
Beispiel #25
0
 protected function catchExceptionCheck($sException, dom\element $test, core\exception $e, fs\file $file)
 {
     $bResult = false;
     if ($sException && $e instanceof $sException) {
         $bResult = true;
     } else {
         $e->addPath($file->asToken());
         $e->addPath('Test ID : ' . $test->readAttribute('name'));
         if ($sException) {
             $e->addPath(sprintf('Exception of type %s expected', $sException));
         }
         //$e->addPath($test->asString());
         $e->save(false);
     }
     return $bResult;
 }
Beispiel #26
0
 protected function loadRule(dom\element $el, array &$aResult)
 {
     $aResult[$el->getName()] = $el->readx('@value', array(), false);
 }
Beispiel #27
0
 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);
 }
Beispiel #28
0
 public function parseRoot(dom\element $el)
 {
     $sFile = $el->read();
     $this->setNode($el);
     return $this->getSourceFile($sFile);
 }
Beispiel #29
0
 protected function testArgument(dom\element $test, dom\document $doc, fs\file $file)
 {
     $expected = $test->getx('self:expected');
     return parent::test($test, $expected->read(), $this, $doc, $file);
 }
Beispiel #30
0
 protected function parsePath(dom\element $el)
 {
     $result = null;
     if (!($sName = $el->readx('@name', array(), false))) {
         $sName = 'default';
     }
     if ($el->readx('@disabled', array(), false)) {
         $this->aDisabled[$sName] = true;
     } else {
         if (!array_key_exists($sName, $this->aDisabled)) {
             $result = $this->parseComponent($el);
             $this->addPath($result);
         }
     }
     return $result;
 }