You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rg...@apache.org on 2012/05/27 21:59:52 UTC
svn commit: r1343084 [10/13] - in /logging/site/branches/cms/trunk: ./
content/ content/pages/ content/resources/ content/resources/css/
content/resources/img/ content/resources/js/ libs/ libs/Twig/
libs/Twig/lib/ libs/Twig/lib/Twig/ libs/Twig/lib/Twig...
Added: logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Function.php
URL: http://svn.apache.org/viewvc/logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Function.php?rev=1343084&view=auto
==============================================================================
--- logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Function.php (added)
+++ logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Function.php Sun May 27 19:59:46 2012
@@ -0,0 +1,66 @@
+<?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.
+ */
+class Twig_Node_Expression_Function extends Twig_Node_Expression
+{
+ public function __construct($name, Twig_NodeInterface $arguments, $lineno)
+ {
+ parent::__construct(array('arguments' => $arguments), array('name' => $name), $lineno);
+ }
+
+ public function compile(Twig_Compiler $compiler)
+ {
+ $name = $this->getAttribute('name');
+
+ if (false === $function = $compiler->getEnvironment()->getFunction($name)) {
+ $message = sprintf('The function "%s" does not exist', $name);
+ if ($alternatives = $compiler->getEnvironment()->computeAlternatives($name, array_keys($compiler->getEnvironment()->getFunctions()))) {
+ $message = sprintf('%s. Did you mean "%s"', $message, implode('", "', $alternatives));
+ }
+
+ throw new Twig_Error_Syntax($message, $this->getLine());
+ }
+
+ $compiler->raw($function->compile().'(');
+
+ $first = true;
+
+ if ($function->needsEnvironment()) {
+ $compiler->raw('$this->env');
+ $first = false;
+ }
+
+ if ($function->needsContext()) {
+ if (!$first) {
+ $compiler->raw(', ');
+ }
+ $compiler->raw('$context');
+ $first = false;
+ }
+
+ foreach ($function->getArguments() as $argument) {
+ if (!$first) {
+ $compiler->raw(', ');
+ }
+ $compiler->string($argument);
+ $first = false;
+ }
+
+ foreach ($this->getNode('arguments') as $node) {
+ if (!$first) {
+ $compiler->raw(', ');
+ }
+ $compiler->subcompile($node);
+ $first = false;
+ }
+
+ $compiler->raw(')');
+ }
+}
Added: logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/GetAttr.php
URL: http://svn.apache.org/viewvc/logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/GetAttr.php?rev=1343084&view=auto
==============================================================================
--- logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/GetAttr.php (added)
+++ logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/GetAttr.php Sun May 27 19:59:46 2012
@@ -0,0 +1,53 @@
+<?php
+
+/*
+ * 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.
+ */
+class Twig_Node_Expression_GetAttr extends Twig_Node_Expression
+{
+ public function __construct(Twig_Node_Expression $node, Twig_Node_Expression $attribute, Twig_Node_Expression_Array $arguments, $type, $lineno)
+ {
+ parent::__construct(array('node' => $node, 'attribute' => $attribute, 'arguments' => $arguments), array('type' => $type, 'is_defined_test' => false, 'ignore_strict_check' => false), $lineno);
+ }
+
+ public function compile(Twig_Compiler $compiler)
+ {
+ if (function_exists('twig_template_get_attributes')) {
+ $compiler->raw('twig_template_get_attributes($this, ');
+ } else {
+ $compiler->raw('$this->getAttribute(');
+ }
+
+ if ($this->getAttribute('ignore_strict_check')) {
+ $this->getNode('node')->setAttribute('ignore_strict_check', true);
+ }
+
+ $compiler->subcompile($this->getNode('node'));
+
+ $compiler->raw(', ')->subcompile($this->getNode('attribute'));
+
+ if (count($this->getNode('arguments')) || Twig_TemplateInterface::ANY_CALL !== $this->getAttribute('type') || $this->getAttribute('is_defined_test') || $this->getAttribute('ignore_strict_check')) {
+ $compiler->raw(', ')->subcompile($this->getNode('arguments'));
+
+ if (Twig_TemplateInterface::ANY_CALL !== $this->getAttribute('type') || $this->getAttribute('is_defined_test') || $this->getAttribute('ignore_strict_check')) {
+ $compiler->raw(', ')->repr($this->getAttribute('type'));
+ }
+
+ if ($this->getAttribute('is_defined_test') || $this->getAttribute('ignore_strict_check')) {
+ $compiler->raw(', '.($this->getAttribute('is_defined_test') ? 'true' : 'false'));
+ }
+
+ if ($this->getAttribute('ignore_strict_check')) {
+ $compiler->raw(', '.($this->getAttribute('ignore_strict_check') ? 'true' : 'false'));
+ }
+ }
+
+ $compiler->raw(')');
+ }
+}
Added: logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/MethodCall.php
URL: http://svn.apache.org/viewvc/logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/MethodCall.php?rev=1343084&view=auto
==============================================================================
--- logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/MethodCall.php (added)
+++ logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/MethodCall.php Sun May 27 19:59:46 2012
@@ -0,0 +1,37 @@
+<?php
+
+/*
+ * This file is part of Twig.
+ *
+ * (c) 2012 Fabien Potencier
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+class Twig_Node_Expression_MethodCall extends Twig_Node_Expression
+{
+ public function __construct(Twig_Node_Expression $node, $method, Twig_Node_Expression_Array $arguments, $lineno)
+ {
+ parent::__construct(array('node' => $node, 'arguments' => $arguments), array('method' => $method, 'safe' => false), $lineno);
+ }
+
+ public function compile(Twig_Compiler $compiler)
+ {
+ $compiler
+ ->subcompile($this->getNode('node'))
+ ->raw('->')
+ ->raw($this->getAttribute('method'))
+ ->raw('(')
+ ;
+ $first = true;
+ foreach ($this->getNode('arguments')->getKeyValuePairs() as $pair) {
+ if (!$first) {
+ $compiler->raw(', ');
+ }
+ $first = false;
+
+ $compiler->subcompile($pair['value']);
+ }
+ $compiler->raw(')');
+ }
+}
Added: logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Name.php
URL: http://svn.apache.org/viewvc/logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Name.php?rev=1343084&view=auto
==============================================================================
--- logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Name.php (added)
+++ logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Name.php Sun May 27 19:59:46 2012
@@ -0,0 +1,76 @@
+<?php
+
+/*
+ * 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.
+ */
+class Twig_Node_Expression_Name extends Twig_Node_Expression
+{
+ protected $specialVars = array(
+ '_self' => '$this',
+ '_context' => '$context',
+ '_charset' => '$this->env->getCharset()',
+ );
+
+ public function __construct($name, $lineno)
+ {
+ parent::__construct(array(), array('name' => $name, 'is_defined_test' => false, 'ignore_strict_check' => false), $lineno);
+ }
+
+ public function compile(Twig_Compiler $compiler)
+ {
+ $name = $this->getAttribute('name');
+
+ if ($this->getAttribute('is_defined_test')) {
+ if ($this->isSpecial()) {
+ $compiler->repr(true);
+ } else {
+ $compiler->raw('array_key_exists(')->repr($name)->raw(', $context)');
+ }
+ } elseif ($this->isSpecial()) {
+ $compiler->raw($this->specialVars[$name]);
+ } else {
+ // remove the non-PHP 5.4 version when PHP 5.3 support is dropped
+ // as the non-optimized version is just a workaround for slow ternary operator
+ // when the context has a lot of variables
+ if (version_compare(phpversion(), '5.4.0RC1', '>=') && ($this->getAttribute('ignore_strict_check') || !$compiler->getEnvironment()->isStrictVariables())) {
+ // PHP 5.4 ternary operator performance was optimized
+ $compiler
+ ->raw('(isset($context[')
+ ->string($name)
+ ->raw(']) ? $context[')
+ ->string($name)
+ ->raw('] : null)')
+ ;
+ } else {
+ $compiler
+ ->raw('$this->getContext($context, ')
+ ->string($name)
+ ;
+
+ if ($this->getAttribute('ignore_strict_check')) {
+ $compiler->raw(', true');
+ }
+
+ $compiler
+ ->raw(')')
+ ;
+ }
+ }
+ }
+
+ public function isSpecial()
+ {
+ return isset($this->specialVars[$this->getAttribute('name')]);
+ }
+
+ public function isSimple()
+ {
+ return !$this->isSpecial() && !$this->getAttribute('is_defined_test');
+ }
+}
Added: logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Parent.php
URL: http://svn.apache.org/viewvc/logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Parent.php?rev=1343084&view=auto
==============================================================================
--- logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Parent.php (added)
+++ logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Parent.php Sun May 27 19:59:46 2012
@@ -0,0 +1,48 @@
+<?php
+
+/*
+ * 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.
+ */
+
+/**
+ * Represents a parent node.
+ *
+ * @package twig
+ * @author Fabien Potencier <fa...@symfony.com>
+ */
+class Twig_Node_Expression_Parent extends Twig_Node_Expression
+{
+ public function __construct($name, $lineno, $tag = null)
+ {
+ parent::__construct(array(), array('output' => false, 'name' => $name), $lineno, $tag);
+ }
+
+ /**
+ * Compiles the node to PHP.
+ *
+ * @param Twig_Compiler A Twig_Compiler instance
+ */
+ public function compile(Twig_Compiler $compiler)
+ {
+ if ($this->getAttribute('output')) {
+ $compiler
+ ->addDebugInfo($this)
+ ->write("\$this->displayParentBlock(")
+ ->string($this->getAttribute('name'))
+ ->raw(", \$context, \$blocks);\n")
+ ;
+ } else {
+ $compiler
+ ->raw("\$this->renderParentBlock(")
+ ->string($this->getAttribute('name'))
+ ->raw(", \$context, \$blocks)")
+ ;
+ }
+ }
+}
Added: logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/TempName.php
URL: http://svn.apache.org/viewvc/logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/TempName.php?rev=1343084&view=auto
==============================================================================
--- logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/TempName.php (added)
+++ logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/TempName.php Sun May 27 19:59:46 2012
@@ -0,0 +1,26 @@
+<?php
+
+/*
+ * This file is part of Twig.
+ *
+ * (c) 2011 Fabien Potencier
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+class Twig_Node_Expression_TempName extends Twig_Node_Expression
+{
+ public function __construct($name, $lineno)
+ {
+ parent::__construct(array(), array('name' => $name), $lineno);
+ }
+
+ public function compile(Twig_Compiler $compiler)
+ {
+ $compiler
+ ->raw('$_')
+ ->raw($this->getAttribute('name'))
+ ->raw('_')
+ ;
+ }
+}
Added: logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Test.php
URL: http://svn.apache.org/viewvc/logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Test.php?rev=1343084&view=auto
==============================================================================
--- logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Test.php (added)
+++ logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Test.php Sun May 27 19:59:46 2012
@@ -0,0 +1,54 @@
+<?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.
+ */
+class Twig_Node_Expression_Test extends Twig_Node_Expression
+{
+ public function __construct(Twig_NodeInterface $node, $name, Twig_NodeInterface $arguments = null, $lineno)
+ {
+ parent::__construct(array('node' => $node, 'arguments' => $arguments), array('name' => $name), $lineno);
+ }
+
+ public function compile(Twig_Compiler $compiler)
+ {
+ $name = $this->getAttribute('name');
+ $testMap = $compiler->getEnvironment()->getTests();
+ if (!isset($testMap[$name])) {
+ $message = sprintf('The test "%s" does not exist', $name);
+ if ($alternatives = $compiler->getEnvironment()->computeAlternatives($name, array_keys($compiler->getEnvironment()->getTests()))) {
+ $message = sprintf('%s. Did you mean "%s"', $message, implode('", "', $alternatives));
+ }
+
+ throw new Twig_Error_Syntax($message, $this->getLine());
+ }
+
+ $name = $this->getAttribute('name');
+ $node = $this->getNode('node');
+
+ $compiler
+ ->raw($testMap[$name]->compile().'(')
+ ->subcompile($node)
+ ;
+
+ if (null !== $this->getNode('arguments')) {
+ $compiler->raw(', ');
+
+ $max = count($this->getNode('arguments')) - 1;
+ foreach ($this->getNode('arguments') as $i => $arg) {
+ $compiler->subcompile($arg);
+
+ if ($i != $max) {
+ $compiler->raw(', ');
+ }
+ }
+ }
+
+ $compiler->raw(')');
+ }
+}
Added: logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Test/Constant.php
URL: http://svn.apache.org/viewvc/logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Test/Constant.php?rev=1343084&view=auto
==============================================================================
--- logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Test/Constant.php (added)
+++ logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Test/Constant.php Sun May 27 19:59:46 2012
@@ -0,0 +1,36 @@
+<?php
+
+/*
+ * This file is part of Twig.
+ *
+ * (c) 2011 Fabien Potencier
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * Checks if a variable is the exact same value as a constant.
+ *
+ * <pre>
+ * {% if post.status is constant('Post::PUBLISHED') %}
+ * the status attribute is exactly the same as Post::PUBLISHED
+ * {% endif %}
+ * </pre>
+ *
+ * @package twig
+ * @author Fabien Potencier <fa...@symfony.com>
+ */
+class Twig_Node_Expression_Test_Constant extends Twig_Node_Expression_Test
+{
+ public function compile(Twig_Compiler $compiler)
+ {
+ $compiler
+ ->raw('(')
+ ->subcompile($this->getNode('node'))
+ ->raw(' === constant(')
+ ->subcompile($this->getNode('arguments')->getNode(0))
+ ->raw('))')
+ ;
+ }
+}
Added: logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Test/Defined.php
URL: http://svn.apache.org/viewvc/logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Test/Defined.php?rev=1343084&view=auto
==============================================================================
--- logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Test/Defined.php (added)
+++ logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Test/Defined.php Sun May 27 19:59:46 2012
@@ -0,0 +1,55 @@
+<?php
+
+/*
+ * This file is part of Twig.
+ *
+ * (c) 2011 Fabien Potencier
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * Checks if a variable is defined in the current context.
+ *
+ * <pre>
+ * {# defined works with variable names and variable attributes #}
+ * {% if foo is defined %}
+ * {# ... #}
+ * {% endif %}
+ * </pre>
+ *
+ * @package twig
+ * @author Fabien Potencier <fa...@symfony.com>
+ */
+class Twig_Node_Expression_Test_Defined extends Twig_Node_Expression_Test
+{
+ public function __construct(Twig_NodeInterface $node, $name, Twig_NodeInterface $arguments = null, $lineno)
+ {
+ parent::__construct($node, $name, $arguments, $lineno);
+
+ if ($node instanceof Twig_Node_Expression_Name) {
+ $node->setAttribute('is_defined_test', true);
+ } elseif ($node instanceof Twig_Node_Expression_GetAttr) {
+ $node->setAttribute('is_defined_test', true);
+
+ $this->changeIgnoreStrictCheck($node);
+ } else {
+ throw new Twig_Error_Syntax('The "defined" test only works with simple variables', $this->getLine());
+ }
+ }
+
+ protected function changeIgnoreStrictCheck(Twig_Node_Expression_GetAttr $node)
+ {
+ $node->setAttribute('ignore_strict_check', true);
+
+ if ($node->getNode('node') instanceof Twig_Node_Expression_GetAttr) {
+ $this->changeIgnoreStrictCheck($node->getNode('node'));
+ }
+ }
+
+ public function compile(Twig_Compiler $compiler)
+ {
+ $compiler->subcompile($this->getNode('node'));
+ }
+}
Added: logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Test/Divisibleby.php
URL: http://svn.apache.org/viewvc/logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Test/Divisibleby.php?rev=1343084&view=auto
==============================================================================
--- logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Test/Divisibleby.php (added)
+++ logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Test/Divisibleby.php Sun May 27 19:59:46 2012
@@ -0,0 +1,34 @@
+<?php
+
+/*
+ * This file is part of Twig.
+ *
+ * (c) 2011 Fabien Potencier
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * Checks if a variable is divisible by a number.
+ *
+ * <pre>
+ * {% if loop.index is divisibleby(3) %}
+ * </pre>
+ *
+ * @package twig
+ * @author Fabien Potencier <fa...@symfony.com>
+ */
+class Twig_Node_Expression_Test_Divisibleby extends Twig_Node_Expression_Test
+{
+ public function compile(Twig_Compiler $compiler)
+ {
+ $compiler
+ ->raw('(0 == ')
+ ->subcompile($this->getNode('node'))
+ ->raw(' % ')
+ ->subcompile($this->getNode('arguments')->getNode(0))
+ ->raw(')')
+ ;
+ }
+}
Added: logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Test/Even.php
URL: http://svn.apache.org/viewvc/logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Test/Even.php?rev=1343084&view=auto
==============================================================================
--- logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Test/Even.php (added)
+++ logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Test/Even.php Sun May 27 19:59:46 2012
@@ -0,0 +1,33 @@
+<?php
+
+/*
+ * This file is part of Twig.
+ *
+ * (c) 2011 Fabien Potencier
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * Checks if a number is even.
+ *
+ * <pre>
+ * {{ var is even }}
+ * </pre>
+ *
+ * @package twig
+ * @author Fabien Potencier <fa...@symfony.com>
+ */
+class Twig_Node_Expression_Test_Even extends Twig_Node_Expression_Test
+{
+ public function compile(Twig_Compiler $compiler)
+ {
+ $compiler
+ ->raw('(')
+ ->subcompile($this->getNode('node'))
+ ->raw(' % 2 == 0')
+ ->raw(')')
+ ;
+ }
+}
Added: logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Test/Null.php
URL: http://svn.apache.org/viewvc/logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Test/Null.php?rev=1343084&view=auto
==============================================================================
--- logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Test/Null.php (added)
+++ logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Test/Null.php Sun May 27 19:59:46 2012
@@ -0,0 +1,32 @@
+<?php
+
+/*
+ * This file is part of Twig.
+ *
+ * (c) 2011 Fabien Potencier
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * Checks that a variable is null.
+ *
+ * <pre>
+ * {{ var is none }}
+ * </pre>
+ *
+ * @package twig
+ * @author Fabien Potencier <fa...@symfony.com>
+ */
+class Twig_Node_Expression_Test_Null extends Twig_Node_Expression_Test
+{
+ public function compile(Twig_Compiler $compiler)
+ {
+ $compiler
+ ->raw('(null === ')
+ ->subcompile($this->getNode('node'))
+ ->raw(')')
+ ;
+ }
+}
Added: logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Test/Odd.php
URL: http://svn.apache.org/viewvc/logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Test/Odd.php?rev=1343084&view=auto
==============================================================================
--- logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Test/Odd.php (added)
+++ logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Test/Odd.php Sun May 27 19:59:46 2012
@@ -0,0 +1,33 @@
+<?php
+
+/*
+ * This file is part of Twig.
+ *
+ * (c) 2011 Fabien Potencier
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * Checks if a number is odd.
+ *
+ * <pre>
+ * {{ var is odd }}
+ * </pre>
+ *
+ * @package twig
+ * @author Fabien Potencier <fa...@symfony.com>
+ */
+class Twig_Node_Expression_Test_Odd extends Twig_Node_Expression_Test
+{
+ public function compile(Twig_Compiler $compiler)
+ {
+ $compiler
+ ->raw('(')
+ ->subcompile($this->getNode('node'))
+ ->raw(' % 2 == 1')
+ ->raw(')')
+ ;
+ }
+}
Added: logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Test/Sameas.php
URL: http://svn.apache.org/viewvc/logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Test/Sameas.php?rev=1343084&view=auto
==============================================================================
--- logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Test/Sameas.php (added)
+++ logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Test/Sameas.php Sun May 27 19:59:46 2012
@@ -0,0 +1,30 @@
+<?php
+
+/*
+ * This file is part of Twig.
+ *
+ * (c) 2011 Fabien Potencier
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * Checks if a variable is the same as another one (=== in PHP).
+ *
+ * @package twig
+ * @author Fabien Potencier <fa...@symfony.com>
+ */
+class Twig_Node_Expression_Test_Sameas extends Twig_Node_Expression_Test
+{
+ public function compile(Twig_Compiler $compiler)
+ {
+ $compiler
+ ->raw('(')
+ ->subcompile($this->getNode('node'))
+ ->raw(' === ')
+ ->subcompile($this->getNode('arguments')->getNode(0))
+ ->raw(')')
+ ;
+ }
+}
Added: logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Unary.php
URL: http://svn.apache.org/viewvc/logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Unary.php?rev=1343084&view=auto
==============================================================================
--- logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Unary.php (added)
+++ logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Unary.php Sun May 27 19:59:46 2012
@@ -0,0 +1,30 @@
+<?php
+
+/*
+ * 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_Node_Expression_Unary extends Twig_Node_Expression
+{
+ public function __construct(Twig_NodeInterface $node, $lineno)
+ {
+ parent::__construct(array('node' => $node), array(), $lineno);
+ }
+
+ public function compile(Twig_Compiler $compiler)
+ {
+ $compiler->raw('(');
+ $this->operator($compiler);
+ $compiler
+ ->subcompile($this->getNode('node'))
+ ->raw(')')
+ ;
+ }
+
+ abstract public function operator(Twig_Compiler $compiler);
+}
Added: logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Unary/Neg.php
URL: http://svn.apache.org/viewvc/logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Unary/Neg.php?rev=1343084&view=auto
==============================================================================
--- logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Unary/Neg.php (added)
+++ logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Unary/Neg.php Sun May 27 19:59:46 2012
@@ -0,0 +1,18 @@
+<?php
+
+/*
+ * 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.
+ */
+class Twig_Node_Expression_Unary_Neg extends Twig_Node_Expression_Unary
+{
+ public function operator(Twig_Compiler $compiler)
+ {
+ $compiler->raw('-');
+ }
+}
Added: logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Unary/Not.php
URL: http://svn.apache.org/viewvc/logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Unary/Not.php?rev=1343084&view=auto
==============================================================================
--- logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Unary/Not.php (added)
+++ logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Unary/Not.php Sun May 27 19:59:46 2012
@@ -0,0 +1,18 @@
+<?php
+
+/*
+ * 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.
+ */
+class Twig_Node_Expression_Unary_Not extends Twig_Node_Expression_Unary
+{
+ public function operator(Twig_Compiler $compiler)
+ {
+ $compiler->raw('!');
+ }
+}
Added: logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Unary/Pos.php
URL: http://svn.apache.org/viewvc/logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Unary/Pos.php?rev=1343084&view=auto
==============================================================================
--- logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Unary/Pos.php (added)
+++ logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Expression/Unary/Pos.php Sun May 27 19:59:46 2012
@@ -0,0 +1,18 @@
+<?php
+
+/*
+ * 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.
+ */
+class Twig_Node_Expression_Unary_Pos extends Twig_Node_Expression_Unary
+{
+ public function operator(Twig_Compiler $compiler)
+ {
+ $compiler->raw('+');
+ }
+}
Added: logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Flush.php
URL: http://svn.apache.org/viewvc/logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Flush.php?rev=1343084&view=auto
==============================================================================
--- logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Flush.php (added)
+++ logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Flush.php Sun May 27 19:59:46 2012
@@ -0,0 +1,37 @@
+<?php
+
+/*
+ * This file is part of Twig.
+ *
+ * (c) 2011 Fabien Potencier
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * Represents a flush node.
+ *
+ * @package twig
+ * @author Fabien Potencier <fa...@symfony.com>
+ */
+class Twig_Node_Flush extends Twig_Node
+{
+ public function __construct($lineno, $tag)
+ {
+ parent::__construct(array(), array(), $lineno, $tag);
+ }
+
+ /**
+ * Compiles the node to PHP.
+ *
+ * @param Twig_Compiler A Twig_Compiler instance
+ */
+ public function compile(Twig_Compiler $compiler)
+ {
+ $compiler
+ ->addDebugInfo($this)
+ ->write("flush();\n")
+ ;
+ }
+}
Added: logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/For.php
URL: http://svn.apache.org/viewvc/logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/For.php?rev=1343084&view=auto
==============================================================================
--- logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/For.php (added)
+++ logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/For.php Sun May 27 19:59:46 2012
@@ -0,0 +1,113 @@
+<?php
+
+/*
+ * 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.
+ */
+
+/**
+ * Represents a for node.
+ *
+ * @package twig
+ * @author Fabien Potencier <fa...@symfony.com>
+ */
+class Twig_Node_For extends Twig_Node
+{
+ protected $loop;
+
+ public function __construct(Twig_Node_Expression_AssignName $keyTarget, Twig_Node_Expression_AssignName $valueTarget, Twig_Node_Expression $seq, Twig_Node_Expression $ifexpr = null, Twig_NodeInterface $body, Twig_NodeInterface $else = null, $lineno, $tag = null)
+ {
+ $body = new Twig_Node(array($body, $this->loop = new Twig_Node_ForLoop($lineno, $tag)));
+
+ if (null !== $ifexpr) {
+ $body = new Twig_Node_If(new Twig_Node(array($ifexpr, $body)), null, $lineno, $tag);
+ }
+
+ parent::__construct(array('key_target' => $keyTarget, 'value_target' => $valueTarget, 'seq' => $seq, 'body' => $body, 'else' => $else), array('with_loop' => true, 'ifexpr' => null !== $ifexpr), $lineno, $tag);
+ }
+
+ /**
+ * Compiles the node to PHP.
+ *
+ * @param Twig_Compiler A Twig_Compiler instance
+ */
+ public function compile(Twig_Compiler $compiler)
+ {
+ $compiler
+ ->addDebugInfo($this)
+ // the (array) cast bypasses a PHP 5.2.6 bug
+ ->write("\$context['_parent'] = (array) \$context;\n")
+ ->write("\$context['_seq'] = twig_ensure_traversable(")
+ ->subcompile($this->getNode('seq'))
+ ->raw(");\n")
+ ;
+
+ if (null !== $this->getNode('else')) {
+ $compiler->write("\$context['_iterated'] = false;\n");
+ }
+
+ if ($this->getAttribute('with_loop')) {
+ $compiler
+ ->write("\$context['loop'] = array(\n")
+ ->write(" 'parent' => \$context['_parent'],\n")
+ ->write(" 'index0' => 0,\n")
+ ->write(" 'index' => 1,\n")
+ ->write(" 'first' => true,\n")
+ ->write(");\n")
+ ;
+
+ if (!$this->getAttribute('ifexpr')) {
+ $compiler
+ ->write("if (is_array(\$context['_seq']) || (is_object(\$context['_seq']) && \$context['_seq'] instanceof Countable)) {\n")
+ ->indent()
+ ->write("\$length = count(\$context['_seq']);\n")
+ ->write("\$context['loop']['revindex0'] = \$length - 1;\n")
+ ->write("\$context['loop']['revindex'] = \$length;\n")
+ ->write("\$context['loop']['length'] = \$length;\n")
+ ->write("\$context['loop']['last'] = 1 === \$length;\n")
+ ->outdent()
+ ->write("}\n")
+ ;
+ }
+ }
+
+ $this->loop->setAttribute('else', null !== $this->getNode('else'));
+ $this->loop->setAttribute('with_loop', $this->getAttribute('with_loop'));
+ $this->loop->setAttribute('ifexpr', $this->getAttribute('ifexpr'));
+
+ $compiler
+ ->write("foreach (\$context['_seq'] as ")
+ ->subcompile($this->getNode('key_target'))
+ ->raw(" => ")
+ ->subcompile($this->getNode('value_target'))
+ ->raw(") {\n")
+ ->indent()
+ ->subcompile($this->getNode('body'))
+ ->outdent()
+ ->write("}\n")
+ ;
+
+ if (null !== $this->getNode('else')) {
+ $compiler
+ ->write("if (!\$context['_iterated']) {\n")
+ ->indent()
+ ->subcompile($this->getNode('else'))
+ ->outdent()
+ ->write("}\n")
+ ;
+ }
+
+ $compiler->write("\$_parent = \$context['_parent'];\n");
+
+ // remove some "private" loop variables (needed for nested loops)
+ $compiler->write('unset($context[\'_seq\'], $context[\'_iterated\'], $context[\''.$this->getNode('key_target')->getAttribute('name').'\'], $context[\''.$this->getNode('value_target')->getAttribute('name').'\'], $context[\'_parent\'], $context[\'loop\']);'."\n");
+
+ // keep the values set in the inner context for variables defined in the outer context
+ $compiler->write("\$context = array_merge(\$_parent, array_intersect_key(\$context, \$_parent));\n");
+ }
+}
Added: logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/ForLoop.php
URL: http://svn.apache.org/viewvc/logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/ForLoop.php?rev=1343084&view=auto
==============================================================================
--- logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/ForLoop.php (added)
+++ logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/ForLoop.php Sun May 27 19:59:46 2012
@@ -0,0 +1,56 @@
+<?php
+
+/*
+ * This file is part of Twig.
+ *
+ * (c) 2011 Fabien Potencier
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * Internal node used by the for node.
+ *
+ * @package twig
+ * @author Fabien Potencier <fa...@symfony.com>
+ */
+class Twig_Node_ForLoop extends Twig_Node
+{
+ public function __construct($lineno, $tag = null)
+ {
+ parent::__construct(array(), array('with_loop' => false, 'ifexpr' => false, 'else' => false), $lineno, $tag);
+ }
+
+ /**
+ * Compiles the node to PHP.
+ *
+ * @param Twig_Compiler A Twig_Compiler instance
+ */
+ public function compile(Twig_Compiler $compiler)
+ {
+ if ($this->getAttribute('else')) {
+ $compiler->write("\$context['_iterated'] = true;\n");
+ }
+
+ if ($this->getAttribute('with_loop')) {
+ $compiler
+ ->write("++\$context['loop']['index0'];\n")
+ ->write("++\$context['loop']['index'];\n")
+ ->write("\$context['loop']['first'] = false;\n")
+ ;
+
+ if (!$this->getAttribute('ifexpr')) {
+ $compiler
+ ->write("if (isset(\$context['loop']['length'])) {\n")
+ ->indent()
+ ->write("--\$context['loop']['revindex0'];\n")
+ ->write("--\$context['loop']['revindex'];\n")
+ ->write("\$context['loop']['last'] = 0 === \$context['loop']['revindex0'];\n")
+ ->outdent()
+ ->write("}\n")
+ ;
+ }
+ }
+ }
+}
Added: logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/If.php
URL: http://svn.apache.org/viewvc/logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/If.php?rev=1343084&view=auto
==============================================================================
--- logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/If.php (added)
+++ logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/If.php Sun May 27 19:59:46 2012
@@ -0,0 +1,67 @@
+<?php
+
+/*
+ * 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.
+ */
+
+/**
+ * Represents an if node.
+ *
+ * @package twig
+ * @author Fabien Potencier <fa...@symfony.com>
+ */
+class Twig_Node_If extends Twig_Node
+{
+ public function __construct(Twig_NodeInterface $tests, Twig_NodeInterface $else = null, $lineno, $tag = null)
+ {
+ parent::__construct(array('tests' => $tests, 'else' => $else), array(), $lineno, $tag);
+ }
+
+ /**
+ * Compiles the node to PHP.
+ *
+ * @param Twig_Compiler A Twig_Compiler instance
+ */
+ public function compile(Twig_Compiler $compiler)
+ {
+ $compiler->addDebugInfo($this);
+ for ($i = 0; $i < count($this->getNode('tests')); $i += 2) {
+ if ($i > 0) {
+ $compiler
+ ->outdent()
+ ->write("} elseif (")
+ ;
+ } else {
+ $compiler
+ ->write('if (')
+ ;
+ }
+
+ $compiler
+ ->subcompile($this->getNode('tests')->getNode($i))
+ ->raw(") {\n")
+ ->indent()
+ ->subcompile($this->getNode('tests')->getNode($i + 1))
+ ;
+ }
+
+ if ($this->hasNode('else') && null !== $this->getNode('else')) {
+ $compiler
+ ->outdent()
+ ->write("} else {\n")
+ ->indent()
+ ->subcompile($this->getNode('else'))
+ ;
+ }
+
+ $compiler
+ ->outdent()
+ ->write("}\n");
+ }
+}
Added: logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Import.php
URL: http://svn.apache.org/viewvc/logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Import.php?rev=1343084&view=auto
==============================================================================
--- logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Import.php (added)
+++ logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Import.php Sun May 27 19:59:46 2012
@@ -0,0 +1,51 @@
+<?php
+
+/*
+ * This file is part of Twig.
+ *
+ * (c) 2009 Fabien Potencier
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * Represents an import node.
+ *
+ * @package twig
+ * @author Fabien Potencier <fa...@symfony.com>
+ */
+class Twig_Node_Import extends Twig_Node
+{
+ public function __construct(Twig_Node_Expression $expr, Twig_Node_Expression $var, $lineno, $tag = null)
+ {
+ parent::__construct(array('expr' => $expr, 'var' => $var), array(), $lineno, $tag);
+ }
+
+ /**
+ * Compiles the node to PHP.
+ *
+ * @param Twig_Compiler A Twig_Compiler instance
+ */
+ public function compile(Twig_Compiler $compiler)
+ {
+ $compiler
+ ->addDebugInfo($this)
+ ->write('')
+ ->subcompile($this->getNode('var'))
+ ->raw(' = ')
+ ;
+
+ if ($this->getNode('expr') instanceof Twig_Node_Expression_Name && '_self' === $this->getNode('expr')->getAttribute('name')) {
+ $compiler->raw("\$this");
+ } else {
+ $compiler
+ ->raw('$this->env->loadTemplate(')
+ ->subcompile($this->getNode('expr'))
+ ->raw(")")
+ ;
+ }
+
+ $compiler->raw(";\n");
+ }
+}
Added: logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Include.php
URL: http://svn.apache.org/viewvc/logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Include.php?rev=1343084&view=auto
==============================================================================
--- logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Include.php (added)
+++ logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Include.php Sun May 27 19:59:46 2012
@@ -0,0 +1,100 @@
+<?php
+
+/*
+ * 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.
+ */
+
+/**
+ * Represents an include node.
+ *
+ * @package twig
+ * @author Fabien Potencier <fa...@symfony.com>
+ */
+class Twig_Node_Include extends Twig_Node implements Twig_NodeOutputInterface
+{
+ public function __construct(Twig_Node_Expression $expr, Twig_Node_Expression $variables = null, $only = false, $ignoreMissing = false, $lineno, $tag = null)
+ {
+ parent::__construct(array('expr' => $expr, 'variables' => $variables), array('only' => (Boolean) $only, 'ignore_missing' => (Boolean) $ignoreMissing), $lineno, $tag);
+ }
+
+ /**
+ * Compiles the node to PHP.
+ *
+ * @param Twig_Compiler A Twig_Compiler instance
+ */
+ public function compile(Twig_Compiler $compiler)
+ {
+ $compiler->addDebugInfo($this);
+
+ if ($this->getAttribute('ignore_missing')) {
+ $compiler
+ ->write("try {\n")
+ ->indent()
+ ;
+ }
+
+ $this->addGetTemplate($compiler);
+
+ $compiler->raw('->display(');
+
+ $this->addTemplateArguments($compiler);
+
+ $compiler->raw(");\n");
+
+ if ($this->getAttribute('ignore_missing')) {
+ $compiler
+ ->outdent()
+ ->write("} catch (Twig_Error_Loader \$e) {\n")
+ ->indent()
+ ->write("// ignore missing template\n")
+ ->outdent()
+ ->write("}\n\n")
+ ;
+ }
+ }
+
+ protected function addGetTemplate(Twig_Compiler $compiler)
+ {
+ if ($this->getNode('expr') instanceof Twig_Node_Expression_Constant) {
+ $compiler
+ ->write("\$this->env->loadTemplate(")
+ ->subcompile($this->getNode('expr'))
+ ->raw(")")
+ ;
+ } else {
+ $compiler
+ ->write("\$template = \$this->env->resolveTemplate(")
+ ->subcompile($this->getNode('expr'))
+ ->raw(");\n")
+ ->write('$template')
+ ;
+ }
+ }
+
+ protected function addTemplateArguments(Twig_Compiler $compiler)
+ {
+ if (false === $this->getAttribute('only')) {
+ if (null === $this->getNode('variables')) {
+ $compiler->raw('$context');
+ } else {
+ $compiler
+ ->raw('array_merge($context, ')
+ ->subcompile($this->getNode('variables'))
+ ->raw(')')
+ ;
+ }
+ } else {
+ if (null === $this->getNode('variables')) {
+ $compiler->raw('array()');
+ } else {
+ $compiler->subcompile($this->getNode('variables'));
+ }
+ }
+ }
+}
Added: logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Macro.php
URL: http://svn.apache.org/viewvc/logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Macro.php?rev=1343084&view=auto
==============================================================================
--- logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Macro.php (added)
+++ logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Macro.php Sun May 27 19:59:46 2012
@@ -0,0 +1,84 @@
+<?php
+
+/*
+ * This file is part of Twig.
+ *
+ * (c) 2009 Fabien Potencier
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * Represents a macro node.
+ *
+ * @package twig
+ * @author Fabien Potencier <fa...@symfony.com>
+ */
+class Twig_Node_Macro extends Twig_Node
+{
+ public function __construct($name, Twig_NodeInterface $body, Twig_NodeInterface $arguments, $lineno, $tag = null)
+ {
+ parent::__construct(array('body' => $body, 'arguments' => $arguments), array('name' => $name), $lineno, $tag);
+ }
+
+ /**
+ * Compiles the node to PHP.
+ *
+ * @param Twig_Compiler A Twig_Compiler instance
+ */
+ public function compile(Twig_Compiler $compiler)
+ {
+ $arguments = array();
+ foreach ($this->getNode('arguments') as $argument) {
+ $arguments[] = '$'.$argument->getAttribute('name').' = null';
+ }
+
+ $compiler
+ ->addDebugInfo($this)
+ ->write(sprintf("public function get%s(%s)\n", $this->getAttribute('name'), implode(', ', $arguments)), "{\n")
+ ->indent()
+ ;
+
+ if (!count($this->getNode('arguments'))) {
+ $compiler->write("\$context = \$this->env->getGlobals();\n\n");
+ } else {
+ $compiler
+ ->write("\$context = \$this->env->mergeGlobals(array(\n")
+ ->indent()
+ ;
+
+ foreach ($this->getNode('arguments') as $argument) {
+ $compiler
+ ->write('')
+ ->string($argument->getAttribute('name'))
+ ->raw(' => $'.$argument->getAttribute('name'))
+ ->raw(",\n")
+ ;
+ }
+
+ $compiler
+ ->outdent()
+ ->write("));\n\n")
+ ;
+ }
+
+ $compiler
+ ->write("\$blocks = array();\n\n")
+ ->write("ob_start();\n")
+ ->write("try {\n")
+ ->indent()
+ ->subcompile($this->getNode('body'))
+ ->outdent()
+ ->write("} catch(Exception \$e) {\n")
+ ->indent()
+ ->write("ob_end_clean();\n\n")
+ ->write("throw \$e;\n")
+ ->outdent()
+ ->write("}\n\n")
+ ->write("return ob_get_clean();\n")
+ ->outdent()
+ ->write("}\n\n")
+ ;
+ }
+}
Added: logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Module.php
URL: http://svn.apache.org/viewvc/logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Module.php?rev=1343084&view=auto
==============================================================================
--- logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Module.php (added)
+++ logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Module.php Sun May 27 19:59:46 2012
@@ -0,0 +1,372 @@
+<?php
+
+/*
+ * 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.
+ */
+
+/**
+ * Represents a module node.
+ *
+ * @package twig
+ * @author Fabien Potencier <fa...@symfony.com>
+ */
+class Twig_Node_Module extends Twig_Node
+{
+ public function __construct(Twig_NodeInterface $body, Twig_Node_Expression $parent = null, Twig_NodeInterface $blocks, Twig_NodeInterface $macros, Twig_NodeInterface $traits, $embeddedTemplates, $filename)
+ {
+ // embedded templates are set as attributes so that they are only visited once by the visitors
+ parent::__construct(array('parent' => $parent, 'body' => $body, 'blocks' => $blocks, 'macros' => $macros, 'traits' => $traits), array('filename' => $filename, 'index' => null, 'embedded_templates' => $embeddedTemplates), 1);
+ }
+
+ public function setIndex($index)
+ {
+ $this->setAttribute('index', $index);
+ }
+
+ /**
+ * Compiles the node to PHP.
+ *
+ * @param Twig_Compiler A Twig_Compiler instance
+ */
+ public function compile(Twig_Compiler $compiler)
+ {
+ $this->compileTemplate($compiler);
+
+ foreach ($this->getAttribute('embedded_templates') as $template) {
+ $compiler->subcompile($template);
+ }
+ }
+
+ protected function compileTemplate(Twig_Compiler $compiler)
+ {
+ if (!$this->getAttribute('index')) {
+ $compiler->write('<?php');
+ }
+
+ $this->compileClassHeader($compiler);
+
+ if (count($this->getNode('blocks')) || count($this->getNode('traits')) || null === $this->getNode('parent') || $this->getNode('parent') instanceof Twig_Node_Expression_Constant) {
+ $this->compileConstructor($compiler);
+ }
+
+ $this->compileGetParent($compiler);
+
+ $this->compileDisplayHeader($compiler);
+
+ $this->compileDisplayBody($compiler);
+
+ $this->compileDisplayFooter($compiler);
+
+ $compiler->subcompile($this->getNode('blocks'));
+
+ $this->compileMacros($compiler);
+
+ $this->compileGetTemplateName($compiler);
+
+ $this->compileIsTraitable($compiler);
+
+ $this->compileDebugInfo($compiler);
+
+ $this->compileClassFooter($compiler);
+ }
+
+ protected function compileGetParent(Twig_Compiler $compiler)
+ {
+ if (null === $this->getNode('parent')) {
+ return;
+ }
+
+ $compiler
+ ->write("protected function doGetParent(array \$context)\n", "{\n")
+ ->indent()
+ ->write("return ")
+ ;
+
+ if ($this->getNode('parent') instanceof Twig_Node_Expression_Constant) {
+ $compiler->subcompile($this->getNode('parent'));
+ } else {
+ $compiler
+ ->raw("\$this->env->resolveTemplate(")
+ ->subcompile($this->getNode('parent'))
+ ->raw(")")
+ ;
+ }
+
+ $compiler
+ ->raw(";\n")
+ ->outdent()
+ ->write("}\n\n")
+ ;
+ }
+
+ protected function compileDisplayBody(Twig_Compiler $compiler)
+ {
+ $compiler->subcompile($this->getNode('body'));
+
+ if (null !== $this->getNode('parent')) {
+ if ($this->getNode('parent') instanceof Twig_Node_Expression_Constant) {
+ $compiler->write("\$this->parent");
+ } else {
+ $compiler->write("\$this->getParent(\$context)");
+ }
+ $compiler->raw("->display(\$context, array_merge(\$this->blocks, \$blocks));\n");
+ }
+ }
+
+ protected function compileClassHeader(Twig_Compiler $compiler)
+ {
+ $compiler
+ ->write("\n\n")
+ // if the filename contains */, add a blank to avoid a PHP parse error
+ ->write("/* ".str_replace('*/', '* /', $this->getAttribute('filename'))." */\n")
+ ->write('class '.$compiler->getEnvironment()->getTemplateClass($this->getAttribute('filename'), $this->getAttribute('index')))
+ ->raw(sprintf(" extends %s\n", $compiler->getEnvironment()->getBaseTemplateClass()))
+ ->write("{\n")
+ ->indent()
+ ;
+ }
+
+ protected function compileConstructor(Twig_Compiler $compiler)
+ {
+ $compiler
+ ->write("public function __construct(Twig_Environment \$env)\n", "{\n")
+ ->indent()
+ ->write("parent::__construct(\$env);\n\n")
+ ;
+
+ // parent
+ if (null === $this->getNode('parent')) {
+ $compiler->write("\$this->parent = false;\n\n");
+ } elseif ($this->getNode('parent') instanceof Twig_Node_Expression_Constant) {
+ $compiler
+ ->write("\$this->parent = \$this->env->loadTemplate(")
+ ->subcompile($this->getNode('parent'))
+ ->raw(");\n\n")
+ ;
+ }
+
+ $countTraits = count($this->getNode('traits'));
+ if ($countTraits) {
+ // traits
+ foreach ($this->getNode('traits') as $i => $trait) {
+ $this->compileLoadTemplate($compiler, $trait->getNode('template'), sprintf('$_trait_%s', $i));
+
+ $compiler
+ ->addDebugInfo($trait->getNode('template'))
+ ->write(sprintf("if (!\$_trait_%s->isTraitable()) {\n", $i))
+ ->indent()
+ ->write("throw new Twig_Error_Runtime('Template \"'.")
+ ->subcompile($trait->getNode('template'))
+ ->raw(".'\" cannot be used as a trait.');\n")
+ ->outdent()
+ ->write("}\n")
+ ->write(sprintf("\$_trait_%s_blocks = \$_trait_%s->getBlocks();\n\n", $i, $i))
+ ;
+
+ foreach ($trait->getNode('targets') as $key => $value) {
+ $compiler
+ ->write(sprintf("\$_trait_%s_blocks[", $i))
+ ->subcompile($value)
+ ->raw(sprintf("] = \$_trait_%s_blocks[", $i))
+ ->string($key)
+ ->raw(sprintf("]; unset(\$_trait_%s_blocks[", $i))
+ ->string($key)
+ ->raw("]);\n\n")
+ ;
+ }
+ }
+
+ if ($countTraits > 1) {
+ $compiler
+ ->write("\$this->traits = array_merge(\n")
+ ->indent()
+ ;
+
+ for ($i = 0; $i < $countTraits; $i++) {
+ $compiler
+ ->write(sprintf("\$_trait_%s_blocks".($i == $countTraits - 1 ? '' : ',')."\n", $i))
+ ;
+ }
+
+ $compiler
+ ->outdent()
+ ->write(");\n\n")
+ ;
+ } else {
+ $compiler
+ ->write("\$this->traits = \$_trait_0_blocks;\n\n")
+ ;
+ }
+
+ $compiler
+ ->write("\$this->blocks = array_merge(\n")
+ ->indent()
+ ->write("\$this->traits,\n")
+ ->write("array(\n")
+ ;
+ } else {
+ $compiler
+ ->write("\$this->blocks = array(\n")
+ ;
+ }
+
+ // blocks
+ $compiler
+ ->indent()
+ ;
+
+ foreach ($this->getNode('blocks') as $name => $node) {
+ $compiler
+ ->write(sprintf("'%s' => array(\$this, 'block_%s'),\n", $name, $name))
+ ;
+ }
+
+ if ($countTraits) {
+ $compiler
+ ->outdent()
+ ->write(")\n")
+ ;
+ }
+
+ $compiler
+ ->outdent()
+ ->write(");\n")
+ ->outdent()
+ ->write("}\n\n");
+ ;
+ }
+
+ protected function compileDisplayHeader(Twig_Compiler $compiler)
+ {
+ $compiler
+ ->write("protected function doDisplay(array \$context, array \$blocks = array())\n", "{\n")
+ ->indent()
+ ;
+ }
+
+ protected function compileDisplayFooter(Twig_Compiler $compiler)
+ {
+ $compiler
+ ->outdent()
+ ->write("}\n\n")
+ ;
+ }
+
+ protected function compileClassFooter(Twig_Compiler $compiler)
+ {
+ $compiler
+ ->outdent()
+ ->write("}\n")
+ ;
+ }
+
+ protected function compileMacros(Twig_Compiler $compiler)
+ {
+ $compiler->subcompile($this->getNode('macros'));
+ }
+
+ protected function compileGetTemplateName(Twig_Compiler $compiler)
+ {
+ $compiler
+ ->write("public function getTemplateName()\n", "{\n")
+ ->indent()
+ ->write('return ')
+ ->repr($this->getAttribute('filename'))
+ ->raw(";\n")
+ ->outdent()
+ ->write("}\n\n")
+ ;
+ }
+
+ protected function compileIsTraitable(Twig_Compiler $compiler)
+ {
+ // A template can be used as a trait if:
+ // * it has no parent
+ // * it has no macros
+ // * it has no body
+ //
+ // Put another way, a template can be used as a trait if it
+ // only contains blocks and use statements.
+ $traitable = null === $this->getNode('parent') && 0 === count($this->getNode('macros'));
+ if ($traitable) {
+ if ($this->getNode('body') instanceof Twig_Node_Body) {
+ $nodes = $this->getNode('body')->getNode(0);
+ } else {
+ $nodes = $this->getNode('body');
+ }
+
+ if (!count($nodes)) {
+ $nodes = new Twig_Node(array($nodes));
+ }
+
+ foreach ($nodes as $node) {
+ if (!count($node)) {
+ continue;
+ }
+
+ if ($node instanceof Twig_Node_Text && ctype_space($node->getAttribute('data'))) {
+ continue;
+ }
+
+ if ($node instanceof Twig_Node_BlockReference) {
+ continue;
+ }
+
+ $traitable = false;
+ break;
+ }
+ }
+
+ if ($traitable) {
+ return;
+ }
+
+ $compiler
+ ->write("public function isTraitable()\n", "{\n")
+ ->indent()
+ ->write(sprintf("return %s;\n", $traitable ? 'true' : 'false'))
+ ->outdent()
+ ->write("}\n\n")
+ ;
+ }
+
+ protected function compileDebugInfo(Twig_Compiler $compiler)
+ {
+ $compiler
+ ->write("public function getDebugInfo()\n", "{\n")
+ ->indent()
+ ->write(sprintf("return %s;\n", str_replace("\n", '', var_export(array_reverse($compiler->getDebugInfo(), true), true))))
+ ->outdent()
+ ->write("}\n")
+ ;
+ }
+
+ protected function compileLoadTemplate(Twig_Compiler $compiler, $node, $var)
+ {
+ if ($node instanceof Twig_Node_Expression_Constant) {
+ $compiler
+ ->write(sprintf("%s = \$this->env->loadTemplate(", $var))
+ ->subcompile($node)
+ ->raw(");\n")
+ ;
+ } else {
+ $compiler
+ ->write(sprintf("%s = ", $var))
+ ->subcompile($node)
+ ->raw(";\n")
+ ->write(sprintf("if (!%s", $var))
+ ->raw(" instanceof Twig_Template) {\n")
+ ->indent()
+ ->write(sprintf("%s = \$this->env->loadTemplate(%s);\n", $var, $var))
+ ->outdent()
+ ->write("}\n")
+ ;
+ }
+ }
+}
Added: logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Print.php
URL: http://svn.apache.org/viewvc/logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Print.php?rev=1343084&view=auto
==============================================================================
--- logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Print.php (added)
+++ logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Print.php Sun May 27 19:59:46 2012
@@ -0,0 +1,40 @@
+<?php
+
+/*
+ * 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.
+ */
+
+/**
+ * Represents a node that outputs an expression.
+ *
+ * @package twig
+ * @author Fabien Potencier <fa...@symfony.com>
+ */
+class Twig_Node_Print extends Twig_Node implements Twig_NodeOutputInterface
+{
+ public function __construct(Twig_Node_Expression $expr, $lineno, $tag = null)
+ {
+ parent::__construct(array('expr' => $expr), array(), $lineno, $tag);
+ }
+
+ /**
+ * Compiles the node to PHP.
+ *
+ * @param Twig_Compiler A Twig_Compiler instance
+ */
+ public function compile(Twig_Compiler $compiler)
+ {
+ $compiler
+ ->addDebugInfo($this)
+ ->write('echo ')
+ ->subcompile($this->getNode('expr'))
+ ->raw(";\n")
+ ;
+ }
+}
Added: logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Sandbox.php
URL: http://svn.apache.org/viewvc/logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Sandbox.php?rev=1343084&view=auto
==============================================================================
--- logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Sandbox.php (added)
+++ logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Sandbox.php Sun May 27 19:59:46 2012
@@ -0,0 +1,48 @@
+<?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 sandbox node.
+ *
+ * @package twig
+ * @author Fabien Potencier <fa...@symfony.com>
+ */
+class Twig_Node_Sandbox extends Twig_Node
+{
+ public function __construct(Twig_NodeInterface $body, $lineno, $tag = null)
+ {
+ parent::__construct(array('body' => $body), array(), $lineno, $tag);
+ }
+
+ /**
+ * Compiles the node to PHP.
+ *
+ * @param Twig_Compiler A Twig_Compiler instance
+ */
+ public function compile(Twig_Compiler $compiler)
+ {
+ $compiler
+ ->addDebugInfo($this)
+ ->write("\$sandbox = \$this->env->getExtension('sandbox');\n")
+ ->write("if (!\$alreadySandboxed = \$sandbox->isSandboxed()) {\n")
+ ->indent()
+ ->write("\$sandbox->enableSandbox();\n")
+ ->outdent()
+ ->write("}\n")
+ ->subcompile($this->getNode('body'))
+ ->write("if (!\$alreadySandboxed) {\n")
+ ->indent()
+ ->write("\$sandbox->disableSandbox();\n")
+ ->outdent()
+ ->write("}\n")
+ ;
+ }
+}
Added: logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/SandboxedModule.php
URL: http://svn.apache.org/viewvc/logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/SandboxedModule.php?rev=1343084&view=auto
==============================================================================
--- logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/SandboxedModule.php (added)
+++ logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/SandboxedModule.php Sun May 27 19:59:46 2012
@@ -0,0 +1,61 @@
+<?php
+
+/*
+ * 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.
+ */
+
+/**
+ * Represents a module node.
+ *
+ * @package twig
+ * @author Fabien Potencier <fa...@symfony.com>
+ */
+class Twig_Node_SandboxedModule extends Twig_Node_Module
+{
+ protected $usedFilters;
+ protected $usedTags;
+ protected $usedFunctions;
+
+ public function __construct(Twig_Node_Module $node, array $usedFilters, array $usedTags, array $usedFunctions)
+ {
+ parent::__construct($node->getNode('body'), $node->getNode('parent'), $node->getNode('blocks'), $node->getNode('macros'), $node->getNode('traits'), $node->getAttribute('embedded_templates'), $node->getAttribute('filename'), $node->getLine(), $node->getNodeTag());
+
+ $this->setAttribute('index', $node->getAttribute('index'));
+
+ $this->usedFilters = $usedFilters;
+ $this->usedTags = $usedTags;
+ $this->usedFunctions = $usedFunctions;
+ }
+
+ protected function compileDisplayBody(Twig_Compiler $compiler)
+ {
+ $compiler->write("\$this->checkSecurity();\n");
+
+ parent::compileDisplayBody($compiler);
+ }
+
+ protected function compileDisplayFooter(Twig_Compiler $compiler)
+ {
+ parent::compileDisplayFooter($compiler);
+
+ $compiler
+ ->write("protected function checkSecurity() {\n")
+ ->indent()
+ ->write("\$this->env->getExtension('sandbox')->checkSecurity(\n")
+ ->indent()
+ ->write(!$this->usedTags ? "array(),\n" : "array('".implode('\', \'', $this->usedTags)."'),\n")
+ ->write(!$this->usedFilters ? "array(),\n" : "array('".implode('\', \'', $this->usedFilters)."'),\n")
+ ->write(!$this->usedFunctions ? "array()\n" : "array('".implode('\', \'', $this->usedFunctions)."')\n")
+ ->outdent()
+ ->write(");\n")
+ ->outdent()
+ ->write("}\n\n")
+ ;
+ }
+}
Added: logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/SandboxedPrint.php
URL: http://svn.apache.org/viewvc/logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/SandboxedPrint.php?rev=1343084&view=auto
==============================================================================
--- logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/SandboxedPrint.php (added)
+++ logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/SandboxedPrint.php Sun May 27 19:59:46 2012
@@ -0,0 +1,60 @@
+<?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.
+ */
+
+/**
+ * Twig_Node_SandboxedPrint adds a check for the __toString() method
+ * when the variable is an object and the sandbox is activated.
+ *
+ * When there is a simple Print statement, like {{ article }},
+ * and if the sandbox is enabled, we need to check that the __toString()
+ * method is allowed if 'article' is an object.
+ *
+ * @package twig
+ * @author Fabien Potencier <fa...@symfony.com>
+ */
+class Twig_Node_SandboxedPrint extends Twig_Node_Print
+{
+ public function __construct(Twig_Node_Expression $expr, $lineno, $tag = null)
+ {
+ parent::__construct($expr, $lineno, $tag);
+ }
+
+ /**
+ * Compiles the node to PHP.
+ *
+ * @param Twig_Compiler A Twig_Compiler instance
+ */
+ public function compile(Twig_Compiler $compiler)
+ {
+ $compiler
+ ->addDebugInfo($this)
+ ->write('echo $this->env->getExtension(\'sandbox\')->ensureToStringAllowed(')
+ ->subcompile($this->getNode('expr'))
+ ->raw(");\n")
+ ;
+ }
+
+ /**
+ * Removes node filters.
+ *
+ * This is mostly needed when another visitor adds filters (like the escaper one).
+ *
+ * @param Twig_Node $node A Node
+ */
+ protected function removeNodeFilter($node)
+ {
+ if ($node instanceof Twig_Node_Expression_Filter) {
+ return $this->removeNodeFilter($node->getNode('node'));
+ }
+
+ return $node;
+ }
+}
Added: logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Set.php
URL: http://svn.apache.org/viewvc/logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Set.php?rev=1343084&view=auto
==============================================================================
--- logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Set.php (added)
+++ logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Set.php Sun May 27 19:59:46 2012
@@ -0,0 +1,102 @@
+<?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 set node.
+ *
+ * @package twig
+ * @author Fabien Potencier <fa...@symfony.com>
+ */
+class Twig_Node_Set extends Twig_Node
+{
+ public function __construct($capture, Twig_NodeInterface $names, Twig_NodeInterface $values, $lineno, $tag = null)
+ {
+ parent::__construct(array('names' => $names, 'values' => $values), array('capture' => $capture, 'safe' => false), $lineno, $tag);
+
+ /*
+ * Optimizes the node when capture is used for a large block of text.
+ *
+ * {% set foo %}foo{% endset %} is compiled to $context['foo'] = new Twig_Markup("foo");
+ */
+ if ($this->getAttribute('capture')) {
+ $this->setAttribute('safe', true);
+
+ $values = $this->getNode('values');
+ if ($values instanceof Twig_Node_Text) {
+ $this->setNode('values', new Twig_Node_Expression_Constant($values->getAttribute('data'), $values->getLine()));
+ $this->setAttribute('capture', false);
+ }
+ }
+ }
+
+ /**
+ * Compiles the node to PHP.
+ *
+ * @param Twig_Compiler A Twig_Compiler instance
+ */
+ public function compile(Twig_Compiler $compiler)
+ {
+ $compiler->addDebugInfo($this);
+
+ if (count($this->getNode('names')) > 1) {
+ $compiler->write('list(');
+ foreach ($this->getNode('names') as $idx => $node) {
+ if ($idx) {
+ $compiler->raw(', ');
+ }
+
+ $compiler->subcompile($node);
+ }
+ $compiler->raw(')');
+ } else {
+ if ($this->getAttribute('capture')) {
+ $compiler
+ ->write("ob_start();\n")
+ ->subcompile($this->getNode('values'))
+ ;
+ }
+
+ $compiler->subcompile($this->getNode('names'), false);
+
+ if ($this->getAttribute('capture')) {
+ $compiler->raw(" = ('' === \$tmp = ob_get_clean()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset())");
+ }
+ }
+
+ if (!$this->getAttribute('capture')) {
+ $compiler->raw(' = ');
+
+ if (count($this->getNode('names')) > 1) {
+ $compiler->write('array(');
+ foreach ($this->getNode('values') as $idx => $value) {
+ if ($idx) {
+ $compiler->raw(', ');
+ }
+
+ $compiler->subcompile($value);
+ }
+ $compiler->raw(')');
+ } else {
+ if ($this->getAttribute('safe')) {
+ $compiler
+ ->raw("('' === \$tmp = ")
+ ->subcompile($this->getNode('values'))
+ ->raw(") ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset())")
+ ;
+ } else {
+ $compiler->subcompile($this->getNode('values'));
+ }
+ }
+ }
+
+ $compiler->raw(";\n");
+ }
+}
Added: logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/SetTemp.php
URL: http://svn.apache.org/viewvc/logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/SetTemp.php?rev=1343084&view=auto
==============================================================================
--- logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/SetTemp.php (added)
+++ logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/SetTemp.php Sun May 27 19:59:46 2012
@@ -0,0 +1,35 @@
+<?php
+
+/*
+ * This file is part of Twig.
+ *
+ * (c) 2011 Fabien Potencier
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+class Twig_Node_SetTemp extends Twig_Node
+{
+ public function __construct($name, $lineno)
+ {
+ parent::__construct(array(), array('name' => $name), $lineno);
+ }
+
+ public function compile(Twig_Compiler $compiler)
+ {
+ $name = $this->getAttribute('name');
+ $compiler
+ ->addDebugInfo($this)
+ ->write('if (isset($context[')
+ ->string($name)
+ ->raw('])) { $_')
+ ->raw($name)
+ ->raw('_ = $context[')
+ ->repr($name)
+ ->raw(']; } else { $_')
+ ->raw($name)
+ ->raw("_ = null; }\n")
+ ;
+ }
+}
Added: logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Spaceless.php
URL: http://svn.apache.org/viewvc/logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Spaceless.php?rev=1343084&view=auto
==============================================================================
--- logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Spaceless.php (added)
+++ logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Spaceless.php Sun May 27 19:59:46 2012
@@ -0,0 +1,41 @@
+<?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 spaceless node.
+ *
+ * It removes spaces between HTML tags.
+ *
+ * @package twig
+ * @author Fabien Potencier <fa...@symfony.com>
+ */
+class Twig_Node_Spaceless extends Twig_Node
+{
+ public function __construct(Twig_NodeInterface $body, $lineno, $tag = 'spaceless')
+ {
+ parent::__construct(array('body' => $body), array(), $lineno, $tag);
+ }
+
+ /**
+ * Compiles the node to PHP.
+ *
+ * @param Twig_Compiler A Twig_Compiler instance
+ */
+ public function compile(Twig_Compiler $compiler)
+ {
+ $compiler
+ ->addDebugInfo($this)
+ ->write("ob_start();\n")
+ ->subcompile($this->getNode('body'))
+ ->write("echo trim(preg_replace('/>\s+</', '><', ob_get_clean()));\n")
+ ;
+ }
+}
Added: logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Text.php
URL: http://svn.apache.org/viewvc/logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Text.php?rev=1343084&view=auto
==============================================================================
--- logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Text.php (added)
+++ logging/site/branches/cms/trunk/libs/Twig/lib/Twig/Node/Text.php Sun May 27 19:59:46 2012
@@ -0,0 +1,40 @@
+<?php
+
+/*
+ * 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.
+ */
+
+/**
+ * Represents a text node.
+ *
+ * @package twig
+ * @author Fabien Potencier <fa...@symfony.com>
+ */
+class Twig_Node_Text extends Twig_Node implements Twig_NodeOutputInterface
+{
+ public function __construct($data, $lineno)
+ {
+ parent::__construct(array(), array('data' => $data), $lineno);
+ }
+
+ /**
+ * Compiles the node to PHP.
+ *
+ * @param Twig_Compiler A Twig_Compiler instance
+ */
+ public function compile(Twig_Compiler $compiler)
+ {
+ $compiler
+ ->addDebugInfo($this)
+ ->write('echo ')
+ ->string($this->getAttribute('data'))
+ ->raw(";\n")
+ ;
+ }
+}
Added: logging/site/branches/cms/trunk/libs/Twig/lib/Twig/NodeInterface.php
URL: http://svn.apache.org/viewvc/logging/site/branches/cms/trunk/libs/Twig/lib/Twig/NodeInterface.php?rev=1343084&view=auto
==============================================================================
--- logging/site/branches/cms/trunk/libs/Twig/lib/Twig/NodeInterface.php (added)
+++ logging/site/branches/cms/trunk/libs/Twig/lib/Twig/NodeInterface.php Sun May 27 19:59:46 2012
@@ -0,0 +1,30 @@
+<?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 <fa...@symfony.com>
+ */
+interface Twig_NodeInterface extends Countable, IteratorAggregate
+{
+ /**
+ * Compiles the node to PHP.
+ *
+ * @param Twig_Compiler A Twig_Compiler instance
+ */
+ function compile(Twig_Compiler $compiler);
+
+ function getLine();
+
+ function getNodeTag();
+}
Added: logging/site/branches/cms/trunk/libs/Twig/lib/Twig/NodeOutputInterface.php
URL: http://svn.apache.org/viewvc/logging/site/branches/cms/trunk/libs/Twig/lib/Twig/NodeOutputInterface.php?rev=1343084&view=auto
==============================================================================
--- logging/site/branches/cms/trunk/libs/Twig/lib/Twig/NodeOutputInterface.php (added)
+++ logging/site/branches/cms/trunk/libs/Twig/lib/Twig/NodeOutputInterface.php Sun May 27 19:59:46 2012
@@ -0,0 +1,20 @@
+<?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 displayable node in the AST.
+ *
+ * @package twig
+ * @author Fabien Potencier <fa...@symfony.com>
+ */
+interface Twig_NodeOutputInterface
+{
+}
Added: logging/site/branches/cms/trunk/libs/Twig/lib/Twig/NodeTraverser.php
URL: http://svn.apache.org/viewvc/logging/site/branches/cms/trunk/libs/Twig/lib/Twig/NodeTraverser.php?rev=1343084&view=auto
==============================================================================
--- logging/site/branches/cms/trunk/libs/Twig/lib/Twig/NodeTraverser.php (added)
+++ logging/site/branches/cms/trunk/libs/Twig/lib/Twig/NodeTraverser.php Sun May 27 19:59:46 2012
@@ -0,0 +1,89 @@
+<?php
+
+/*
+ * This file is part of Twig.
+ *
+ * (c) 2009 Fabien Potencier
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * Twig_NodeTraverser is a node traverser.
+ *
+ * It visits all nodes and their children and call the given visitor for each.
+ *
+ * @package twig
+ * @author Fabien Potencier <fa...@symfony.com>
+ */
+class Twig_NodeTraverser
+{
+ protected $env;
+ protected $visitors;
+
+ /**
+ * Constructor.
+ *
+ * @param Twig_Environment $env A Twig_Environment instance
+ * @param array $visitors An array of Twig_NodeVisitorInterface instances
+ */
+ public function __construct(Twig_Environment $env, array $visitors = array())
+ {
+ $this->env = $env;
+ $this->visitors = array();
+ foreach ($visitors as $visitor) {
+ $this->addVisitor($visitor);
+ }
+ }
+
+ /**
+ * Adds a visitor.
+ *
+ * @param Twig_NodeVisitorInterface $visitor A Twig_NodeVisitorInterface instance
+ */
+ public function addVisitor(Twig_NodeVisitorInterface $visitor)
+ {
+ if (!isset($this->visitors[$visitor->getPriority()])) {
+ $this->visitors[$visitor->getPriority()] = array();
+ }
+
+ $this->visitors[$visitor->getPriority()][] = $visitor;
+ }
+
+ /**
+ * Traverses a node and calls the registered visitors.
+ *
+ * @param Twig_NodeInterface $node A Twig_NodeInterface instance
+ */
+ public function traverse(Twig_NodeInterface $node)
+ {
+ ksort($this->visitors);
+ foreach ($this->visitors as $visitors) {
+ foreach ($visitors as $visitor) {
+ $node = $this->traverseForVisitor($visitor, $node);
+ }
+ }
+
+ return $node;
+ }
+
+ protected function traverseForVisitor(Twig_NodeVisitorInterface $visitor, Twig_NodeInterface $node = null)
+ {
+ if (null === $node) {
+ return null;
+ }
+
+ $node = $visitor->enterNode($node, $this->env);
+
+ foreach ($node as $k => $n) {
+ if (false !== $n = $this->traverseForVisitor($visitor, $n)) {
+ $node->setNode($k, $n);
+ } else {
+ $node->removeNode($k);
+ }
+ }
+
+ return $visitor->leaveNode($node, $this->env);
+ }
+}
Added: logging/site/branches/cms/trunk/libs/Twig/lib/Twig/NodeVisitor/Escaper.php
URL: http://svn.apache.org/viewvc/logging/site/branches/cms/trunk/libs/Twig/lib/Twig/NodeVisitor/Escaper.php?rev=1343084&view=auto
==============================================================================
--- logging/site/branches/cms/trunk/libs/Twig/lib/Twig/NodeVisitor/Escaper.php (added)
+++ logging/site/branches/cms/trunk/libs/Twig/lib/Twig/NodeVisitor/Escaper.php Sun May 27 19:59:46 2012
@@ -0,0 +1,164 @@
+<?php
+
+/*
+ * This file is part of Twig.
+ *
+ * (c) 2009 Fabien Potencier
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * Twig_NodeVisitor_Escaper implements output escaping.
+ *
+ * @package twig
+ * @author Fabien Potencier <fa...@symfony.com>
+ */
+class Twig_NodeVisitor_Escaper implements Twig_NodeVisitorInterface
+{
+ protected $statusStack = array();
+ protected $blocks = array();
+ protected $safeAnalysis;
+ protected $traverser;
+ protected $defaultStrategy = false;
+
+ public function __construct()
+ {
+ $this->safeAnalysis = new Twig_NodeVisitor_SafeAnalysis();
+ }
+
+ /**
+ * Called before child nodes are visited.
+ *
+ * @param Twig_NodeInterface $node The node to visit
+ * @param Twig_Environment $env The Twig environment instance
+ *
+ * @return Twig_NodeInterface The modified node
+ */
+ public function enterNode(Twig_NodeInterface $node, Twig_Environment $env)
+ {
+ if ($node instanceof Twig_Node_Module) {
+ if ($env->hasExtension('escaper') && $defaultStrategy = $env->getExtension('escaper')->getDefaultStrategy($node->getAttribute('filename'))) {
+ $this->defaultStrategy = $defaultStrategy;
+ }
+ } elseif ($node instanceof Twig_Node_AutoEscape) {
+ $this->statusStack[] = $node->getAttribute('value');
+ } elseif ($node instanceof Twig_Node_Block) {
+ $this->statusStack[] = isset($this->blocks[$node->getAttribute('name')]) ? $this->blocks[$node->getAttribute('name')] : $this->needEscaping($env);
+ }
+
+ return $node;
+ }
+
+ /**
+ * Called after child nodes are visited.
+ *
+ * @param Twig_NodeInterface $node The node to visit
+ * @param Twig_Environment $env The Twig environment instance
+ *
+ * @return Twig_NodeInterface The modified node
+ */
+ public function leaveNode(Twig_NodeInterface $node, Twig_Environment $env)
+ {
+ if ($node instanceof Twig_Node_Module) {
+ $this->defaultStrategy = false;
+ } elseif ($node instanceof Twig_Node_Expression_Filter) {
+ return $this->preEscapeFilterNode($node, $env);
+ } elseif ($node instanceof Twig_Node_Print) {
+ return $this->escapePrintNode($node, $env, $this->needEscaping($env));
+ }
+
+ if ($node instanceof Twig_Node_AutoEscape || $node instanceof Twig_Node_Block) {
+ array_pop($this->statusStack);
+ } elseif ($node instanceof Twig_Node_BlockReference) {
+ $this->blocks[$node->getAttribute('name')] = $this->needEscaping($env);
+ }
+
+ return $node;
+ }
+
+ protected function escapePrintNode(Twig_Node_Print $node, Twig_Environment $env, $type)
+ {
+ if (false === $type) {
+ return $node;
+ }
+
+ $expression = $node->getNode('expr');
+
+ if ($this->isSafeFor($type, $expression, $env)) {
+ return $node;
+ }
+
+ $class = get_class($node);
+
+ return new $class(
+ $this->getEscaperFilter($type, $expression),
+ $node->getLine()
+ );
+ }
+
+ protected function preEscapeFilterNode(Twig_Node_Expression_Filter $filter, Twig_Environment $env)
+ {
+ $name = $filter->getNode('filter')->getAttribute('value');
+
+ if (false !== $f = $env->getFilter($name)) {
+ $type = $f->getPreEscape();
+ if (null === $type) {
+ return $filter;
+ }
+
+ $node = $filter->getNode('node');
+ if ($this->isSafeFor($type, $node, $env)) {
+ return $filter;
+ }
+
+ $filter->setNode('node', $this->getEscaperFilter($type, $node));
+
+ return $filter;
+ }
+
+ return $filter;
+ }
+
+ protected function isSafeFor($type, Twig_NodeInterface $expression, $env)
+ {
+ $safe = $this->safeAnalysis->getSafe($expression);
+
+ if (null === $safe) {
+ if (null === $this->traverser) {
+ $this->traverser = new Twig_NodeTraverser($env, array($this->safeAnalysis));
+ }
+ $this->traverser->traverse($expression);
+ $safe = $this->safeAnalysis->getSafe($expression);
+ }
+
+ return in_array($type, $safe) || in_array('all', $safe);
+ }
+
+ protected function needEscaping(Twig_Environment $env)
+ {
+ if (count($this->statusStack)) {
+ return $this->statusStack[count($this->statusStack) - 1];
+ }
+
+ return $this->defaultStrategy ? $this->defaultStrategy : false;
+ }
+
+ protected function getEscaperFilter($type, Twig_NodeInterface $node)
+ {
+ $line = $node->getLine();
+ $name = new Twig_Node_Expression_Constant('escape', $line);
+ $args = new Twig_Node(array(new Twig_Node_Expression_Constant((string) $type, $line), new Twig_Node_Expression_Constant(null, $line), new Twig_Node_Expression_Constant(true, $line)));
+
+ return new Twig_Node_Expression_Filter($node, $name, $args, $line);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getPriority()
+ {
+ return 0;
+ }
+}