當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Twig_Parser類代碼示例

本文整理匯總了PHP中Twig_Parser的典型用法代碼示例。如果您正苦於以下問題:PHP Twig_Parser類的具體用法?PHP Twig_Parser怎麽用?PHP Twig_Parser使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Twig_Parser類的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: 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

示例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: 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

示例6: 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

示例7: 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

示例8: parseTestExpression

 public function parseTestExpression(Twig_Parser $parser, $node)
 {
     $stream = $parser->getStream();
     $name = $stream->expect(Twig_Token::NAME_TYPE);
     $arguments = null;
     if ($stream->test(Twig_Token::PUNCTUATION_TYPE, '(')) {
         $arguments = $parser->getExpressionParser()->parseArguments();
     }
     return new Twig_Node_Expression_Test($node, $name->getValue(), $arguments, $parser->getCurrentToken()->getLine());
 }
開發者ID:kuslahne,項目名稱:rapid-slim-php-blog-application,代碼行數:10,代碼來源:Core.php

示例9: parseTestExpression

 public function parseTestExpression(Twig_Parser $parser, $node)
 {
     $stream = $parser->getStream();
     $name = $stream->expect(Twig_Token::NAME_TYPE)->getValue();
     $arguments = null;
     if ($stream->test(Twig_Token::PUNCTUATION_TYPE, '(')) {
         $arguments = $parser->getExpressionParser()->parseArguments();
     }
     $class = $this->getTestNodeClass($parser->getEnvironment(), $name);
     return new $class($node, $name, $arguments, $parser->getCurrentToken()->getLine());
 }
開發者ID:carlesgutierrez,項目名稱:libreobjet.org,代碼行數:11,代碼來源:Core.php

示例10: getParserForFilterBodyNodes

 protected function getParserForFilterBodyNodes()
 {
     $invoker = new ReflectionMethod('Twig_Parser', 'filterBodyNodes');
     $invoker->setAccessible(true);
     $p = new ReflectionProperty('Twig_Parser', 'stream');
     $p->setAccessible(true);
     $parser = new Twig_Parser(new Twig_Environment());
     $parser->setParent(new Twig_Node());
     $p->setValue($parser, $this->getMockBuilder('Twig_TokenStream')->disableOriginalConstructor()->getMock());
     return array($parser, $invoker);
 }
開發者ID:robertowest,項目名稱:CuteFlow-V4,代碼行數:11,代碼來源:ParserTest.php

示例11: __construct

 public function __construct(Twig_Parser $parser, Twig_Environment $env = null)
 {
     $this->parser = $parser;
     if ($env instanceof Twig_Environment) {
         $this->env = $env;
         $this->unaryOperators = $env->getUnaryOperators();
         $this->binaryOperators = $env->getBinaryOperators();
     } else {
         @trigger_error('Passing the operators as constructor arguments to ' . __METHOD__ . ' is deprecated since version 1.27. Pass the environment instead.', E_USER_DEPRECATED);
         $this->env = $parser->getEnvironment();
         $this->unaryOperators = func_get_arg(1);
         $this->binaryOperators = func_get_arg(2);
     }
 }
開發者ID:bigbitecreative,項目名稱:wordpress-git-content,代碼行數:14,代碼來源:ExpressionParser.php

示例12: getTestNodeClass

 protected function getTestNodeClass(Twig_Parser $parser, $name, $line)
 {
     $env = $parser->getEnvironment();
     $testMap = $env->getTests();
     $testName = null;
     if (isset($testMap[$name])) {
         $testName = $name;
     } elseif ($parser->getStream()->test(Twig_Token::NAME_TYPE)) {
         // try 2-words tests
         $name = $name . ' ' . $parser->getCurrentToken()->getValue();
         if (isset($testMap[$name])) {
             $parser->getStream()->next();
             $testName = $name;
         }
     }
     if (null === $testName) {
         $message = sprintf('The test "%s" does not exist', $name);
         if ($alternatives = $env->computeAlternatives($name, array_keys($env->getTests()))) {
             $message = sprintf('%s. Did you mean "%s"', $message, implode('", "', $alternatives));
         }
         throw new Twig_Error_Syntax($message, $line, $parser->getFilename());
     }
     if ($testMap[$name] instanceof Twig_SimpleTest) {
         return $testMap[$name]->getNodeClass();
     }
     return $testMap[$name] instanceof Twig_Test_Node ? $testMap[$name]->getClass() : 'Twig_Node_Expression_Test';
 }
開發者ID:TiGR,項目名稱:Twig,代碼行數:27,代碼來源:Core.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: moveToNextNode

 public function moveToNextNode(\Twig_Parser $parser)
 {
     $parser->getStream()->next();
     $parser->getStream()->expect(\Twig_Token::BLOCK_START_TYPE);
 }
開發者ID:ner0tic,項目名稱:YepsuaSmarTwigBundle,代碼行數:5,代碼來源:CommonTokenParser.php

示例15: 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


注:本文中的Twig_Parser類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。