当前位置: 首页>>代码示例>>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;未经允许,请勿转载。