You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ih...@apache.org on 2012/05/22 16:42:31 UTC
svn commit: r1341499 [4/7] - in
/logging/site/branches/experimental-twig-textile: ./ libs/Twig/
libs/Twig/lib/ libs/Twig/lib/Twig/ libs/Twig/lib/Twig/Error/
libs/Twig/lib/Twig/Extension/ libs/Twig/lib/Twig/Filter/
libs/Twig/lib/Twig/Function/ libs/Twig...
Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Loader/Filesystem.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Loader/Filesystem.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Loader/Filesystem.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Loader/Filesystem.php Tue May 22 14:42:25 2012
@@ -0,0 +1,152 @@
+<?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.
+ */
+
+/**
+ * Loads template from the filesystem.
+ *
+ * @package twig
+ * @author Fabien Potencier <fa...@symfony.com>
+ */
+class Twig_Loader_Filesystem implements Twig_LoaderInterface
+{
+ protected $paths;
+ protected $cache;
+
+ /**
+ * Constructor.
+ *
+ * @param string|array $paths A path or an array of paths where to look for templates
+ */
+ public function __construct($paths)
+ {
+ $this->setPaths($paths);
+ }
+
+ /**
+ * Returns the paths to the templates.
+ *
+ * @return array The array of paths where to look for templates
+ */
+ public function getPaths()
+ {
+ return $this->paths;
+ }
+
+ /**
+ * Sets the paths where templates are stored.
+ *
+ * @param string|array $paths A path or an array of paths where to look for templates
+ */
+ public function setPaths($paths)
+ {
+ if (!is_array($paths)) {
+ $paths = array($paths);
+ }
+
+ $this->paths = array();
+ foreach ($paths as $path) {
+ $this->addPath($path);
+ }
+ }
+
+ /**
+ * Adds a path where templates are stored.
+ *
+ * @param string $path A path where to look for templates
+ */
+ public function addPath($path)
+ {
+ // invalidate the cache
+ $this->cache = array();
+
+ if (!is_dir($path)) {
+ throw new Twig_Error_Loader(sprintf('The "%s" directory does not exist.', $path));
+ }
+
+ $this->paths[] = $path;
+ }
+
+ /**
+ * Gets the source code of a template, given its name.
+ *
+ * @param string $name The name of the template to load
+ *
+ * @return string The template source code
+ */
+ public function getSource($name)
+ {
+ return file_get_contents($this->findTemplate($name));
+ }
+
+ /**
+ * Gets the cache key to use for the cache for a given template name.
+ *
+ * @param string $name The name of the template to load
+ *
+ * @return string The cache key
+ */
+ public function getCacheKey($name)
+ {
+ return $this->findTemplate($name);
+ }
+
+ /**
+ * Returns true if the template is still fresh.
+ *
+ * @param string $name The template name
+ * @param timestamp $time The last modification time of the cached template
+ */
+ public function isFresh($name, $time)
+ {
+ return filemtime($this->findTemplate($name)) <= $time;
+ }
+
+ protected function findTemplate($name)
+ {
+ // normalize name
+ $name = preg_replace('#/{2,}#', '/', strtr($name, '\\', '/'));
+
+ if (isset($this->cache[$name])) {
+ return $this->cache[$name];
+ }
+
+ $this->validateName($name);
+
+ foreach ($this->paths as $path) {
+ if (is_file($path.'/'.$name)) {
+ return $this->cache[$name] = $path.'/'.$name;
+ }
+ }
+
+ throw new Twig_Error_Loader(sprintf('Unable to find template "%s" (looked into: %s).', $name, implode(', ', $this->paths)));
+ }
+
+ protected function validateName($name)
+ {
+ if (false !== strpos($name, "\0")) {
+ throw new Twig_Error_Loader('A template name cannot contain NUL bytes.');
+ }
+
+ $parts = explode('/', $name);
+ $level = 0;
+ foreach ($parts as $part) {
+ if ('..' === $part) {
+ --$level;
+ } elseif ('.' !== $part) {
+ ++$level;
+ }
+
+ if ($level < 0) {
+ throw new Twig_Error_Loader(sprintf('Looks like you try to load a template outside configured directories (%s).', $name));
+ }
+ }
+ }
+}
Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Loader/String.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Loader/String.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Loader/String.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Loader/String.php Tue May 22 14:42:25 2012
@@ -0,0 +1,59 @@
+<?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.
+ */
+
+/**
+ * Loads a template from a string.
+ *
+ * When using this loader with a cache mechanism, you should know that a new cache
+ * key is generated each time a template content "changes" (the cache key being the
+ * source code of the template). If you don't want to see your cache grows out of
+ * control, you need to take care of clearing the old cache file by yourself.
+ *
+ * @package twig
+ * @author Fabien Potencier <fa...@symfony.com>
+ */
+class Twig_Loader_String implements Twig_LoaderInterface
+{
+ /**
+ * Gets the source code of a template, given its name.
+ *
+ * @param string $name The name of the template to load
+ *
+ * @return string The template source code
+ */
+ public function getSource($name)
+ {
+ return $name;
+ }
+
+ /**
+ * Gets the cache key to use for the cache for a given template name.
+ *
+ * @param string $name The name of the template to load
+ *
+ * @return string The cache key
+ */
+ public function getCacheKey($name)
+ {
+ return $name;
+ }
+
+ /**
+ * Returns true if the template is still fresh.
+ *
+ * @param string $name The template name
+ * @param timestamp $time The last modification time of the cached template
+ */
+ public function isFresh($name, $time)
+ {
+ return true;
+ }
+}
Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/LoaderInterface.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/LoaderInterface.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/LoaderInterface.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/LoaderInterface.php Tue May 22 14:42:25 2012
@@ -0,0 +1,53 @@
+<?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.
+ */
+
+/**
+ * Interface all loaders must implement.
+ *
+ * @package twig
+ * @author Fabien Potencier <fa...@symfony.com>
+ */
+interface Twig_LoaderInterface
+{
+ /**
+ * Gets the source code of a template, given its name.
+ *
+ * @param string $name The name of the template to load
+ *
+ * @return string The template source code
+ *
+ * @throws Twig_Error_Loader When $name is not found
+ */
+ function getSource($name);
+
+ /**
+ * Gets the cache key to use for the cache for a given template name.
+ *
+ * @param string $name The name of the template to load
+ *
+ * @return string The cache key
+ *
+ * @throws Twig_Error_Loader When $name is not found
+ */
+ function getCacheKey($name);
+
+ /**
+ * Returns true if the template is still fresh.
+ *
+ * @param string $name The template name
+ * @param timestamp $time The last modification time of the cached template
+ *
+ * @return Boolean true if the template is fresh, false otherwise
+ *
+ * @throws Twig_Error_Loader When $name is not found
+ */
+ function isFresh($name, $time);
+}
Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Markup.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Markup.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Markup.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Markup.php Tue May 22 14:42:25 2012
@@ -0,0 +1,38 @@
+<?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.
+ */
+
+/**
+ * Marks a content as safe.
+ *
+ * @package twig
+ * @author Fabien Potencier <fa...@symfony.com>
+ */
+class Twig_Markup implements Countable
+{
+ protected $content;
+ protected $charset;
+
+ public function __construct($content, $charset)
+ {
+ $this->content = (string) $content;
+ $this->charset = $charset;
+ }
+
+ public function __toString()
+ {
+ return $this->content;
+ }
+
+ public function count()
+ {
+ return function_exists('mb_get_info') ? mb_strlen($this->content, $this->charset) : strlen($this->content);
+ }
+}
Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node.php Tue May 22 14:42:25 2012
@@ -0,0 +1,227 @@
+<?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 in the AST.
+ *
+ * @package twig
+ * @author Fabien Potencier <fa...@symfony.com>
+ */
+class Twig_Node implements Twig_NodeInterface
+{
+ protected $nodes;
+ protected $attributes;
+ protected $lineno;
+ protected $tag;
+
+ /**
+ * Constructor.
+ *
+ * The nodes are automatically made available as properties ($this->node).
+ * The attributes are automatically made available as array items ($this['name']).
+ *
+ * @param array $nodes An array of named nodes
+ * @param array $attributes An array of attributes (should not be nodes)
+ * @param integer $lineno The line number
+ * @param string $tag The tag name associated with the Node
+ */
+ public function __construct(array $nodes = array(), array $attributes = array(), $lineno = 0, $tag = null)
+ {
+ $this->nodes = $nodes;
+ $this->attributes = $attributes;
+ $this->lineno = $lineno;
+ $this->tag = $tag;
+ }
+
+ public function __toString()
+ {
+ $attributes = array();
+ foreach ($this->attributes as $name => $value) {
+ $attributes[] = sprintf('%s: %s', $name, str_replace("\n", '', var_export($value, true)));
+ }
+
+ $repr = array(get_class($this).'('.implode(', ', $attributes));
+
+ if (count($this->nodes)) {
+ foreach ($this->nodes as $name => $node) {
+ $len = strlen($name) + 4;
+ $noderepr = array();
+ foreach (explode("\n", (string) $node) as $line) {
+ $noderepr[] = str_repeat(' ', $len).$line;
+ }
+
+ $repr[] = sprintf(' %s: %s', $name, ltrim(implode("\n", $noderepr)));
+ }
+
+ $repr[] = ')';
+ } else {
+ $repr[0] .= ')';
+ }
+
+ return implode("\n", $repr);
+ }
+
+ public function toXml($asDom = false)
+ {
+ $dom = new DOMDocument('1.0', 'UTF-8');
+ $dom->formatOutput = true;
+ $dom->appendChild($xml = $dom->createElement('twig'));
+
+ $xml->appendChild($node = $dom->createElement('node'));
+ $node->setAttribute('class', get_class($this));
+
+ foreach ($this->attributes as $name => $value) {
+ $node->appendChild($attribute = $dom->createElement('attribute'));
+ $attribute->setAttribute('name', $name);
+ $attribute->appendChild($dom->createTextNode($value));
+ }
+
+ foreach ($this->nodes as $name => $n) {
+ if (null === $n) {
+ continue;
+ }
+
+ $child = $n->toXml(true)->getElementsByTagName('node')->item(0);
+ $child = $dom->importNode($child, true);
+ $child->setAttribute('name', $name);
+
+ $node->appendChild($child);
+ }
+
+ return $asDom ? $dom : $dom->saveXml();
+ }
+
+ public function compile(Twig_Compiler $compiler)
+ {
+ foreach ($this->nodes as $node) {
+ $node->compile($compiler);
+ }
+ }
+
+ public function getLine()
+ {
+ return $this->lineno;
+ }
+
+ public function getNodeTag()
+ {
+ return $this->tag;
+ }
+
+ /**
+ * Returns true if the attribute is defined.
+ *
+ * @param string The attribute name
+ *
+ * @return Boolean true if the attribute is defined, false otherwise
+ */
+ public function hasAttribute($name)
+ {
+ return array_key_exists($name, $this->attributes);
+ }
+
+ /**
+ * Gets an attribute.
+ *
+ * @param string The attribute name
+ *
+ * @return mixed The attribute value
+ */
+ public function getAttribute($name)
+ {
+ if (!array_key_exists($name, $this->attributes)) {
+ throw new Twig_Error_Runtime(sprintf('Attribute "%s" does not exist for Node "%s".', $name, get_class($this)));
+ }
+
+ return $this->attributes[$name];
+ }
+
+ /**
+ * Sets an attribute.
+ *
+ * @param string The attribute name
+ * @param mixed The attribute value
+ */
+ public function setAttribute($name, $value)
+ {
+ $this->attributes[$name] = $value;
+ }
+
+ /**
+ * Removes an attribute.
+ *
+ * @param string The attribute name
+ */
+ public function removeAttribute($name)
+ {
+ unset($this->attributes[$name]);
+ }
+
+ /**
+ * Returns true if the node with the given identifier exists.
+ *
+ * @param string The node name
+ *
+ * @return Boolean true if the node with the given name exists, false otherwise
+ */
+ public function hasNode($name)
+ {
+ return array_key_exists($name, $this->nodes);
+ }
+
+ /**
+ * Gets a node by name.
+ *
+ * @param string The node name
+ *
+ * @return Twig_Node A Twig_Node instance
+ */
+ public function getNode($name)
+ {
+ if (!array_key_exists($name, $this->nodes)) {
+ throw new Twig_Error_Runtime(sprintf('Node "%s" does not exist for Node "%s".', $name, get_class($this)));
+ }
+
+ return $this->nodes[$name];
+ }
+
+ /**
+ * Sets a node.
+ *
+ * @param string The node name
+ * @param Twig_Node A Twig_Node instance
+ */
+ public function setNode($name, $node = null)
+ {
+ $this->nodes[$name] = $node;
+ }
+
+ /**
+ * Removes a node by name.
+ *
+ * @param string The node name
+ */
+ public function removeNode($name)
+ {
+ unset($this->nodes[$name]);
+ }
+
+ public function count()
+ {
+ return count($this->nodes);
+ }
+
+ public function getIterator()
+ {
+ return new ArrayIterator($this->nodes);
+ }
+}
Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/AutoEscape.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/AutoEscape.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/AutoEscape.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/AutoEscape.php Tue May 22 14:42:25 2012
@@ -0,0 +1,40 @@
+<?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 autoescape node.
+ *
+ * The value is the escaping strategy (can be html, js, ...)
+ *
+ * The true value is equivalent to html.
+ *
+ * If autoescaping is disabled, then the value is false.
+ *
+ * @package twig
+ * @author Fabien Potencier <fa...@symfony.com>
+ */
+class Twig_Node_AutoEscape extends Twig_Node
+{
+ public function __construct($value, Twig_NodeInterface $body, $lineno, $tag = 'autoescape')
+ {
+ parent::__construct(array('body' => $body), array('value' => $value), $lineno, $tag);
+ }
+
+ /**
+ * Compiles the node to PHP.
+ *
+ * @param Twig_Compiler A Twig_Compiler instance
+ */
+ public function compile(Twig_Compiler $compiler)
+ {
+ $compiler->subcompile($this->getNode('body'));
+ }
+}
Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Block.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Block.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Block.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Block.php Tue May 22 14:42:25 2012
@@ -0,0 +1,45 @@
+<?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 block node.
+ *
+ * @package twig
+ * @author Fabien Potencier <fa...@symfony.com>
+ */
+class Twig_Node_Block extends Twig_Node
+{
+ public function __construct($name, Twig_NodeInterface $body, $lineno, $tag = null)
+ {
+ parent::__construct(array('body' => $body), array('name' => $name), $lineno, $tag);
+ }
+
+ /**
+ * Compiles the node to PHP.
+ *
+ * @param Twig_Compiler A Twig_Compiler instance
+ */
+ public function compile(Twig_Compiler $compiler)
+ {
+ $compiler
+ ->addDebugInfo($this)
+ ->write(sprintf("public function block_%s(\$context, array \$blocks = array())\n", $this->getAttribute('name')), "{\n")
+ ->indent()
+ ;
+
+ $compiler
+ ->subcompile($this->getNode('body'))
+ ->outdent()
+ ->write("}\n\n")
+ ;
+ }
+}
Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/BlockReference.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/BlockReference.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/BlockReference.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/BlockReference.php Tue May 22 14:42:25 2012
@@ -0,0 +1,38 @@
+<?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 block call node.
+ *
+ * @package twig
+ * @author Fabien Potencier <fa...@symfony.com>
+ */
+class Twig_Node_BlockReference extends Twig_Node implements Twig_NodeOutputInterface
+{
+ public function __construct($name, $lineno, $tag = null)
+ {
+ parent::__construct(array(), array('name' => $name), $lineno, $tag);
+ }
+
+ /**
+ * Compiles the node to PHP.
+ *
+ * @param Twig_Compiler A Twig_Compiler instance
+ */
+ public function compile(Twig_Compiler $compiler)
+ {
+ $compiler
+ ->addDebugInfo($this)
+ ->write(sprintf("\$this->displayBlock('%s', \$context, \$blocks);\n", $this->getAttribute('name')))
+ ;
+ }
+}
Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Body.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Body.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Body.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Body.php Tue May 22 14:42:25 2012
@@ -0,0 +1,20 @@
+<?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 body node.
+ *
+ * @package twig
+ * @author Fabien Potencier <fa...@symfony.com>
+ */
+class Twig_Node_Body extends Twig_Node
+{
+}
Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Do.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Do.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Do.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Do.php Tue May 22 14:42:25 2012
@@ -0,0 +1,39 @@
+<?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 do node.
+ *
+ * @package twig
+ * @author Fabien Potencier <fa...@symfony.com>
+ */
+class Twig_Node_Do extends Twig_Node
+{
+ 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('')
+ ->subcompile($this->getNode('expr'))
+ ->raw(";\n")
+ ;
+ }
+}
Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Embed.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Embed.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Embed.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Embed.php Tue May 22 14:42:25 2012
@@ -0,0 +1,39 @@
+<?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.
+ */
+
+/**
+ * Represents an embed node.
+ *
+ * @package twig
+ * @author Fabien Potencier <fa...@symfony.com>
+ */
+class Twig_Node_Embed extends Twig_Node_Include
+{
+ // we don't inject the module to avoid node visitors to traverse it twice (as it will be already visited in the main module)
+ public function __construct($filename, $index, Twig_Node_Expression $variables = null, $only = false, $ignoreMissing = false, $lineno, $tag = null)
+ {
+ parent::__construct(new Twig_Node_Expression_Constant('not_used', $lineno), $variables, $only, $ignoreMissing, $lineno, $tag);
+
+ $this->setAttribute('filename', $filename);
+ $this->setAttribute('index', $index);
+ }
+
+ protected function addGetTemplate(Twig_Compiler $compiler)
+ {
+ $compiler
+ ->write("\$this->env->loadTemplate(")
+ ->string($this->getAttribute('filename'))
+ ->raw(', ')
+ ->string($this->getAttribute('index'))
+ ->raw(")")
+ ;
+ }
+}
Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression.php Tue May 22 14:42:25 2012
@@ -0,0 +1,21 @@
+<?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 for all nodes that represents an expression.
+ *
+ * @package twig
+ * @author Fabien Potencier <fa...@symfony.com>
+ */
+abstract class Twig_Node_Expression extends Twig_Node
+{
+}
Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Array.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Array.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Array.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Array.php Tue May 22 14:42:25 2012
@@ -0,0 +1,86 @@
+<?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.
+ */
+class Twig_Node_Expression_Array extends Twig_Node_Expression
+{
+ protected $index;
+
+ public function __construct(array $elements, $lineno)
+ {
+ parent::__construct($elements, array(), $lineno);
+
+ $this->index = -1;
+ foreach ($this->getKeyValuePairs() as $pair) {
+ if ($pair['key'] instanceof Twig_Node_Expression_Constant && ctype_digit((string) $pair['key']->getAttribute('value')) && $pair['key']->getAttribute('value') > $this->index) {
+ $this->index = $pair['key']->getAttribute('value');
+ }
+ }
+ }
+
+ public function getKeyValuePairs()
+ {
+ $pairs = array();
+
+ foreach (array_chunk($this->nodes, 2) as $pair) {
+ $pairs[] = array(
+ 'key' => $pair[0],
+ 'value' => $pair[1],
+ );
+ }
+
+ return $pairs;
+ }
+
+ public function hasElement(Twig_Node_Expression $key)
+ {
+ foreach ($this->getKeyValuePairs() as $pair) {
+ // we compare the string representation of the keys
+ // to avoid comparing the line numbers which are not relevant here.
+ if ((string) $key == (string) $pair['key']) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public function addElement(Twig_Node_Expression $value, Twig_Node_Expression $key = null)
+ {
+ if (null === $key) {
+ $key = new Twig_Node_Expression_Constant(++$this->index, $value->getLine());
+ }
+
+ array_push($this->nodes, $key, $value);
+ }
+
+ /**
+ * Compiles the node to PHP.
+ *
+ * @param Twig_Compiler A Twig_Compiler instance
+ */
+ public function compile(Twig_Compiler $compiler)
+ {
+ $compiler->raw('array(');
+ $first = true;
+ foreach ($this->getKeyValuePairs() as $pair) {
+ if (!$first) {
+ $compiler->raw(', ');
+ }
+ $first = false;
+
+ $compiler
+ ->subcompile($pair['key'])
+ ->raw(' => ')
+ ->subcompile($pair['value'])
+ ;
+ }
+ $compiler->raw(')');
+ }
+}
Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/AssignName.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/AssignName.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/AssignName.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/AssignName.php Tue May 22 14:42:25 2012
@@ -0,0 +1,28 @@
+<?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_AssignName extends Twig_Node_Expression_Name
+{
+ /**
+ * Compiles the node to PHP.
+ *
+ * @param Twig_Compiler A Twig_Compiler instance
+ */
+ public function compile(Twig_Compiler $compiler)
+ {
+ $compiler
+ ->raw('$context[')
+ ->string($this->getAttribute('name'))
+ ->raw(']')
+ ;
+ }
+}
Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary.php Tue May 22 14:42:25 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.
+ */
+abstract class Twig_Node_Expression_Binary extends Twig_Node_Expression
+{
+ public function __construct(Twig_NodeInterface $left, Twig_NodeInterface $right, $lineno)
+ {
+ parent::__construct(array('left' => $left, 'right' => $right), array(), $lineno);
+ }
+
+ /**
+ * Compiles the node to PHP.
+ *
+ * @param Twig_Compiler A Twig_Compiler instance
+ */
+ public function compile(Twig_Compiler $compiler)
+ {
+ $compiler
+ ->raw('(')
+ ->subcompile($this->getNode('left'))
+ ->raw(' ')
+ ;
+ $this->operator($compiler);
+ $compiler
+ ->raw(' ')
+ ->subcompile($this->getNode('right'))
+ ->raw(')')
+ ;
+ }
+
+ abstract public function operator(Twig_Compiler $compiler);
+}
Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Add.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Add.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Add.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Add.php Tue May 22 14:42:25 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_Binary_Add extends Twig_Node_Expression_Binary
+{
+ public function operator(Twig_Compiler $compiler)
+ {
+ return $compiler->raw('+');
+ }
+}
Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/And.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/And.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/And.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/And.php Tue May 22 14:42:25 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_Binary_And extends Twig_Node_Expression_Binary
+{
+ public function operator(Twig_Compiler $compiler)
+ {
+ return $compiler->raw('&&');
+ }
+}
Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/BitwiseAnd.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/BitwiseAnd.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/BitwiseAnd.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/BitwiseAnd.php Tue May 22 14:42:25 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_Binary_BitwiseAnd extends Twig_Node_Expression_Binary
+{
+ public function operator(Twig_Compiler $compiler)
+ {
+ return $compiler->raw('&');
+ }
+}
Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/BitwiseOr.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/BitwiseOr.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/BitwiseOr.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/BitwiseOr.php Tue May 22 14:42:25 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_Binary_BitwiseOr extends Twig_Node_Expression_Binary
+{
+ public function operator(Twig_Compiler $compiler)
+ {
+ return $compiler->raw('|');
+ }
+}
Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/BitwiseXor.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/BitwiseXor.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/BitwiseXor.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/BitwiseXor.php Tue May 22 14:42:25 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_Binary_BitwiseXor extends Twig_Node_Expression_Binary
+{
+ public function operator(Twig_Compiler $compiler)
+ {
+ return $compiler->raw('^');
+ }
+}
Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Concat.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Concat.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Concat.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Concat.php Tue May 22 14:42:25 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_Binary_Concat extends Twig_Node_Expression_Binary
+{
+ public function operator(Twig_Compiler $compiler)
+ {
+ return $compiler->raw('.');
+ }
+}
Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Div.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Div.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Div.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Div.php Tue May 22 14:42:25 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_Binary_Div extends Twig_Node_Expression_Binary
+{
+ public function operator(Twig_Compiler $compiler)
+ {
+ return $compiler->raw('/');
+ }
+}
Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Equal.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Equal.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Equal.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Equal.php Tue May 22 14:42:25 2012
@@ -0,0 +1,17 @@
+<?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_Binary_Equal extends Twig_Node_Expression_Binary
+{
+ public function operator(Twig_Compiler $compiler)
+ {
+ return $compiler->raw('==');
+ }
+}
Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/FloorDiv.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/FloorDiv.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/FloorDiv.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/FloorDiv.php Tue May 22 14:42:25 2012
@@ -0,0 +1,29 @@
+<?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.
+ */
+class Twig_Node_Expression_Binary_FloorDiv extends Twig_Node_Expression_Binary
+{
+ /**
+ * Compiles the node to PHP.
+ *
+ * @param Twig_Compiler A Twig_Compiler instance
+ */
+ public function compile(Twig_Compiler $compiler)
+ {
+ $compiler->raw('intval(floor(');
+ parent::compile($compiler);
+ $compiler->raw('))');
+ }
+
+ public function operator(Twig_Compiler $compiler)
+ {
+ return $compiler->raw('/');
+ }
+}
Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Greater.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Greater.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Greater.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Greater.php Tue May 22 14:42:25 2012
@@ -0,0 +1,17 @@
+<?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_Binary_Greater extends Twig_Node_Expression_Binary
+{
+ public function operator(Twig_Compiler $compiler)
+ {
+ return $compiler->raw('>');
+ }
+}
Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/GreaterEqual.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/GreaterEqual.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/GreaterEqual.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/GreaterEqual.php Tue May 22 14:42:25 2012
@@ -0,0 +1,17 @@
+<?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_Binary_GreaterEqual extends Twig_Node_Expression_Binary
+{
+ public function operator(Twig_Compiler $compiler)
+ {
+ return $compiler->raw('>=');
+ }
+}
Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/In.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/In.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/In.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/In.php Tue May 22 14:42:25 2012
@@ -0,0 +1,33 @@
+<?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_Binary_In extends Twig_Node_Expression_Binary
+{
+ /**
+ * Compiles the node to PHP.
+ *
+ * @param Twig_Compiler A Twig_Compiler instance
+ */
+ public function compile(Twig_Compiler $compiler)
+ {
+ $compiler
+ ->raw('twig_in_filter(')
+ ->subcompile($this->getNode('left'))
+ ->raw(', ')
+ ->subcompile($this->getNode('right'))
+ ->raw(')')
+ ;
+ }
+
+ public function operator(Twig_Compiler $compiler)
+ {
+ return $compiler->raw('in');
+ }
+}
Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Less.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Less.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Less.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Less.php Tue May 22 14:42:25 2012
@@ -0,0 +1,17 @@
+<?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_Binary_Less extends Twig_Node_Expression_Binary
+{
+ public function operator(Twig_Compiler $compiler)
+ {
+ return $compiler->raw('<');
+ }
+}
Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/LessEqual.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/LessEqual.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/LessEqual.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/LessEqual.php Tue May 22 14:42:25 2012
@@ -0,0 +1,17 @@
+<?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_Binary_LessEqual extends Twig_Node_Expression_Binary
+{
+ public function operator(Twig_Compiler $compiler)
+ {
+ return $compiler->raw('<=');
+ }
+}
Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Mod.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Mod.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Mod.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Mod.php Tue May 22 14:42:25 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_Binary_Mod extends Twig_Node_Expression_Binary
+{
+ public function operator(Twig_Compiler $compiler)
+ {
+ return $compiler->raw('%');
+ }
+}
Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Mul.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Mul.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Mul.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Mul.php Tue May 22 14:42:25 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_Binary_Mul extends Twig_Node_Expression_Binary
+{
+ public function operator(Twig_Compiler $compiler)
+ {
+ return $compiler->raw('*');
+ }
+}
Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/NotEqual.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/NotEqual.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/NotEqual.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/NotEqual.php Tue May 22 14:42:25 2012
@@ -0,0 +1,17 @@
+<?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_Binary_NotEqual extends Twig_Node_Expression_Binary
+{
+ public function operator(Twig_Compiler $compiler)
+ {
+ return $compiler->raw('!=');
+ }
+}
Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/NotIn.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/NotIn.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/NotIn.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/NotIn.php Tue May 22 14:42:25 2012
@@ -0,0 +1,33 @@
+<?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_Binary_NotIn extends Twig_Node_Expression_Binary
+{
+ /**
+ * Compiles the node to PHP.
+ *
+ * @param Twig_Compiler A Twig_Compiler instance
+ */
+ public function compile(Twig_Compiler $compiler)
+ {
+ $compiler
+ ->raw('!twig_in_filter(')
+ ->subcompile($this->getNode('left'))
+ ->raw(', ')
+ ->subcompile($this->getNode('right'))
+ ->raw(')')
+ ;
+ }
+
+ public function operator(Twig_Compiler $compiler)
+ {
+ return $compiler->raw('not in');
+ }
+}
Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Or.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Or.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Or.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Or.php Tue May 22 14:42:25 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_Binary_Or extends Twig_Node_Expression_Binary
+{
+ public function operator(Twig_Compiler $compiler)
+ {
+ return $compiler->raw('||');
+ }
+}
Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Power.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Power.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Power.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Power.php Tue May 22 14:42:25 2012
@@ -0,0 +1,33 @@
+<?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_Binary_Power extends Twig_Node_Expression_Binary
+{
+ /**
+ * Compiles the node to PHP.
+ *
+ * @param Twig_Compiler A Twig_Compiler instance
+ */
+ public function compile(Twig_Compiler $compiler)
+ {
+ $compiler
+ ->raw('pow(')
+ ->subcompile($this->getNode('left'))
+ ->raw(', ')
+ ->subcompile($this->getNode('right'))
+ ->raw(')')
+ ;
+ }
+
+ public function operator(Twig_Compiler $compiler)
+ {
+ return $compiler->raw('**');
+ }
+}
Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Range.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Range.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Range.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Range.php Tue May 22 14:42:25 2012
@@ -0,0 +1,33 @@
+<?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_Binary_Range extends Twig_Node_Expression_Binary
+{
+ /**
+ * Compiles the node to PHP.
+ *
+ * @param Twig_Compiler A Twig_Compiler instance
+ */
+ public function compile(Twig_Compiler $compiler)
+ {
+ $compiler
+ ->raw('range(')
+ ->subcompile($this->getNode('left'))
+ ->raw(', ')
+ ->subcompile($this->getNode('right'))
+ ->raw(')')
+ ;
+ }
+
+ public function operator(Twig_Compiler $compiler)
+ {
+ return $compiler->raw('..');
+ }
+}
Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Sub.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Sub.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Sub.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Binary/Sub.php Tue May 22 14:42:25 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_Binary_Sub extends Twig_Node_Expression_Binary
+{
+ public function operator(Twig_Compiler $compiler)
+ {
+ return $compiler->raw('-');
+ }
+}
Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/BlockReference.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/BlockReference.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/BlockReference.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/BlockReference.php Tue May 22 14:42:25 2012
@@ -0,0 +1,52 @@
+<?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 block call node.
+ *
+ * @package twig
+ * @author Fabien Potencier <fa...@symfony.com>
+ */
+class Twig_Node_Expression_BlockReference extends Twig_Node_Expression
+{
+ public function __construct(Twig_NodeInterface $name, $asString = false, $lineno, $tag = null)
+ {
+ parent::__construct(array('name' => $name), array('as_string' => $asString, 'output' => false), $lineno, $tag);
+ }
+
+ /**
+ * Compiles the node to PHP.
+ *
+ * @param Twig_Compiler A Twig_Compiler instance
+ */
+ public function compile(Twig_Compiler $compiler)
+ {
+ if ($this->getAttribute('as_string')) {
+ $compiler->raw('(string) ');
+ }
+
+ if ($this->getAttribute('output')) {
+ $compiler
+ ->addDebugInfo($this)
+ ->write("\$this->displayBlock(")
+ ->subcompile($this->getNode('name'))
+ ->raw(", \$context, \$blocks);\n")
+ ;
+ } else {
+ $compiler
+ ->raw("\$this->renderBlock(")
+ ->subcompile($this->getNode('name'))
+ ->raw(", \$context, \$blocks)")
+ ;
+ }
+ }
+}
Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Conditional.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Conditional.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Conditional.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Conditional.php Tue May 22 14:42:25 2012
@@ -0,0 +1,31 @@
+<?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_Conditional extends Twig_Node_Expression
+{
+ public function __construct(Twig_Node_Expression $expr1, Twig_Node_Expression $expr2, Twig_Node_Expression $expr3, $lineno)
+ {
+ parent::__construct(array('expr1' => $expr1, 'expr2' => $expr2, 'expr3' => $expr3), array(), $lineno);
+ }
+
+ public function compile(Twig_Compiler $compiler)
+ {
+ $compiler
+ ->raw('((')
+ ->subcompile($this->getNode('expr1'))
+ ->raw(') ? (')
+ ->subcompile($this->getNode('expr2'))
+ ->raw(') : (')
+ ->subcompile($this->getNode('expr3'))
+ ->raw('))')
+ ;
+ }
+}
Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Constant.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Constant.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Constant.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Constant.php Tue May 22 14:42:25 2012
@@ -0,0 +1,23 @@
+<?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_Constant extends Twig_Node_Expression
+{
+ public function __construct($value, $lineno)
+ {
+ parent::__construct(array(), array('value' => $value), $lineno);
+ }
+
+ public function compile(Twig_Compiler $compiler)
+ {
+ $compiler->repr($this->getAttribute('value'));
+ }
+}
Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/ExtensionReference.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/ExtensionReference.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/ExtensionReference.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/ExtensionReference.php Tue May 22 14:42:25 2012
@@ -0,0 +1,34 @@
+<?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 extension call node.
+ *
+ * @package twig
+ * @author Fabien Potencier <fa...@symfony.com>
+ */
+class Twig_Node_Expression_ExtensionReference extends Twig_Node_Expression
+{
+ public function __construct($name, $lineno, $tag = null)
+ {
+ parent::__construct(array(), array('name' => $name), $lineno, $tag);
+ }
+
+ /**
+ * Compiles the node to PHP.
+ *
+ * @param Twig_Compiler A Twig_Compiler instance
+ */
+ public function compile(Twig_Compiler $compiler)
+ {
+ $compiler->raw(sprintf("\$this->env->getExtension('%s')", $this->getAttribute('name')));
+ }
+}
Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Filter.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Filter.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Filter.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Filter.php Tue May 22 14:42:25 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.
+ */
+class Twig_Node_Expression_Filter extends Twig_Node_Expression
+{
+ public function __construct(Twig_NodeInterface $node, Twig_Node_Expression_Constant $filterName, Twig_NodeInterface $arguments, $lineno, $tag = null)
+ {
+ parent::__construct(array('node' => $node, 'filter' => $filterName, 'arguments' => $arguments), array(), $lineno, $tag);
+ }
+
+ public function compile(Twig_Compiler $compiler)
+ {
+ $name = $this->getNode('filter')->getAttribute('value');
+
+ if (false === $filter = $compiler->getEnvironment()->getFilter($name)) {
+ $message = sprintf('The filter "%s" does not exist', $name);
+ if ($alternatives = $compiler->getEnvironment()->computeAlternatives($name, array_keys($compiler->getEnvironment()->getFilters()))) {
+ $message = sprintf('%s. Did you mean "%s"', $message, implode('", "', $alternatives));
+ }
+
+ throw new Twig_Error_Syntax($message, $this->getLine());
+ }
+
+ $this->compileFilter($compiler, $filter);
+ }
+
+ protected function compileFilter(Twig_Compiler $compiler, Twig_FilterInterface $filter)
+ {
+ $compiler
+ ->raw($filter->compile().'(')
+ ->raw($filter->needsEnvironment() ? '$this->env, ' : '')
+ ->raw($filter->needsContext() ? '$context, ' : '')
+ ;
+
+ foreach ($filter->getArguments() as $argument) {
+ $compiler
+ ->string($argument)
+ ->raw(', ')
+ ;
+ }
+
+ $compiler->subcompile($this->getNode('node'));
+
+ foreach ($this->getNode('arguments') as $node) {
+ $compiler
+ ->raw(', ')
+ ->subcompile($node)
+ ;
+ }
+
+ $compiler->raw(')');
+ }
+}
Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Filter/Default.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Filter/Default.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Filter/Default.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Filter/Default.php Tue May 22 14:42:25 2012
@@ -0,0 +1,44 @@
+<?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.
+ */
+
+/**
+ * Returns the value or the default value when it is undefined or empty.
+ *
+ * <pre>
+ * {{ var.foo|default('foo item on var is not defined') }}
+ * </pre>
+ *
+ * @package twig
+ * @author Fabien Potencier <fa...@symfony.com>
+ */
+class Twig_Node_Expression_Filter_Default extends Twig_Node_Expression_Filter
+{
+ public function __construct(Twig_NodeInterface $node, Twig_Node_Expression_Constant $filterName, Twig_NodeInterface $arguments, $lineno, $tag = null)
+ {
+ $default = new Twig_Node_Expression_Filter($node, new Twig_Node_Expression_Constant('_default', $node->getLine()), $arguments, $node->getLine());
+
+ if ('default' === $filterName->getAttribute('value') && ($node instanceof Twig_Node_Expression_Name || $node instanceof Twig_Node_Expression_GetAttr)) {
+ $test = new Twig_Node_Expression_Test_Defined(clone $node, 'defined', new Twig_Node(), $node->getLine());
+ $false = count($arguments) ? $arguments->getNode(0) : new Twig_Node_Expression_Constant('', $node->getLine());
+
+ $node = new Twig_Node_Expression_Conditional($test, $default, $false, $node->getLine());
+ } else {
+ $node = $default;
+ }
+
+ parent::__construct($node, $filterName, $arguments, $lineno, $tag);
+ }
+
+ public function compile(Twig_Compiler $compiler)
+ {
+ $compiler->subcompile($this->getNode('node'));
+ }
+}
Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Function.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Function.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Function.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Function.php Tue May 22 14:42:25 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/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/GetAttr.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/GetAttr.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/GetAttr.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/GetAttr.php Tue May 22 14:42:25 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/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/MethodCall.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/MethodCall.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/MethodCall.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/MethodCall.php Tue May 22 14:42:25 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/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Name.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Name.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Name.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Name.php Tue May 22 14:42:25 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/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Parent.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Parent.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Parent.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Parent.php Tue May 22 14:42:25 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/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/TempName.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/TempName.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/TempName.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/TempName.php Tue May 22 14:42:25 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/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Test.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Test.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Test.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Test.php Tue May 22 14:42:25 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/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Test/Constant.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Test/Constant.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Test/Constant.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Test/Constant.php Tue May 22 14:42:25 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/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Test/Defined.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Test/Defined.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Test/Defined.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Test/Defined.php Tue May 22 14:42:25 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/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Test/Divisibleby.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Test/Divisibleby.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Test/Divisibleby.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/Node/Expression/Test/Divisibleby.php Tue May 22 14:42:25 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(')')
+ ;
+ }
+}