本文整理汇总了PHP中Twig_Parser::parse方法的典型用法代码示例。如果您正苦于以下问题:PHP Twig_Parser::parse方法的具体用法?PHP Twig_Parser::parse怎么用?PHP Twig_Parser::parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Twig_Parser
的用法示例。
在下文中一共展示了Twig_Parser::parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testStringExpression
/**
* @dataProvider getTestsForString
*/
public function testStringExpression($template, $expected)
{
$env = new Twig_Environment(new Twig_Loader_String(), array('cache' => false, 'autoescape' => false, 'optimizations' => 0));
$stream = $env->tokenize($template, 'index');
$parser = new Twig_Parser($env);
$this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode(0)->getNode('expr'));
}
示例2: testArraySyntaxError
/**
* @expectedException Twig_Error_Syntax
* @dataProvider getFailingTestsForArray
*/
public function testArraySyntaxError($template)
{
$env = new Twig_Environment(new Twig_Loader_String(), array('cache' => false, 'autoescape' => false));
$parser = new Twig_Parser($env);
$parser->parse($env->tokenize($template, 'index'));
}
示例3: testParseIsReentrant
public function testParseIsReentrant()
{
$twig = new Twig_Environment($this->getMock('Twig_LoaderInterface'), array('autoescape' => false, 'optimizations' => 0));
$twig->addTokenParser(new TestTokenParser());
$parser = new Twig_Parser($twig);
$parser->parse(new Twig_TokenStream(array(new Twig_Token(Twig_Token::BLOCK_START_TYPE, '', 1), new Twig_Token(Twig_Token::NAME_TYPE, 'test', 1), new Twig_Token(Twig_Token::BLOCK_END_TYPE, '', 1), new Twig_Token(Twig_Token::VAR_START_TYPE, '', 1), new Twig_Token(Twig_Token::NAME_TYPE, 'foo', 1), new Twig_Token(Twig_Token::VAR_END_TYPE, '', 1), new Twig_Token(Twig_Token::EOF_TYPE, '', 1))));
$this->assertNull($parser->getParent());
}
示例4: testCompile
/**
* @dataProvider getTestsForRender
*/
public function testCompile($source, $expected)
{
$env = new \Twig_Environment(new \Twig_Loader_String(), array('cache' => false, 'autoescape' => false, 'optimizations' => 0));
$env->addTokenParser(new RenderTokenParser());
$stream = $env->tokenize($source);
$parser = new \Twig_Parser($env);
$this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode(0));
}
示例5: testCompile
/**
* @dataProvider getTestsForFormTheme
*/
public function testCompile($source, $expected)
{
$env = new \Twig_Environment($this->getMock('Twig_LoaderInterface'), array('cache' => false, 'autoescape' => false, 'optimizations' => 0));
$env->addTokenParser(new FormThemeTokenParser());
$stream = $env->tokenize(new \Twig_Source($source, ''));
$parser = new \Twig_Parser($env);
$this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode(0));
}
示例6: testParseIsReentrant
public function testParseIsReentrant()
{
$twig = new Twig_Environment(null, ['autoescape' => false, 'optimizations' => 0]);
$twig->addTokenParser(new TestTokenParser());
$parser = new Twig_Parser($twig);
$parser->parse(new Twig_TokenStream([new Twig_Token(Twig_Token::BLOCK_START_TYPE, '', 1), new Twig_Token(Twig_Token::NAME_TYPE, 'test', 1), new Twig_Token(Twig_Token::BLOCK_END_TYPE, '', 1), new Twig_Token(Twig_Token::VAR_START_TYPE, '', 1), new Twig_Token(Twig_Token::NAME_TYPE, 'foo', 1), new Twig_Token(Twig_Token::VAR_END_TYPE, '', 1), new Twig_Token(Twig_Token::EOF_TYPE, '', 1)]));
$this->assertNull($parser->getParent());
}
示例7: getParser
/**
* @return \Twig_Parser
* @throws \Exception
* @throws \Twig_Error_Syntax
*/
private function getParser()
{
$stream = new \Twig_TokenStream(array(new \Twig_Token(\Twig_Token::TEXT_TYPE, '<!DOCTYPE html><html><body>', 1), new \Twig_Token(\Twig_Token::BLOCK_START_TYPE, '', 2), new \Twig_Token(\Twig_Token::NAME_TYPE, 'form', 2), new \Twig_Token(\Twig_Token::PUNCTUATION_TYPE, '(', 2), new \Twig_Token(\Twig_Token::NAME_TYPE, 'method', 2), new \Twig_Token(\Twig_Token::OPERATOR_TYPE, '=', 2), new \Twig_Token(\Twig_Token::STRING_TYPE, 'post', 2), new \Twig_Token(\Twig_Token::PUNCTUATION_TYPE, ',', 2), new \Twig_Token(\Twig_Token::NAME_TYPE, 'action', 2), new \Twig_Token(\Twig_Token::OPERATOR_TYPE, '=', 2), new \Twig_Token(\Twig_Token::NAME_TYPE, 'request_uri', 2), new \Twig_Token(\Twig_Token::PUNCTUATION_TYPE, '|', 2), new \Twig_Token(\Twig_Token::NAME_TYPE, 'e', 2), new \Twig_Token(\Twig_Token::PUNCTUATION_TYPE, ')', 2), new \Twig_Token(\Twig_Token::BLOCK_END_TYPE, '', 2), new \Twig_Token(\Twig_Token::TEXT_TYPE, '<input type="submit" value="Submit">', 3), new \Twig_Token(\Twig_Token::BLOCK_START_TYPE, '', 4), new \Twig_Token(\Twig_Token::NAME_TYPE, 'endform', 4), new \Twig_Token(\Twig_Token::BLOCK_END_TYPE, '', 4), new \Twig_Token(\Twig_Token::TEXT_TYPE, '</body></html>', 5), new \Twig_Token(\Twig_Token::EOF_TYPE, '', 5)));
$env = new \Twig_Environment();
$env->addTokenParser(new FormTokenParser());
$parser = new \Twig_Parser($env);
$parser->parse($stream);
return $parser;
}
示例8: testCompile
/**
* @dataProvider getTestsForRender
*/
public function testCompile($enabled, $source, $expected)
{
$translator = $this->getMock('Symfony\\Component\\Translation\\TranslatorInterface');
$env = new \Twig_Environment(new \Twig_Loader_String(), array('cache' => false, 'autoescape' => false, 'optimizations' => 0));
$env->addTokenParser(new TemplateBoxTokenParser($enabled, $translator));
$stream = $env->tokenize($source);
$parser = new \Twig_Parser($env);
$this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode(0));
}
示例9: testCompile
/**
* @dataProvider getCompileTestData
*
* @param ContentEditableNode $expectedNode
* @param string $source
* @param string $message
*/
public function testCompile(ContentEditableNode $expectedNode, $source, $message = '')
{
$env = new \Twig_Environment($this->getMock('Twig_LoaderInterface'), ['cache' => false, 'autoescape' => false, 'optimizations' => 0]);
$env->addTokenParser(new ContentEditableTokenParser());
$parser = new \Twig_Parser($env);
$stream = $env->tokenize($source);
$node = $parser->parse($stream)->getNode('body')->getNode(0);
$this->assertEquals($expectedNode, $node, $message);
}
示例10: testUnknownTest
/**
* @expectedException Twig_Error_Syntax
* @expectedExceptionMessage The test "nul" does not exist. Did you mean "null" in "index" at line 1
*/
public function testUnknownTest()
{
$env = new Twig_Environment($this->getMock('Twig_LoaderInterface'), array('cache' => false, 'autoescape' => false));
$parser = new Twig_Parser($env);
$parser->parse($env->tokenize('{{ 1 is nul }}', 'index'));
}
示例11: testUnknownTestWithoutSuggestions
/**
* @expectedException Twig_Error_Syntax
* @expectedExceptionMessage Unknown "foobar" test in "index" at line 1.
*/
public function testUnknownTestWithoutSuggestions()
{
$env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false));
$parser = new Twig_Parser($env);
$parser->parse($env->tokenize(new Twig_Source('{{ 1 is foobar }}', 'index')));
}
示例12: testUnknownTest
/**
* @expectedException Twig_Error_Syntax
* @expectedExceptionMessage The test "nul" does not exist. Did you mean "null" in "index" at line 1
*/
public function testUnknownTest()
{
$env = new Twig_Environment(new Twig_Loader_String(), array('cache' => false, 'autoescape' => false));
$parser = new Twig_Parser($env);
$parser->parse($env->tokenize('{{ 1 is nul }}', 'index'));
}
示例13: twig_parse
/**
* Twig::Parser
* ~~~~~~~~~~~~
*
* This module implements the Twig parser.
*
* :copyright: 2008 by Armin Ronacher.
* :license: BSD.
*/
function twig_parse($source, $filename = NULL)
{
$stream = twig_tokenize($source, $filename);
$parser = new Twig_Parser($stream);
return $parser->parse();
}
示例14: testUnkownTag
/**
* @expectedException Twig_Error_Syntax
* @expectedExceptionMessage Unknown tag name "foo". Did you mean "for" at line 0
*/
public function testUnkownTag()
{
$stream = new Twig_TokenStream(array(new Twig_Token(Twig_Token::BLOCK_START_TYPE, '', 0), new Twig_Token(Twig_Token::NAME_TYPE, 'foo', 0), new Twig_Token(Twig_Token::BLOCK_END_TYPE, '', 0), new Twig_Token(Twig_Token::EOF_TYPE, '', 0)));
$parser = new Twig_Parser(new Twig_Environment());
$parser->parse($stream);
}
示例15: parse
/**
* Replace Twig_Node_Module with Curry_Twig_Node_Module
*
* @param Twig_TokenStream $stream
* @return Curry_Twig_Node_Module
*/
public function parse(Twig_TokenStream $stream)
{
$node = parent::parse($stream);
// Convert Twig_Node_Module to Curry_Twig_Node_Module
return new Curry_Twig_Node_Module($node->getNode('body'), $node->getNode('parent'), $node->getNode('blocks'), $node->getNode('macros'), $node->getNode('traits'), $node->getAttribute('embedded_templates'), $node->getAttribute('filename'));
}