コード例 #1
0
ファイル: TokenStreamTest.php プロジェクト: naldz/cyberden
 /**
  * @group legacy
  */
 public function testLegacyConstructorSignature()
 {
     $stream = new Twig_TokenStream(array(), 'foo', '{{ foo }}');
     $this->assertEquals('foo', $stream->getFilename());
     $this->assertEquals('{{ foo }}', $stream->getSource());
     $this->assertEquals('foo', $stream->getSourceContext()->getName());
     $this->assertEquals('{{ foo }}', $stream->getSourceContext()->getCode());
 }
コード例 #2
0
ファイル: Parser.php プロジェクト: vgrish/twiggy
 /**
  * {@inheritdoc}
  */
 public function parse(Twig_TokenStream $stream, $test = null, $dropNeedle = false)
 {
     // push all variables into the stack to keep the current state of the parser
     // using get_object_vars() instead of foreach would lead to https://bugs.php.net/71336
     $vars = array();
     foreach ($this as $k => $v) {
         $vars[$k] = $v;
     }
     unset($vars['stack'], $vars['env'], $vars['handlers'], $vars['visitors'], $vars['expressionParser'], $vars['reservedMacroNames']);
     $this->stack[] = $vars;
     // tag handlers
     if (null === $this->handlers) {
         $this->handlers = array();
         foreach ($this->env->getTokenParsers() as $handler) {
             $handler->setParser($this);
             $this->handlers[$handler->getTag()] = $handler;
         }
     }
     // node visitors
     if (null === $this->visitors) {
         $this->visitors = $this->env->getNodeVisitors();
     }
     if (null === $this->expressionParser) {
         $this->expressionParser = new Twig_ExpressionParser($this, $this->env->getUnaryOperators(), $this->env->getBinaryOperators());
     }
     $this->stream = $stream;
     $this->parent = null;
     $this->blocks = array();
     $this->macros = array();
     $this->traits = array();
     $this->blockStack = array();
     $this->importedSymbols = array(array());
     $this->embeddedTemplates = array();
     try {
         $body = $this->subparse($test, $dropNeedle);
         if (null !== $this->parent && null === ($body = $this->filterBodyNodes($body))) {
             $body = new Twig_Node();
         }
     } catch (Twig_Error_Syntax $e) {
         if (!$e->getTemplateFile()) {
             $e->setTemplateFile($this->getFilename());
         }
         if (!$e->getTemplateLine()) {
             $e->setTemplateLine($this->stream->getCurrent()->getLine());
         }
         throw $e;
     }
     $node = new Twig_Node_Module(new Twig_Node_Body(array($body)), $this->parent, new Twig_Node($this->blocks), new Twig_Node($this->macros), new Twig_Node($this->traits), $this->embeddedTemplates, $this->getFilename(), $stream->getSource());
     $traverser = new Twig_NodeTraverser($this->env, $this->visitors);
     $node = $traverser->traverse($node);
     // restore previous stack so previous parse() call can resume working
     foreach (array_pop($this->stack) as $key => $val) {
         $this->{$key} = $val;
     }
     return $node;
 }