當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。