Commit 8043f5cf authored by webchick's avatar webchick

Issue #2550299 by mpdonadio, neclimdul: Update to Twig 1.20

parent b16b01df
......@@ -18,7 +18,7 @@
"symfony/validator": "2.7.*",
"symfony/process": "2.7.*",
"symfony/yaml": "2.7.*",
"twig/twig": "1.18.*",
"twig/twig": "1.20.*",
"doctrine/common": "~2.4.2",
"doctrine/annotations": "1.2.*",
"guzzlehttp/guzzle": "dev-master#1879fbe853b0c64d109e369c7aeff09849e62d1e",
......
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "3708d8fdb54957e5ce661cda1df88353",
"hash": "6d065bd806544df5f446905bc3d6379f",
"packages": [
{
"name": "behat/mink",
......@@ -796,7 +796,7 @@
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/1879fbe853b0c64d109e369c7aeff09849e62d1e",
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/e4046d42e6abc055c16d47bfbae573ae4c8646d1",
"reference": "1879fbe853b0c64d109e369c7aeff09849e62d1e",
"shasum": ""
},
......@@ -3111,16 +3111,16 @@
},
{
"name": "twig/twig",
"version": "v1.18.1",
"version": "v1.20.0",
"source": {
"type": "git",
"url": "https://github.com/twigphp/Twig.git",
"reference": "9f70492f44398e276d1b81c1b43adfe6751c7b7f"
"reference": "1ea4e5f81c6d005fe84d0b38e1c4f1955eb86844"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/twigphp/Twig/zipball/9f70492f44398e276d1b81c1b43adfe6751c7b7f",
"reference": "9f70492f44398e276d1b81c1b43adfe6751c7b7f",
"url": "https://api.github.com/repos/twigphp/Twig/zipball/1ea4e5f81c6d005fe84d0b38e1c4f1955eb86844",
"reference": "1ea4e5f81c6d005fe84d0b38e1c4f1955eb86844",
"shasum": ""
},
"require": {
......@@ -3129,7 +3129,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.18-dev"
"dev-master": "1.20-dev"
}
},
"autoload": {
......@@ -3164,7 +3164,7 @@
"keywords": [
"templating"
],
"time": "2015-04-19 08:30:27"
"time": "2015-08-12 15:56:39"
},
{
"name": "zendframework/zend-diactoros",
......
......@@ -351,7 +351,7 @@ private function findFileWithExtension($class, $ext)
foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) {
if (0 === strpos($class, $prefix)) {
foreach ($this->prefixDirsPsr4[$prefix] as $dir) {
if (is_file($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) {
return $file;
}
}
......@@ -361,7 +361,7 @@ private function findFileWithExtension($class, $ext)
// PSR-4 fallback dirs
foreach ($this->fallbackDirsPsr4 as $dir) {
if (is_file($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
return $file;
}
}
......@@ -380,7 +380,7 @@ private function findFileWithExtension($class, $ext)
foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
if (0 === strpos($class, $prefix)) {
foreach ($dirs as $dir) {
if (is_file($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
return $file;
}
}
......@@ -390,7 +390,7 @@ private function findFileWithExtension($class, $ext)
// PSR-0 fallback dirs
foreach ($this->fallbackDirsPsr0 as $dir) {
if (is_file($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
return $file;
}
}
......
......@@ -1107,65 +1107,6 @@
"zf2"
]
},
{
"name": "twig/twig",
"version": "v1.18.1",
"version_normalized": "1.18.1.0",
"source": {
"type": "git",
"url": "https://github.com/twigphp/Twig.git",
"reference": "9f70492f44398e276d1b81c1b43adfe6751c7b7f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/twigphp/Twig/zipball/9f70492f44398e276d1b81c1b43adfe6751c7b7f",
"reference": "9f70492f44398e276d1b81c1b43adfe6751c7b7f",
"shasum": ""
},
"require": {
"php": ">=5.2.7"
},
"time": "2015-04-19 08:30:27",
"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"
]
},
{
"name": "sebastian/version",
"version": "1.0.5",
......@@ -3265,7 +3206,7 @@
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/1879fbe853b0c64d109e369c7aeff09849e62d1e",
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/e4046d42e6abc055c16d47bfbae573ae4c8646d1",
"reference": "1879fbe853b0c64d109e369c7aeff09849e62d1e",
"shasum": ""
},
......@@ -3477,5 +3418,64 @@
"validation",
"validator"
]
},
{
"name": "twig/twig",
"version": "v1.20.0",
"version_normalized": "1.20.0.0",
"source": {
"type": "git",
"url": "https://github.com/twigphp/Twig.git",
"reference": "1ea4e5f81c6d005fe84d0b38e1c4f1955eb86844"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/twigphp/Twig/zipball/1ea4e5f81c6d005fe84d0b38e1c4f1955eb86844",
"reference": "1ea4e5f81c6d005fe84d0b38e1c4f1955eb86844",
"shasum": ""
},
"require": {
"php": ">=5.2.7"
},
"time": "2015-08-12 15:56:39",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.20-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"
]
}
]
......@@ -8,11 +8,9 @@ php:
- 5.6
- hhvm
- nightly
- hhvm-nightly
allow_failures:
- php: nightly
- php: hhvm-nightly
env:
- TWIG_EXT=no
......@@ -26,7 +24,5 @@ matrix:
exclude:
- php: hhvm
env: TWIG_EXT=yes
- php: hhvm-nightly
env: TWIG_EXT=yes
- php: nightly
env: TWIG_EXT=yes
* 1.20.0 (2015-08-12)
* forbid access to the Twig environment from templates and internal parts of Twig_Template
* fixed limited RCEs when in sandbox mode
* deprecated Twig_Template::getEnvironment()
* deprecated the _self variable for usage outside of the from and import tags
* added Twig_BaseNodeVisitor to ease the compatibility of node visitors
between 1.x and 2.x
* 1.19.0 (2015-07-31)
* fixed wrong error message when including an undefined template in a child template
* added support for variadic filters, functions, and tests
* added support for extra positional arguments in macros
* added ignore_missing flag to the source function
* fixed batch filter with zero items
* deprecated Twig_Environment::clearTemplateCache()
* fixed sandbox disabling when using the include function
* 1.18.2 (2015-06-06)
* fixed template/line guessing in exceptions for nested templates
* optimized the number of inodes and the size of realpath cache when using the cache
* 1.18.1 (2015-04-19)
* fixed memory leaks in the C extension
......
......@@ -36,7 +36,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "1.18-dev"
"dev-master": "1.20-dev"
}
}
}
......@@ -224,6 +224,23 @@ through your filter::
$filter = new Twig_SimpleFilter('somefilter', 'somefilter', array('pre_escape' => 'html', 'is_safe' => array('html')));
Variadic Filters
~~~~~~~~~~~~~~~~
.. versionadded:: 1.19
Support for variadic filters was added in Twig 1.19.
When a filter should accept an arbitrary number of arguments, set the
``is_variadic`` option to ``true``; Twig will pass the extra arguments as the
last argument to the filter call as an array::
$filter = new Twig_SimpleFilter('thumbnail', function ($file, array $options = array()) {
// ...
}, array('is_variadic' => true));
Be warned that named arguments passed to a variadic filter cannot be checked
for validity as they will automatically end up in the option array.
Dynamic Filters
~~~~~~~~~~~~~~~
......@@ -331,6 +348,10 @@ The ``node`` sub-node will contain an expression of ``my_value``. Node-based
tests also have access to the ``arguments`` node. This node will contain the
various other arguments that have been provided to your test.
If you want to pass a variable number of positional or named arguments to the
test, set the ``is_variadic`` option to ``true``. Tests also support dynamic
name feature as filters and functions.
Tags
----
......
......@@ -72,29 +72,43 @@ options as the constructor second argument::
The following options are available:
* ``debug``: When set to ``true``, the generated templates have a
* ``debug`` *boolean*
When set to ``true``, the generated templates have a
``__toString()`` method that you can use to display the generated nodes
(default to ``false``).
* ``charset``: The charset used by the templates (default to ``utf-8``).
* ``charset`` *string (default to ``utf-8``)*
The charset used by the templates.
* ``base_template_class`` *string (default to ``Twig_Template``)*
The base template class to use for generated
templates.
* ``base_template_class``: The base template class to use for generated
templates (default to ``Twig_Template``).
* ``cache`` *string|false*
* ``cache``: An absolute path where to store the compiled templates, or
An absolute path where to store the compiled templates, or
``false`` to disable caching (which is the default).
* ``auto_reload``: When developing with Twig, it's useful to recompile the
* ``auto_reload`` *boolean*
When developing with Twig, it's useful to recompile the
template whenever the source code changes. If you don't provide a value for
the ``auto_reload`` option, it will be determined automatically based on the
``debug`` value.
* ``strict_variables``: If set to ``false``, Twig will silently ignore invalid
* ``strict_variables`` *boolean*
If set to ``false``, Twig will silently ignore invalid
variables (variables and or attributes/methods that do not exist) and
replace them with a ``null`` value. When set to ``true``, Twig throws an
exception instead (default to ``false``).
* ``autoescape``: If set to ``true``, HTML auto-escaping will be enabled by
* ``autoescape`` *string|boolean*
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``,
......@@ -110,7 +124,9 @@ The following options are available:
strategy does not incur any overhead at runtime as auto-escaping is done at
compilation time.)
* ``optimizations``: A flag that indicates which optimizations to apply
* ``optimizations`` *integer*
A flag that indicates which optimizations to apply
(default to ``-1`` -- all optimizations are enabled; set it to ``0`` to
disable).
......
......@@ -107,9 +107,30 @@ Loaders
* As of Twig 1.x, ``Twig_Loader_String`` is deprecated and will be removed in
2.0.
Node Visitors
-------------
* Because of the removal of ``Twig_NodeInterface`` in 2.0, you need to extend
``Twig_BaseNodeVistor`` instead of implementing ``Twig_NodeVisitorInterface``
directly to make your node visitors compatible with both Twig 1.x and 2.x.
Globals
-------
* As of Twig 2.x, the ability to register a global variable after the runtime
or the extensions have been initialized is not possible anymore (but
changing the value of an already registered global is possible).
* As of Twig 1.x, the ``_self`` global variable is deprecated except for usage
in the ``from`` and the ``import`` tags. In Twig 2.0, ``_self`` is not
exposed anymore but still usable in the ``from`` and the ``import`` tags.
Miscellaneous
-------------
* As of Twig 1.x, ``Twig_Environment::clearTemplateCache()`` is deprecated and
will be removed in 2.0.
* As of Twig 1.x, ``Twig_Template::getEnvironment()`` and
``Twig_TemplateInterface::getEnvironment()`` are deprecated and will be
removed in 2.0.
......@@ -43,3 +43,9 @@ The above example will be rendered as:
<td>No item</td>
</tr>
</table>
Arguments
---------
* ``size``: The size of the batch; fractional numbers will be rounded up
* ``fill``: Used to fill in missing items
......@@ -4,6 +4,9 @@
.. versionadded:: 1.15
The ``source`` function was added in Twig 1.15.
.. versionadded:: 1.18.3
The ``ignore_missing`` flag was added in Twig 1.18.3.
The ``source`` function returns the content of a template without rendering it:
.. code-block:: jinja
......@@ -11,6 +14,13 @@ The ``source`` function returns the content of a template without rendering it:
{{ source('template.html') }}
{{ source(some_var) }}
When you set the ``ignore_missing`` flag, Twig will return an empty string if
the template does not exist:
.. code-block:: jinja
{{ source('template.html', ignore_missing = true) }}
The function uses the same template loaders as the ones used to include
templates. So, if you are using the filesystem loader, the templates are looked
for in the paths defined by it.
......@@ -19,3 +29,4 @@ Arguments
---------
* ``name``: The name of the template to read
* ``ignore_missing``: Whether to ignore missing templates or not
......@@ -124,7 +124,7 @@ using)::
{
// line 1
echo "Hello ";
echo twig_escape_filter($this->env, $this->getContext($context, "name"), "html", null, true);
echo twig_escape_filter($this->env, isset($context["name"]) ? $context["name"] : null), "html", null, true);
}
// some more code
......
......@@ -21,10 +21,14 @@ The key-features are...
* *Flexible*: Twig is powered by a flexible lexer and parser. This allows the
developer to define its own custom tags and filters, and create its own DSL.
Twig is used by many Open-Source projects like Symfony, Drupal8, eZPublish,
phpBB, Piwik, OroCRM, and many frameworks have support for it as well like
Slim, Yii, Laravel, Codeigniter, and Kohana, just to name a few.
Prerequisites
-------------
Twig needs at least **PHP 5.2.4** to run.
Twig needs at least **PHP 5.2.7** to run.
Installation
------------
......
......@@ -37,8 +37,16 @@ You can also use ``not`` to check for values that evaluate to ``false``:
<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:
For multiple conditions, ``and`` and ``or`` can be used:
.. code-block:: jinja
{% if temperature > 18 and temperature < 27 %}
<p>It's a nice day for a walk in the park.</p>
{% endif %}
For multiple branches ``elseif`` and ``else`` can be used like in PHP. You can
use more complex ``expressions`` there too:
.. code-block:: jinja
......
......@@ -20,6 +20,9 @@ Macros differs from native PHP functions in a few ways:
* Arguments of a macro are always optional.
* If extra positional arguments are passed to a macro, they end up in the
special ``varargs`` variable as a list of values.
But as with PHP functions, macros don't have access to the current template
variables.
......
......@@ -33,5 +33,5 @@ quirks under some circumstances.
.. tip::
For more information on whitespace control, read the
:doc:`dedicated<../templates>` section of the documentation and learn how
:ref:`dedicated section <templates-whitespace-control>` of the documentation and learn how
you can also use the whitespace control modifier on your tags.
......@@ -74,7 +74,7 @@ is ignored. To avoid name conflicts, you can rename imported blocks:
{% extends "base.html" %}
{% use "blocks.html" with sidebar as base_sidebar %}
{% use "blocks.html" with sidebar as base_sidebar, title as base_title %}
{% block sidebar %}{% endblock %}
{% block title %}{% endblock %}
......
......@@ -93,7 +93,7 @@ access the variable attribute:
don't put the braces around them.
If a variable or attribute does not exist, you will receive a ``null`` value
when the ``strict_variables`` option is set to ``false``; alternatively, if ``strict_variables``
when the ``strict_variables`` option is set to ``false``; alternatively, if ``strict_variables``
is set, Twig will throw an error (see :ref:`environment options<environment_options>`).
.. sidebar:: Implementation
......@@ -124,7 +124,7 @@ Global Variables
The following variables are always available in templates:
* ``_self``: references the current template;
* ``_self``: references the current template (deprecated since Twig 1.20);
* ``_context``: references the current context;
* ``_charset``: references the current charset.
......@@ -541,6 +541,9 @@ macro call:
<input type="{{ type }}" name="{{ name }}" value="{{ value|e }}" size="{{ size }}" />
{% endmacro %}
If extra positional arguments are passed to a macro call, they end up in the
special ``varargs`` variable as a list of values.
.. _twig-expressions:
Expressions
......@@ -669,6 +672,10 @@ You can combine multiple expressions with the following operators:
Twig also support bitwise operators (``b-and``, ``b-xor``, and ``b-or``).
.. note::
Operators are case sensitive.
Comparisons
~~~~~~~~~~~
......@@ -801,6 +808,8 @@ inserted into the string:
{{ "foo #{bar} baz" }}
{{ "foo #{1 + 2} baz" }}
.. _templates-whitespace-control:
Whitespace Control
------------------
......
......@@ -15,7 +15,7 @@
#ifndef PHP_TWIG_H
#define PHP_TWIG_H
#define PHP_TWIG_VERSION "1.18.1"
#define PHP_TWIG_VERSION "1.20.0"
#include "php.h"
......
......@@ -55,7 +55,7 @@ ZEND_BEGIN_ARG_INFO_EX(twig_template_get_attribute_args, ZEND_SEND_BY_VAL, ZEND_
ZEND_END_ARG_INFO()
#ifndef PHP_FE_END
#define PHP_FE_END { NULL, NULL, NULL, 0, 0 }
#define PHP_FE_END { NULL, NULL, NULL}
#endif
static const zend_function_entry twig_functions[] = {
......@@ -609,6 +609,7 @@ static char *TWIG_GET_CLASS_NAME(zval *object TSRMLS_DC)
static int twig_add_method_to_class(void *pDest APPLY_TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key)