function preParse() { if (!$this->hasAttribute('target') && !$this->hasAttribute('to')) { $this->raiseCompilerError('Required attribute not found', array('attribute' => 'target or to')); } if ($this->hasAttribute('target') && $this->hasAttribute('to')) { $this->raiseCompilerError('Both target and to attribute are not supported'); } $this->_fillToAttributeFromTargetAttribute(); return parent::preParse(); }
/** * @param WactCompiler **/ function preParse($compiler) { parent::preParse($compiler); $locator = $compiler->getTemplateLocator(); if (!($file = $this->getAttribute('file'))) { $this->raiseRequiredAttributeError($file); } $source_file = $locator->locateSourceTemplate($file); if (empty($source_file)) { $this->raiseCompilerError('Template source file not found', array('file_name' => $file)); } if ($this->getBoolAttribute('literal')) { $this->addChild(new WactTextNode(null, $locator->readTemplateFile($source_file))); } elseif ($this->getBoolAttribute('source')) { $this->addChild(new WactTextNode(null, highlight_string($locator->readTemplateFile($source_file), true))); } else { if ($this->getBoolAttribute('in_datasource')) { $this->_createNewDatasourceTag($compiler); $compiler->parseTemplate($file, $this->new_datasource_tag); } else { $compiler->parseTemplate($file, $this); } } }
function testRestrictSelfNesting() { $tag_info = new WactTagInfo('CompilerTag', 'whatever'); $tag_info->setRestrictSelfNesting(true); $component = new WactCompilerTag(new WactSourceLocation('my_file', 13), 'whatever', $tag_info); $parent = new WactCompilerTag(new WactSourceLocation('my_file', 10), 'whatEver', $tag_info); $component->parent = $parent; try { $component->preParse(); $this->assertTrue(false); } catch (WactException $e) { $this->assertWantedPattern('/Tag cannot be nested within the same tag/', $e->getMessage()); $this->assertEqual($e->getParam('same_tag_file'), 'my_file'); $this->assertEqual($e->getParam('same_tag_line'), 10); } }