当前位置: 首页>>代码示例>>PHP>>正文


PHP Twig_Parser::parse方法代码示例

本文整理汇总了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'));
 }
开发者ID:fdelgados,项目名称:building-testable-applications,代码行数:10,代码来源:ExpressionParserTest.php

示例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'));
    }
开发者ID:nizsheanez,项目名称:PolymorphCMS,代码行数:11,代码来源:ExpressionParserTest.php

示例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());
 }
开发者ID:Aryellix,项目名称:scrumator,代码行数:8,代码来源:ParserTest.php

示例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));
 }
开发者ID:RuntyCybin,项目名称:csymfony,代码行数:11,代码来源:LegacyRenderTokenParserTest.php

示例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));
 }
开发者ID:blazarecki,项目名称:symfony,代码行数:11,代码来源:FormThemeTokenParserTest.php

示例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());
 }
开发者ID:DeDoOozZz,项目名称:brighterycms,代码行数:8,代码来源:ParserTest.php

示例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;
 }
开发者ID:hum2,项目名称:twig-form,代码行数:14,代码来源:FormTokenParserSpec.php

示例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));
 }
开发者ID:manudatta12,项目名称:POC,代码行数:12,代码来源:TemplateBoxTokenParserTest.php

示例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);
 }
开发者ID:ivoaz,项目名称:content-editable-bundle,代码行数:16,代码来源:ContentEditableTokenParserTest.php

示例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'));
 }
开发者ID:stler,项目名称:NMFrame,代码行数:10,代码来源:ExpressionParserTest.php

示例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')));
 }
开发者ID:naldz,项目名称:cyberden,代码行数:10,代码来源:ExpressionParserTest.php

示例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'));
 }
开发者ID:necromuncher,项目名称:Twig,代码行数:10,代码来源:ExpressionParserTest.php

示例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();
}
开发者ID:betsyzhang,项目名称:chyrp,代码行数:15,代码来源:parser.php

示例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);
 }
开发者ID:gembux2012,项目名称:lesson2_1,代码行数:10,代码来源:ParserTest.php

示例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'));
 }
开发者ID:varvanin,项目名称:currycms,代码行数:12,代码来源:Parser.php


注:本文中的Twig_Parser::parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。