Commit 028f5301 authored by webchick's avatar webchick

Issue #2472961 by lussoluca: Update Twig to latest stable

parent 167b32c8
......@@ -17,7 +17,7 @@
"symfony/validator": "2.6.*",
"symfony/process": "2.6.*",
"symfony/yaml": "2.6.*",
"twig/twig": "1.16.*",
"twig/twig": "1.18.*",
"doctrine/common": "~2.4.2",
"doctrine/annotations": "1.2.*",
"guzzlehttp/guzzle": "~5.0",
......
......@@ -4,7 +4,7 @@
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "17d7b4a789169d1156ff398b5889b1a2",
"hash": "8f0a2765121612251cd2967473bb66e0",
"packages": [
{
"name": "behat/mink",
......@@ -2850,16 +2850,16 @@
},
{
"name": "twig/twig",
"version": "v1.16.2",
"version": "v1.18.0",
"source": {
"type": "git",
"url": "https://github.com/fabpot/Twig.git",
"reference": "42f758d9fe2146d1f0470604fc05ee43580873fc"
"url": "https://github.com/twigphp/Twig.git",
"reference": "4cf7464348e7f9893a93f7096a90b73722be99cf"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/fabpot/Twig/zipball/42f758d9fe2146d1f0470604fc05ee43580873fc",
"reference": "42f758d9fe2146d1f0470604fc05ee43580873fc",
"url": "https://api.github.com/repos/twigphp/Twig/zipball/4cf7464348e7f9893a93f7096a90b73722be99cf",
"reference": "4cf7464348e7f9893a93f7096a90b73722be99cf",
"shasum": ""
},
"require": {
......@@ -2868,7 +2868,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.16-dev"
"dev-master": "1.18-dev"
}
},
"autoload": {
......@@ -2894,7 +2894,7 @@
},
{
"name": "Twig Team",
"homepage": "https://github.com/fabpot/Twig/graphs/contributors",
"homepage": "http://twig.sensiolabs.org/contributors",
"role": "Contributors"
}
],
......@@ -2903,7 +2903,7 @@
"keywords": [
"templating"
],
"time": "2014-10-17 12:53:44"
"time": "2015-01-25 17:32:08"
},
{
"name": "zendframework/zend-escaper",
......
......@@ -1159,65 +1159,6 @@
"routing"
]
},
{
"name": "twig/twig",
"version": "v1.16.2",
"version_normalized": "1.16.2.0",
"source": {
"type": "git",
"url": "https://github.com/fabpot/Twig.git",
"reference": "42f758d9fe2146d1f0470604fc05ee43580873fc"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/fabpot/Twig/zipball/42f758d9fe2146d1f0470604fc05ee43580873fc",
"reference": "42f758d9fe2146d1f0470604fc05ee43580873fc",
"shasum": ""
},
"require": {
"php": ">=5.2.4"
},
"time": "2014-10-17 12:53:44",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.16-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-0": {
"Twig_": "lib/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com",
"homepage": "http://fabien.potencier.org",
"role": "Lead Developer"
},
{
"name": "Armin Ronacher",
"email": "armin.ronacher@active-4.com",
"role": "Project Founder"
},
{
"name": "Twig Team",
"homepage": "https://github.com/fabpot/Twig/graphs/contributors",
"role": "Contributors"
}
],
"description": "Twig, the flexible, fast, and secure template language for PHP",
"homepage": "http://twig.sensiolabs.org",
"keywords": [
"templating"
]
},
{
"name": "egulias/email-validator",
"version": "1.2.5",
......@@ -3156,5 +3097,64 @@
"feed",
"zf2"
]
},
{
"name": "twig/twig",
"version": "v1.18.0",
"version_normalized": "1.18.0.0",
"source": {
"type": "git",
"url": "https://github.com/twigphp/Twig.git",
"reference": "4cf7464348e7f9893a93f7096a90b73722be99cf"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/twigphp/Twig/zipball/4cf7464348e7f9893a93f7096a90b73722be99cf",
"reference": "4cf7464348e7f9893a93f7096a90b73722be99cf",
"shasum": ""
},
"require": {
"php": ">=5.2.4"
},
"time": "2015-01-25 17:32:08",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.18-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-0": {
"Twig_": "lib/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com",
"homepage": "http://fabien.potencier.org",
"role": "Lead Developer"
},
{
"name": "Armin Ronacher",
"email": "armin.ronacher@active-4.com",
"role": "Project Founder"
},
{
"name": "Twig Team",
"homepage": "http://twig.sensiolabs.org/contributors",
"role": "Contributors"
}
],
"description": "Twig, the flexible, fast, and secure template language for PHP",
"homepage": "http://twig.sensiolabs.org",
"keywords": [
"templating"
]
}
]
/build
/composer.lock
/ext/twig/autom4te.cache/
/phpunit.xml
/vendor
* 1.18.0 (2015-XX-XX)
* fixed some error messages where the line was wrong (unknown variables or argument names)
* added a new way to customize the main Module node (via empty nodes)
* added Twig_Environment::createTemplate() to create a template from a string
* added a profiler
* fixed filesystem loader cache when different file paths are used for the same template
* 1.17.0 (2015-01-14)
* added a 'filename' autoescaping strategy, which dynamically chooses the
autoescaping strategy for a template based on template file extension.
* 1.16.3 (2014-12-25)
* fixed regression for dynamic parent templates
* fixed cache management with statcache
* fixed a regression in the slice filter
* 1.16.2 (2014-10-17)
* fixed timezone on dates as strings
......
......@@ -14,7 +14,7 @@
},
{
"name": "Twig Team",
"homepage": "https://github.com/fabpot/Twig/graphs/contributors",
"homepage": "http://twig.sensiolabs.org/contributors",
"role": "Contributors"
},
{
......@@ -36,7 +36,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "1.16-dev"
"dev-master": "1.18-dev"
}
}
}
......@@ -281,7 +281,7 @@ Tests allow you to create custom application specific logic for evaluating
boolean conditions. As a simple example, let's create a Twig test that checks if
objects are 'red'::
$twig = new Twig_Environment($loader)
$twig = new Twig_Environment($loader);
$test = new Twig_SimpleTest('red', function ($value) {
if (isset($value->color) && $value->color == 'red') {
return true;
......@@ -299,7 +299,7 @@ When creating tests you can use the ``node_class`` option to provide custom test
compilation. This is useful if your test can be compiled into PHP primitives.
This is used by many of the tests built into Twig::
$twig = new Twig_Environment($loader)
$twig = new Twig_Environment($loader);
$test = new Twig_SimpleTest(
'odd',
null,
......@@ -503,7 +503,7 @@ to host all the specific tags and filters you want to add to Twig.
.. note::
Before writing your own extensions, have a look at the Twig official
extension repository: http://github.com/fabpot/Twig-extensions.
extension repository: http://github.com/twigphp/Twig-extensions.
An extension is a class that implements the following interface::
......@@ -830,5 +830,5 @@ Testing the node visitors can be complex, so extend your test cases from
.. _`spl_autoload_register()`: http://www.php.net/spl_autoload_register
.. _`rot13`: http://www.php.net/manual/en/function.str-rot13.php
.. _`tests/Twig/Fixtures`: https://github.com/fabpot/Twig/tree/master/test/Twig/Tests/Fixtures
.. _`tests/Twig/Node`: https://github.com/fabpot/Twig/tree/master/test/Twig/Tests/Node
.. _`tests/Twig/Fixtures`: https://github.com/twigphp/Twig/tree/master/test/Twig/Tests/Fixtures
.. _`tests/Twig/Node`: https://github.com/twigphp/Twig/tree/master/test/Twig/Tests/Node
......@@ -529,7 +529,7 @@ to host all the specific tags and filters you want to add to Twig.
.. note::
Before writing your own extensions, have a look at the Twig official
extension repository: http://github.com/fabpot/Twig-extensions.
extension repository: http://github.com/twigphp/Twig-extensions.
An extension is a class that implements the following interface::
......@@ -883,5 +883,5 @@ Testing the node visitors can be complex, so extend your test cases from
.. _`spl_autoload_register()`: http://www.php.net/spl_autoload_register
.. _`rot13`: http://www.php.net/manual/en/function.str-rot13.php
.. _`tests/Twig/Fixtures`: https://github.com/fabpot/Twig/tree/master/test/Twig/Tests/Fixtures
.. _`tests/Twig/Node`: https://github.com/fabpot/Twig/tree/master/test/Twig/Tests/Node
.. _`tests/Twig/Fixtures`: https://github.com/twigphp/Twig/tree/master/test/Twig/Tests/Fixtures
.. _`tests/Twig/Node`: https://github.com/twigphp/Twig/tree/master/test/Twig/Tests/Node
......@@ -94,14 +94,20 @@ The following options are available:
replace them with a ``null`` value. When set to ``true``, Twig throws an
exception instead (default to ``false``).
* ``autoescape``: If set to ``true``, auto-escaping will be enabled by default
for all templates (default to ``true``). As of Twig 1.8, you can set the
escaping strategy to use (``html``, ``js``, ``false`` to disable).
As of Twig 1.9, you can set the escaping strategy to use (``css``, ``url``,
``html_attr``, or a PHP callback that takes the template "filename" and must
* ``autoescape``: If set to ``true``, HTML auto-escaping will be enabled by
default for all templates (default to ``true``).
As of Twig 1.8, you can set the escaping strategy to use (``html``, ``js``,
``false`` to disable).
As of Twig 1.9, you can set the escaping strategy to use (``css``, ``url``,
``html_attr``, or a PHP callback that takes the template "filename" and must
return the escaping strategy to use -- the callback cannot be a function name
to avoid collision with built-in escaping strategies).
As of Twig 1.17, the ``filename`` escaping strategy determines the escaping
strategy to use for a template based on the template filename extension.
* ``optimizations``: A flag that indicates which optimizations to apply
(default to ``-1`` -- all optimizations are enabled; set it to ``0`` to
disable).
......@@ -279,6 +285,9 @@ Twig comes bundled with the following extensions:
* *Twig_Extension_Sandbox*: Adds a sandbox mode to the default Twig
environment, making it safe to evaluate untrusted code.
* *Twig_Extension_Profiler*: Enabled the built-in Twig profiler (as of Twig
1.18).
* *Twig_Extension_Optimizer*: Optimizes the node tree before compilation.
The core, escaper, and optimizer extensions do not need to be added to the
......@@ -447,6 +456,37 @@ the extension constructor::
$sandbox = new Twig_Extension_Sandbox($policy, true);
Profiler Extension
~~~~~~~~~~~~~~~~~~
.. versionadded:: 1.18
The Profile extension was added in Twig 1.18.
The ``profiler`` extension enables a profiler for Twig templates; it should
only be used on your development machines as it adds some overhead::
$profile = new Twig_Profiler_Profile();
$twig->addExtension(new Twig_Extension_Profiler($profile));
$dumper = new Twig_Profiler_Dumper_Text();
echo $dumper->dump($profile);
A profile contains information about time and memory consumption for template,
block, and macro executions.
You can also dump the data in a `Blackfire.io <https://blackfire.io/>`_
compatible format::
$dumper = new Twig_Profiler_Dumper_Blackfire();
file_put_contents('/path/to/profile.prof', $dumper->dump($profile));
Upload the profile to visualize it (create a `free account
<https://blackfire.io/signup>`_ first):
.. code-block:: sh
blackfire --slot=7 upload /path/to/profile.prof
Optimizer Extension
~~~~~~~~~~~~~~~~~~~
......
......@@ -5,7 +5,7 @@
The ``batch`` filter was added in Twig 1.12.3.
The ``batch`` filter "batches" items by returning a list of lists with the
given number of items. If you provide a second parameter, it is used to fill
given number of items. A second parameter can be provided and used to fill in
missing items:
.. code-block:: jinja
......
......@@ -20,10 +20,9 @@ Filters
last
length
lower
merge
nl2br
number_format
merge
upper
raw
replace
reverse
......@@ -34,4 +33,5 @@ Filters
striptags
title
trim
upper
url_encode
......@@ -32,7 +32,7 @@ As syntactic sugar, you can also use the ``[]`` notation:
{# ... #}
{% endfor %}
{{ '12345'[1:2] }}
{{ '12345'[1:2] }} {# will display "23" #}
{# you can omit the first argument -- which is the same as 0 #}
{{ '12345'[:2] }} {# will display "12" #}
......
......@@ -28,7 +28,7 @@ Installing the development version
.. code-block:: bash
git clone git://github.com/fabpot/Twig.git
git clone git://github.com/twigphp/Twig.git
Installing the PEAR package
~~~~~~~~~~~~~~~~~~~~~~~~~~~
......@@ -107,7 +107,7 @@ advantage of the C extension. Note that this extension does not replace the
PHP code but only provides an optimized version of the
``Twig_Template::getAttribute()`` method.
.. _`download page`: https://github.com/fabpot/Twig/tags
.. _`Composer`: https://getcomposer.org/download/
.. _`download page`: https://github.com/twigphp/Twig/tags
.. _`Composer`: https://getcomposer.org/download/
.. _`PHP documentation`: https://wiki.php.net/internals/windows/stepbystepbuild
.. _`Zend Server FAQ`: http://www.zend.com/en/products/server/faq#faqD6
.. _`Zend Server FAQ`: http://www.zend.com/en/products/server/faq#faqD6
......@@ -50,9 +50,9 @@ This section gives you a brief introduction to the PHP API for Twig.
require_once '/path/to/vendor/autoload.php';
$loader = new Twig_Loader_Array(
$loader = new Twig_Loader_Array(array(
'index' => 'Hello {{ name }}!',
);
));
$twig = new Twig_Environment($loader);
echo $twig->render('index', array('name' => 'Fabien'));
......
......@@ -29,6 +29,14 @@ You can also test if an array is not empty:
If you want to test if the variable is defined, use ``if users is
defined`` instead.
You can also use ``not`` to check for values that evaluate to ``false``:
.. code-block:: jinja
{% if not user.subscribed %}
<p>You are not subscribed to our mailing list.</p>
{% endif %}
For multiple branches ``elseif`` and ``else`` can be used like in PHP. You can use
more complex ``expressions`` there too:
......
......@@ -6,10 +6,10 @@ Tags
autoescape
block
filter
do
embed
extends
filter
flush
for
from
......
......@@ -866,7 +866,7 @@ Extension<creating_extensions>` chapter.
.. _`Twig syntax plugin`: http://plugins.netbeans.org/plugin/37069/php-twig
.. _`Twig plugin`: https://github.com/pulse00/Twig-Eclipse-Plugin
.. _`Twig language definition`: https://github.com/gabrielcorpse/gedit-twig-template-language
.. _`extension repository`: http://github.com/fabpot/Twig-extensions
.. _`extension repository`: http://github.com/twigphp/Twig-extensions
.. _`Twig syntax mode`: https://github.com/bobthecow/Twig-HTML.mode
.. _`other Twig syntax mode`: https://github.com/muxx/Twig-HTML.mode
.. _`Notepad++ Twig Highlighter`: https://github.com/Banane9/notepadplusplus-twig
......
......@@ -15,7 +15,7 @@
#ifndef PHP_TWIG_H
#define PHP_TWIG_H
#define PHP_TWIG_VERSION "1.16.2"
#define PHP_TWIG_VERSION "1.18.0"
#include "php.h"
......
......@@ -19,7 +19,7 @@ class Twig_Autoloader
/**
* Registers Twig_Autoloader as an SPL autoloader.
*
* @param bool $prepend Whether to prepend the autoloader or not.
* @param bool $prepend Whether to prepend the autoloader or not.
*/
public static function register($prepend = false)
{
......
......@@ -231,13 +231,15 @@ public function addDebugInfo(Twig_NodeInterface $node)
public function getDebugInfo()
{
ksort($this->debugInfo);
return $this->debugInfo;
}
/**
* Indents the generated code.
*
* @param int $step The number of indentation to add
* @param int $step The number of indentation to add
*
* @return Twig_Compiler The current compiler instance
*/
......@@ -251,7 +253,7 @@ public function indent($step = 1)
/**
* Outdents the generated code.
*
* @param int $step The number of indentation to remove
* @param int $step The number of indentation to remove
*
* @return Twig_Compiler The current compiler instance
*
......
......@@ -16,7 +16,7 @@
*/
class Twig_Environment
{
const VERSION = '1.16.2';
const VERSION = '1.18.0';
protected $charset;
protected $loader;
......@@ -72,6 +72,7 @@ class Twig_Environment
* * false: disable auto-escaping
* * true: equivalent to html
* * html, js: set the autoescaping to one of the supported strategies
* * filename: set the autoescaping strategy based on the template filename extension
* * PHP callback: a PHP callback that returns an escaping strategy based on the template "filename"
*
* * optimizations: A flag that indicates which optimizations to apply
......@@ -154,7 +155,7 @@ public function disableDebug()
/**
* Checks if debug mode is enabled.
*
* @return bool true if debug mode is enabled, false otherwise
* @return bool true if debug mode is enabled, false otherwise
*/
public function isDebug()
{
......@@ -180,7 +181,7 @@ public function disableAutoReload()
/**
* Checks if the auto_reload option is enabled.
*
* @return bool true if auto_reload is enabled, false otherwise
* @return bool true if auto_reload is enabled, false otherwise
*/
public function isAutoReload()
{
......@@ -206,7 +207,7 @@ public function disableStrictVariables()
/**
* Checks if the strict_variables option is enabled.
*
* @return bool true if strict_variables is enabled, false otherwise
* @return bool true if strict_variables is enabled, false otherwise
*/
public function isStrictVariables()
{
......@@ -223,12 +224,12 @@ public function getCache()
return $this->cache;
}
/**
* Sets the cache directory or false if cache is disabled.
*
* @param string|false $cache The absolute path to the compiled templates,
* or false to disable cache
*/
/**
* Sets the cache directory or false if cache is disabled.
*
* @param string|false $cache The absolute path to the compiled templates,
* or false to disable cache
*/
public function setCache($cache)
{
$this->cache = $cache ? $cache : false;
......@@ -255,8 +256,8 @@ public function getCacheFilename($name)
/**
* Gets the template class associated with the given string.
*
* @param string $name The name for which to calculate the template class name
* @param int $index The index if it is an embedded template
* @param string $name The name for which to calculate the template class name
* @param int $index The index if it is an embedded template
*
* @return string The template class name
*/
......@@ -310,8 +311,8 @@ public function display($name, array $context = array())
/**
* Loads a template by name.
*
* @param string $name The template name
* @param int $index The index if it is an embedded template
* @param string $name The template name
* @param int $index The index if it is an embedded template
*
* @return Twig_TemplateInterface A template instance representing the given template name
*
......@@ -345,6 +346,41 @@ public function loadTemplate($name, $index = null)
return $this->loadedTemplates[$cls] = new $cls($this);
}