public function testIllegalElementNames2() { $parser = new PHPTAL_Dom_SaxXmlParser('UTF-8'); try { $parser->parseString(new PHPTAL_Dom_PHPTALDocumentBuilder(), '<t><element~ /></t>'); $this->fail("Accepted invalid element name")->getResult(); } catch (PHPTAL_Exception $e) { } }
public function testNotClosing() { $parser = new PHPTAL_Dom_SaxXmlParser('UTF-8'); try { $parser->parseString(new PHPTAL_Dom_PHPTALDocumentBuilder(), "<element_a><element_b><element_x/><element_c><element_d><element_e>"); $this->fail("Accepted invalid XML"); } catch (PHPTAL_ParserException $e) { $this->assertNotContains("documentElement", $e->getMessage()); $this->assertRegExp("/element_e.*element_d.*element_c.*element_b.*element_a/", $e->getMessage()); } }
/** * Parse currently set template, prefilter and generate PHP code. * * @return string (compiled PHP code) */ protected function parse() { $data = $this->_source->getData(); $prefilters = $this->getPreFilterInstances(); foreach ($prefilters as $prefilter) { $data = $prefilter->filter($data); } $realpath = $this->_source->getRealPath(); $parser = new PHPTAL_Dom_SaxXmlParser($this->_encoding); $builder = new PHPTAL_Dom_PHPTALDocumentBuilder(); $tree = $parser->parseString($builder, $data, $realpath)->getResult(); foreach ($prefilters as $prefilter) { if ($prefilter instanceof PHPTAL_PreFilter) { if ($prefilter->filterDOM($tree) !== NULL) { throw new PHPTAL_ConfigurationException("Don't return value from filterDOM()"); } } } $state = new PHPTAL_Php_State($this); $codewriter = new PHPTAL_Php_CodeWriter($state); $codewriter->doTemplateFile($this->getFunctionName(), $tree); return $codewriter->getResult(); }
/** * parse currently set template * @return string (compiled PHP code) */ protected function parse() { self::setIncludePath(); require_once 'PHPTAL/Dom/DocumentBuilder.php'; require_once 'PHPTAL/Php/CodeGenerator.php'; self::restoreIncludePath(); // instantiate the PHPTAL source parser $parser = new PHPTAL_Dom_SaxXmlParser($this->_encoding); $builder = new PHPTAL_Dom_DocumentBuilder(); $builder->stripComments($this->_stripComments); $data = $this->_source->getData(); $realpath = $this->_source->getRealPath(); if ($this->_prefilter) { $data = $this->_prefilter->filter($data); } $tree = $parser->parseString($builder, $data, $realpath)->getResult(); $generator = new PHPTAL_Php_CodeGenerator($this->getFunctionName(), $this->_source->getRealPath(), $this->_encoding, $this->_outputMode, $this->getCodePath()); $result = $generator->generateCode($tree); return $result; }
/** * Parse currently set template, prefilter and generate PHP code. * * @return string (compiled PHP code) */ protected function parse() { self::setIncludePath(); require_once 'PHPTAL/Dom/DocumentBuilder.php'; require_once 'PHPTAL/Php/State.php'; require_once 'PHPTAL/Php/CodeWriter.php'; self::restoreIncludePath(); // instantiate the PHPTAL source parser $data = $this->_source->getData(); $prefilters = $this->getPreFilterInstances(); foreach ($prefilters as $prefilter) { $data = $prefilter->filter($data); } $parser = new PHPTAL_Dom_SaxXmlParser($this->_encoding); $builder = new PHPTAL_Dom_DocumentBuilder(); $realpath = $this->_source->getRealPath(); $tree = $parser->parseString($builder, $data, $realpath)->getResult(); foreach ($prefilters as $prefilter) { if ($prefilter instanceof PHPTAL_PreFilter) { if ($prefilter->filterDOM($tree)) { throw new PHPTAL_ConfigurationException("Don't return value from filterDOM()"); } } } $state = new PHPTAL_Php_State($this); $codewriter = new PHPTAL_Php_CodeWriter($state); $codewriter->doTemplateFile($this->getFunctionName(), $tree); return $codewriter->getResult(); }