Backward incompatibilities:
* The short notation of the `block` tag changed.
+ * added two interfaces: Twig_NodeInterface and Twig_TokenParserInterface
* changed the generated code to match the new coding standards
* fixed sandbox mode (__toString() method check was not enforced if called implicitly from a simple statement like {{ article }})
* added a 'as' string to the block tag short notation ({% block title "Title" %} must now be {% block title as "Title" %})
/**
* Compiles a node.
*
- * @param Twig_Node $node The node to compile
+ * @param Twig_NodeInterface $node The node to compile
*
* @return Twig_Compiler The current compiler instance
*/
- public function compile(Twig_Node $node)
+ public function compile(Twig_NodeInterface $node)
{
$this->lastLine = null;
$this->source = '';
return $this;
}
- public function subcompile(Twig_Node $node)
+ public function subcompile(Twig_NodeInterface $node)
{
$node->compile($this);
/**
* Adds debugging information.
*
- * @param Twig_Node $node The related twig node
+ * @param Twig_NodeInterface $node The related twig node
*
* @return Twig_Compiler The current compiler instance
*/
- public function addDebugInfo(Twig_Node $node)
+ public function addDebugInfo(Twig_NodeInterface $node)
{
if ($node->getLine() != $this->lastLine) {
$this->lastLine = $node->getLine();
/**
* Compiles a node.
*
- * @param Twig_Node $node The node to compile
+ * @param Twig_NodeInterface $node The node to compile
*
* @return Twig_Compiler The current compiler instance
*/
- public function compile(Twig_Node $node);
+ public function compile(Twig_NodeInterface $node);
/**
* Gets the current PHP code after compilation.
$compiler->setEnvironment($this);
}
- public function compile(Twig_Node $node)
+ public function compile(Twig_NodeInterface $node)
{
return $this->getCompiler()->compile($node)->getSource();
}
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @version SVN: $Id$
*/
-abstract class Twig_Node
+abstract class Twig_Node implements Twig_NodeInterface
{
protected $lineno;
protected $tag;
return get_class($this).'()';
}
- abstract public function compile($compiler);
-
public function getLine()
{
return $this->lineno;
}
- public function getTag()
+ public function getNodeTag()
{
return $this->tag;
}
protected $left;
protected $right;
- public function __construct(Twig_Node $left, Twig_Node $right, $lineno)
+ public function __construct(Twig_NodeInterface $left, Twig_NodeInterface $right, $lineno)
{
parent::__construct($lineno);
$this->left = $left;
protected $node;
protected $filters;
- public function __construct(Twig_Node $node, array $filters, $lineno, $tag = null)
+ public function __construct(Twig_NodeInterface $node, array $filters, $lineno, $tag = null)
{
parent::__construct($lineno, $tag);
protected $attr;
protected $arguments;
- public function __construct(Twig_Node $node, $attr, $arguments, $lineno, $token_value)
+ public function __construct(Twig_NodeInterface $node, $attr, $arguments, $lineno, $token_value)
{
parent::__construct($lineno);
$this->node = $node;
{
protected $node;
- public function __construct(Twig_Node $node, $lineno)
+ public function __construct(Twig_NodeInterface $node, $lineno)
{
parent::__construct($lineno);
$this->node = $node;
--- /dev/null
+<?php
+
+/*
+ * This file is part of Twig.
+ *
+ * (c) 2010 Fabien Potencier
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * Represents a node in the AST.
+ *
+ * @package twig
+ * @author Fabien Potencier <fabien.potencier@symfony-project.com>
+ * @version SVN: $Id$
+ */
+interface Twig_NodeInterface
+{
+ public function compile($compiler);
+
+ public function getLine();
+
+ public function getNodeTag();
+}
$this->env = $env;
}
- public function traverse(Twig_Node $node, Twig_NodeVisitorInterface $visitor)
+ public function traverse(Twig_NodeInterface $node, Twig_NodeVisitorInterface $visitor)
{
$node = $visitor->enterNode($node, $this->env);
protected $statusStack = array();
protected $blocks = array();
- public function enterNode(Twig_Node $node, Twig_Environment $env)
+ public function enterNode(Twig_NodeInterface $node, Twig_Environment $env)
{
if ($node instanceof Twig_Node_AutoEscape) {
$this->statusStack[] = $node->getValue();
return $node;
}
- public function leaveNode(Twig_Node $node, Twig_Environment $env)
+ public function leaveNode(Twig_NodeInterface $node, Twig_Environment $env)
{
if ($node instanceof Twig_Node_AutoEscape || $node instanceof Twig_Node_Block) {
array_pop($this->statusStack);
return $node;
}
- protected function escapeNode(Twig_Node $node, Twig_Environment $env, $type)
+ protected function escapeNode(Twig_NodeInterface $node, Twig_Environment $env, $type)
{
if (false === $type) {
return $node;
{
protected $statusStack = array();
- public function enterNode(Twig_Node $node, Twig_Environment $env)
+ public function enterNode(Twig_NodeInterface $node, Twig_Environment $env)
{
if ($node instanceof Twig_Node_Filter) {
$this->statusStack[] = $node->getFilters();
return $node;
}
- public function leaveNode(Twig_Node $node, Twig_Environment $env)
+ public function leaveNode(Twig_NodeInterface $node, Twig_Environment $env)
{
if ($node instanceof Twig_Node_Filter) {
array_pop($this->statusStack);
return $node;
}
- protected function applyFilters(Twig_Node $node)
+ protected function applyFilters(Twig_NodeInterface $node)
{
if (false === $filters = $this->getCurrentFilters()) {
return $node;
protected $tags;
protected $filters;
- public function enterNode(Twig_Node $node, Twig_Environment $env)
+ public function enterNode(Twig_NodeInterface $node, Twig_Environment $env)
{
if ($node instanceof Twig_Node_Module) {
$this->inAModule = true;
return $node;
} elseif ($this->inAModule) {
// look for tags
- if ($node->getTag()) {
- $this->tags[$node->getTag()] = true;
+ if ($node->getNodeTag()) {
+ $this->tags[$node->getNodeTag()] = true;
}
// look for filters
// look for simple print statement ({{ article }})
if ($node instanceof Twig_Node_Print && $node->getExpression() instanceof Twig_Node_Expression_Name) {
- return new Twig_Node_SandboxPrint($node->getExpression(), $node->getLine(), $node->getTag());
+ return new Twig_Node_SandboxPrint($node->getExpression(), $node->getLine(), $node->getNodeTag());
}
}
return $node;
}
- public function leaveNode(Twig_Node $node, Twig_Environment $env)
+ public function leaveNode(Twig_NodeInterface $node, Twig_Environment $env)
{
if ($node instanceof Twig_Node_Module) {
$node->setUsedFilters(array_keys($this->filters));
interface Twig_NodeVisitorInterface
{
- public function enterNode(Twig_Node $node, Twig_Environment $env);
+ public function enterNode(Twig_NodeInterface $node, Twig_Environment $env);
- public function leaveNode(Twig_Node $node, Twig_Environment $env);
+ public function leaveNode(Twig_NodeInterface $node, Twig_Environment $env);
}
* This file is part of Twig.
*
* (c) 2009 Fabien Potencier
- * (c) 2009 Armin Ronacher
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
-abstract class Twig_TokenParser
+abstract class Twig_TokenParser implements Twig_TokenParserInterface
{
protected $parser;
{
$this->parser = $parser;
}
-
- abstract public function parse(Twig_Token $token);
-
- abstract public function getTag();
}
--- /dev/null
+<?php
+
+/*
+ * This file is part of Twig.
+ *
+ * (c) 2010 Fabien Potencier
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+interface Twig_TokenParserInterface
+{
+ public function setParser(Twig_Parser $parser);
+
+ public function parse(Twig_Token $token);
+
+ public function getTag();
+}