diff --git a/core/composer.json b/core/composer.json index 75b45b9..2452f70 100644 --- a/core/composer.json +++ b/core/composer.json @@ -18,7 +18,7 @@ "symfony/validator": "2.7.*", "symfony/process": "2.7.*", "symfony/yaml": "2.7.*", - "twig/twig": "~1.20", + "twig/twig": "~2.0", "doctrine/common": "2.5.*", "doctrine/annotations": "1.2.*", "guzzlehttp/guzzle": "dev-master#1879fbe853b0c64d109e369c7aeff09849e62d1e", diff --git a/core/composer.lock b/core/composer.lock index 98265d4..8cc7dc5 100644 --- a/core/composer.lock +++ b/core/composer.lock @@ -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": "d39a311bc4d6e7db527d6a43a8ac34d4", + "hash": "a5eb0072b1150c0bb1a639ebec3a0c3c", "packages": [ { "name": "behat/mink", @@ -794,7 +794,7 @@ }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/33af93ab4b5e76df7a4c774910590f814a3e576c", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/4771e34b9e9dbadb393da39f61ec29dadb8979b2", "reference": "1879fbe853b0c64d109e369c7aeff09849e62d1e", "shasum": "" }, @@ -3103,20 +3103,20 @@ }, { "name": "twig/twig", - "version": "v1.21.1", + "version": "dev-master", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "ca8d3aa90b6a01c82e07909fe815d6b443e75a23" + "reference": "6c107c513a4c173ca2e34049266774ac244446b8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/ca8d3aa90b6a01c82e07909fe815d6b443e75a23", - "reference": "ca8d3aa90b6a01c82e07909fe815d6b443e75a23", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/6c107c513a4c173ca2e34049266774ac244446b8", + "reference": "6c107c513a4c173ca2e34049266774ac244446b8", "shasum": "" }, "require": { - "php": ">=5.2.7" + "php": ">=5.5.0" }, "require-dev": { "symfony/debug": "~2.7", @@ -3125,7 +3125,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.21-dev" + "dev-master": "2.0-dev" } }, "autoload": { @@ -3160,7 +3160,7 @@ "keywords": [ "templating" ], - "time": "2015-08-26 08:58:31" + "time": "2015-09-06 06:50:29" }, { "name": "zendframework/zend-diactoros", diff --git a/core/lib/Drupal/Core/Template/Loader/ThemeRegistryLoader.php b/core/lib/Drupal/Core/Template/Loader/ThemeRegistryLoader.php index fe1ae25..7f74cb0 100644 --- a/core/lib/Drupal/Core/Template/Loader/ThemeRegistryLoader.php +++ b/core/lib/Drupal/Core/Template/Loader/ThemeRegistryLoader.php @@ -38,6 +38,8 @@ public function __construct(Registry $theme_registry) { * * @param string $name * The name of the template to load. + * @param bool $throw + * Whether to throw an exception when an error occurs * * @return string * The path to the template. @@ -45,7 +47,7 @@ public function __construct(Registry $theme_registry) { * @throws \Twig_Error_Loader * Thrown if a template matching $name cannot be found. */ - protected function findTemplate($name) { + protected function findTemplate($name, $throw = TRUE) { // Allow for loading based on the Drupal theme registry. $hook = str_replace('.html.twig', '', strtr($name, '-', '_')); $theme_registry = $this->themeRegistry->getRuntime(); @@ -63,7 +65,9 @@ protected function findTemplate($name) { } } - throw new \Twig_Error_Loader(sprintf('Unable to find template "%s" in the Drupal theme registry.', $name)); + if ($throw) { + throw new \Twig_Error_Loader(sprintf('Unable to find template "%s" in the Drupal theme registry.', $name)); + } } } diff --git a/core/lib/Drupal/Core/Template/TwigNodeVisitor.php b/core/lib/Drupal/Core/Template/TwigNodeVisitor.php index ac1e676..860cc56 100644 --- a/core/lib/Drupal/Core/Template/TwigNodeVisitor.php +++ b/core/lib/Drupal/Core/Template/TwigNodeVisitor.php @@ -16,19 +16,19 @@ * * @see twig_render */ -class TwigNodeVisitor implements \Twig_NodeVisitorInterface { +class TwigNodeVisitor extends \Twig_BaseNodeVisitor { /** * {@inheritdoc} */ - public function enterNode(\Twig_NodeInterface $node, \Twig_Environment $env) { + protected function doEnterNode(\Twig_Node $node, \Twig_Environment $env) { return $node; } /** * {@inheritdoc} */ - public function leaveNode(\Twig_NodeInterface $node, \Twig_Environment $env) { + protected function doLeaveNode(\Twig_Node $node, \Twig_Environment $env) { // We use this to inject a call to render_var -> TwigExtension->renderVar() // before anything is printed. if ($node instanceof \Twig_Node_Print) { diff --git a/core/vendor/composer/installed.json b/core/vendor/composer/installed.json index 94733ab..ac66c66 100644 --- a/core/vendor/composer/installed.json +++ b/core/vendor/composer/installed.json @@ -592,7 +592,7 @@ }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/33af93ab4b5e76df7a4c774910590f814a3e576c", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/4771e34b9e9dbadb393da39f61ec29dadb8979b2", "reference": "1879fbe853b0c64d109e369c7aeff09849e62d1e", "shasum": "" }, @@ -2764,69 +2764,6 @@ ] }, { - "name": "twig/twig", - "version": "v1.21.1", - "version_normalized": "1.21.1.0", - "source": { - "type": "git", - "url": "https://github.com/twigphp/Twig.git", - "reference": "ca8d3aa90b6a01c82e07909fe815d6b443e75a23" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/ca8d3aa90b6a01c82e07909fe815d6b443e75a23", - "reference": "ca8d3aa90b6a01c82e07909fe815d6b443e75a23", - "shasum": "" - }, - "require": { - "php": ">=5.2.7" - }, - "require-dev": { - "symfony/debug": "~2.7", - "symfony/phpunit-bridge": "~2.7" - }, - "time": "2015-08-26 08:58:31", - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.21-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": "fabpot/goutte", "version": "v3.1.1", "version_normalized": "3.1.1.0", @@ -3483,5 +3420,68 @@ "serializer", "xml" ] + }, + { + "name": "twig/twig", + "version": "dev-master", + "version_normalized": "9999999-dev", + "source": { + "type": "git", + "url": "https://github.com/twigphp/Twig.git", + "reference": "6c107c513a4c173ca2e34049266774ac244446b8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/6c107c513a4c173ca2e34049266774ac244446b8", + "reference": "6c107c513a4c173ca2e34049266774ac244446b8", + "shasum": "" + }, + "require": { + "php": ">=5.5.0" + }, + "require-dev": { + "symfony/debug": "~2.7", + "symfony/phpunit-bridge": "~2.7" + }, + "time": "2015-09-06 06:50:29", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-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" + ] } ] diff --git a/core/vendor/twig/twig/.travis.yml b/core/vendor/twig/twig/.travis.yml index 37262da..b3effbc 100644 --- a/core/vendor/twig/twig/.travis.yml +++ b/core/vendor/twig/twig/.travis.yml @@ -8,9 +8,6 @@ cache: - $HOME/.composer/cache php: - - 5.2 - - 5.3 - - 5.4 - 5.5 - 5.6 - 7.0 @@ -21,13 +18,11 @@ env: - TWIG_EXT=yes install: - # Composer is not available on PHP 5.2 - - if [ ${TRAVIS_PHP_VERSION:0:3} != "5.2" ]; then travis_retry composer install; fi + - travis_retry composer install before_script: - if [ "$TWIG_EXT" == "yes" ]; then sh -c "cd ext/twig && phpize && ./configure --enable-twig && make && make install"; fi - if [ "$TWIG_EXT" == "yes" ]; then echo "extension=twig.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`; fi - - if [ ${TRAVIS_PHP_VERSION:0:3} == "5.2" ]; then sed -i.bak "s|vendor/autoload.php|test/bootstrap.php|" phpunit.xml.dist; fi matrix: fast_finish: true diff --git a/core/vendor/twig/twig/CHANGELOG b/core/vendor/twig/twig/CHANGELOG index 6e574d4..04734fc 100644 --- a/core/vendor/twig/twig/CHANGELOG +++ b/core/vendor/twig/twig/CHANGELOG @@ -1,3 +1,23 @@ +* 2.0.0 (201X-XX-XX) + + * removed reserved macro names; all names can be used as macro + * removed Twig_Template::getEnvironment() + * removed _self variable (except for usage in from and import tags) + * made the loader a required argument of Twig_Environment constructor + * removed Twig_Environment::clearTemplateCache() + * removed Twig_Autoloader (use Composer instead) + * removed `true` as an equivalent to `html` for the auto-escaping strategy + * removed pre-1.8 autoescape tag syntax + * dropped support for PHP 5.2, 5.3, and 5.4 + * removed the ability to register a global variable after the runtime or the extensions have been initialized + * improved the performance of the filesystem loader + * removed features that were deprecated in 1.x + +* 1.21.2 (2015-XX-XX) + + * added Traversable support for replace, merge, and sort + * deprecated support for character by character replacement for the "replace" filter + * 1.21.1 (2015-08-26) * fixed regression when using the deprecated Twig_Test_* classes @@ -13,7 +33,7 @@ * 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 + * added Twig_BaseNodeVisitor to ease the compatibility of node visitors between 1.x and 2.x * 1.19.0 (2015-07-31) diff --git a/core/vendor/twig/twig/LICENSE b/core/vendor/twig/twig/LICENSE index a470002..d0c66ae 100644 --- a/core/vendor/twig/twig/LICENSE +++ b/core/vendor/twig/twig/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2009-2014 by the Twig Team. +Copyright (c) 2009-2015 by the Twig Team. Some rights reserved. diff --git a/core/vendor/twig/twig/composer.json b/core/vendor/twig/twig/composer.json index 2d3438e..ba17fb1 100644 --- a/core/vendor/twig/twig/composer.json +++ b/core/vendor/twig/twig/composer.json @@ -27,7 +27,7 @@ "forum": "https://groups.google.com/forum/#!forum/twig-users" }, "require": { - "php": ">=5.2.7" + "php": ">=5.5.0" }, "require-dev": { "symfony/phpunit-bridge": "~2.7", @@ -40,7 +40,7 @@ }, "extra": { "branch-alias": { - "dev-master": "1.21-dev" + "dev-master": "2.0-dev" } } } diff --git a/core/vendor/twig/twig/doc/advanced.rst b/core/vendor/twig/twig/doc/advanced.rst index a20eab0..18cf51f 100644 --- a/core/vendor/twig/twig/doc/advanced.rst +++ b/core/vendor/twig/twig/doc/advanced.rst @@ -1,12 +1,6 @@ Extending Twig ============== -.. caution:: - - This section describes how to extend Twig as of **Twig 1.12**. If you are - using an older version, read the :doc:`legacy` chapter - instead. - Twig can be extended in many ways; you can add extra tags, filters, tests, operators, global variables, and functions. You can even extend the parser itself with node visitors. @@ -129,19 +123,19 @@ Filters Creating a filter is as simple as associating a name with a PHP callable:: // an anonymous function - $filter = new Twig_SimpleFilter('rot13', function ($string) { + $filter = new Twig_Filter('rot13', function ($string) { return str_rot13($string); }); // or a simple PHP function - $filter = new Twig_SimpleFilter('rot13', 'str_rot13'); + $filter = new Twig_Filter('rot13', 'str_rot13'); // or a class method - $filter = new Twig_SimpleFilter('rot13', array('SomeClass', 'rot13Filter')); + $filter = new Twig_Filter('rot13', array('SomeClass', 'rot13Filter')); -The first argument passed to the ``Twig_SimpleFilter`` constructor is the name -of the filter you will use in templates and the second one is the PHP callable -to associate with it. +The first argument passed to the ``Twig_Filter`` constructor is the name of the +filter you will use in templates and the second one is the PHP callable to +associate with it. Then, add the filter to your Twig environment:: @@ -172,10 +166,9 @@ is compiled to something like the following:: -The ``Twig_SimpleFilter`` class takes an array of options as its last -argument:: +The ``Twig_Filter`` class takes an array of options as its last argument:: - $filter = new Twig_SimpleFilter('rot13', 'str_rot13', $options); + $filter = new Twig_Filter('rot13', 'str_rot13', $options); Environment-aware Filters ~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -184,7 +177,7 @@ If you want to access the current environment instance in your filter, set the ``needs_environment`` option to ``true``; Twig will pass the current environment as the first argument to the filter call:: - $filter = new Twig_SimpleFilter('rot13', function (Twig_Environment $env, $string) { + $filter = new Twig_Filter('rot13', function (Twig_Environment $env, $string) { // get the current charset for instance $charset = $env->getCharset(); @@ -199,11 +192,11 @@ If you want to access the current context in your filter, set the the first argument to the filter call (or the second one if ``needs_environment`` is also set to ``true``):: - $filter = new Twig_SimpleFilter('rot13', function ($context, $string) { + $filter = new Twig_Filter('rot13', function ($context, $string) { // ... }, array('needs_context' => true)); - $filter = new Twig_SimpleFilter('rot13', function (Twig_Environment $env, $context, $string) { + $filter = new Twig_Filter('rot13', function (Twig_Environment $env, $context, $string) { // ... }, array('needs_context' => true, 'needs_environment' => true)); @@ -215,21 +208,18 @@ before printing. If your filter acts as an escaper (or explicitly outputs HTML or JavaScript code), you will want the raw output to be printed. In such a case, set the ``is_safe`` option:: - $filter = new Twig_SimpleFilter('nl2br', 'nl2br', array('is_safe' => array('html'))); + $filter = new Twig_Filter('nl2br', 'nl2br', array('is_safe' => array('html'))); Some filters may need to work on input that is already escaped or safe, for example when adding (safe) HTML tags to originally unsafe output. In such a case, set the ``pre_escape`` option to escape the input data before it is run through your filter:: - $filter = new Twig_SimpleFilter('somefilter', 'somefilter', array('pre_escape' => 'html', 'is_safe' => array('html'))); + $filter = new Twig_Filter('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:: @@ -247,7 +237,7 @@ Dynamic Filters A filter name containing the special ``*`` character is a dynamic filter as the ``*`` can be any string:: - $filter = new Twig_SimpleFilter('*_path', function ($name, $arguments) { + $filter = new Twig_Filter('*_path', function ($name, $arguments) { // ... }); @@ -258,7 +248,7 @@ The following filters will be matched by the above defined dynamic filter: A dynamic filter can define more than one dynamic parts:: - $filter = new Twig_SimpleFilter('*_path_*', function ($name, $suffix, $arguments) { + $filter = new Twig_Filter('*_path_*', function ($name, $suffix, $arguments) { // ... }); @@ -270,9 +260,6 @@ the filter: ``('a', 'b', 'foo')``. Deprecated Filters ~~~~~~~~~~~~~~~~~~ -.. versionadded:: 1.21 - Support for deprecated filters was added in Twig 1.21. - You can mark a filter as being deprecated by setting the ``deprecated`` option to ``true``. You can also give an alternative filter that replaces the deprecated one when that makes sense:: @@ -288,10 +275,10 @@ Functions --------- Functions are defined in the exact same way as filters, but you need to create -an instance of ``Twig_SimpleFunction``:: +an instance of ``Twig_Function``:: $twig = new Twig_Environment($loader); - $function = new Twig_SimpleFunction('function_name', function () { + $function = new Twig_Function('function_name', function () { // ... }); $twig->addFunction($function); @@ -303,10 +290,10 @@ Tests ----- Tests are defined in the exact same way as filters and functions, but you need -to create an instance of ``Twig_SimpleTest``:: +to create an instance of ``Twig_Test``:: $twig = new Twig_Environment($loader); - $test = new Twig_SimpleTest('test_name', function () { + $test = new Twig_Test('test_name', function () { // ... }); $twig->addTest($test); @@ -316,7 +303,7 @@ boolean conditions. As a simple example, let's create a Twig test that checks if objects are 'red':: $twig = new Twig_Environment($loader); - $test = new Twig_SimpleTest('red', function ($value) { + $test = new Twig_Test('red', function ($value) { if (isset($value->color) && $value->color == 'red') { return true; } @@ -334,7 +321,7 @@ 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); - $test = new Twig_SimpleTest( + $test = new Twig_Test( 'odd', null, array('node_class' => 'Twig_Node_Expression_Test_Odd')); @@ -554,63 +541,63 @@ An extension is a class that implements the following interface:: * * @param Twig_Environment $environment The current Twig_Environment instance */ - function initRuntime(Twig_Environment $environment); + public function initRuntime(Twig_Environment $environment); /** * Returns the token parser instances to add to the existing list. * - * @return array An array of Twig_TokenParserInterface or Twig_TokenParserBrokerInterface instances + * @return array An array of Twig_TokenParserInterface instances */ - function getTokenParsers(); + public function getTokenParsers(); /** * Returns the node visitor instances to add to the existing list. * - * @return array An array of Twig_NodeVisitorInterface instances + * @return Twig_NodeVisitorInterface[] An array of Twig_NodeVisitorInterface instances */ - function getNodeVisitors(); + public function getNodeVisitors(); /** * Returns a list of filters to add to the existing list. * * @return array An array of filters */ - function getFilters(); + public function getFilters(); /** * Returns a list of tests to add to the existing list. * * @return array An array of tests */ - function getTests(); + public function getTests(); /** * Returns a list of functions to add to the existing list. * * @return array An array of functions */ - function getFunctions(); + public function getFunctions(); /** * Returns a list of operators to add to the existing list. * * @return array An array of operators */ - function getOperators(); + public function getOperators(); /** * Returns a list of global variables to add to the existing list. * * @return array An array of global variables */ - function getGlobals(); + public function getGlobals(); /** * Returns the name of the extension. * * @return string The extension name */ - function getName(); + public function getName(); } To keep your extension class clean and lean, it can inherit from the built-in @@ -681,7 +668,7 @@ method:: public function getFunctions() { return array( - new Twig_SimpleFunction('lipsum', 'generate_lipsum'), + new Twig_Function('lipsum', 'generate_lipsum'), ); } @@ -700,7 +687,7 @@ environment:: public function getFilters() { return array( - new Twig_SimpleFilter('rot13', 'str_rot13'), + new Twig_Filter('rot13', 'str_rot13'), ); } @@ -762,7 +749,7 @@ The ``getTests()`` method lets you add new test functions:: public function getTests() { return array( - new Twig_SimpleTest('even', 'twig_test_even'), + new Twig_Test('even', 'twig_test_even'), ); } @@ -781,7 +768,7 @@ possible** (order matters):: public function getFilters() { return array( - new Twig_SimpleFilter('date', array($this, 'dateFilter')), + new Twig_Filter('date', array($this, 'dateFilter')), ); } @@ -805,7 +792,7 @@ If you do the same on the Twig_Environment itself, beware that it takes precedence over any other registered extensions:: $twig = new Twig_Environment($loader); - $twig->addFilter(new Twig_SimpleFilter('date', function ($timestamp, $format = 'F j, Y H:i') { + $twig->addFilter(new Twig_Filter('date', function ($timestamp, $format = 'F j, Y H:i') { // do something different from the built-in date filter })); // the date filter will come from the above registration, not diff --git a/core/vendor/twig/twig/doc/advanced_legacy.rst b/core/vendor/twig/twig/doc/advanced_legacy.rst deleted file mode 100644 index 2ef6bfd..0000000 --- a/core/vendor/twig/twig/doc/advanced_legacy.rst +++ /dev/null @@ -1,887 +0,0 @@ -Extending Twig -============== - -.. caution:: - - This section describes how to extends Twig for versions **older than - 1.12**. If you are using a newer version, read the :doc:`newer` - chapter instead. - -Twig can be extended in many ways; you can add extra tags, filters, tests, -operators, global variables, and functions. You can even extend the parser -itself with node visitors. - -.. note:: - - The first section of this chapter describes how to extend Twig easily. If - you want to reuse your changes in different projects or if you want to - share them with others, you should then create an extension as described - in the following section. - -.. caution:: - - When extending Twig by calling methods on the Twig environment instance, - Twig won't be able to recompile your templates when the PHP code is - updated. To see your changes in real-time, either disable template caching - or package your code into an extension (see the next section of this - chapter). - -Before extending Twig, you must understand the differences between all the -different possible extension points and when to use them. - -First, remember that Twig has two main language constructs: - -* ``{{ }}``: used to print the result of an expression evaluation; - -* ``{% %}``: used to execute statements. - -To understand why Twig exposes so many extension points, let's see how to -implement a *Lorem ipsum* generator (it needs to know the number of words to -generate). - -You can use a ``lipsum`` *tag*: - -.. code-block:: jinja - - {% lipsum 40 %} - -That works, but using a tag for ``lipsum`` is not a good idea for at least -three main reasons: - -* ``lipsum`` is not a language construct; -* The tag outputs something; -* The tag is not flexible as you cannot use it in an expression: - - .. code-block:: jinja - - {{ 'some text' ~ {% lipsum 40 %} ~ 'some more text' }} - -In fact, you rarely need to create tags; and that's good news because tags are -the most complex extension point of Twig. - -Now, let's use a ``lipsum`` *filter*: - -.. code-block:: jinja - - {{ 40|lipsum }} - -Again, it works, but it looks weird. A filter transforms the passed value to -something else but here we use the value to indicate the number of words to -generate (so, ``40`` is an argument of the filter, not the value we want to -transform). - -Next, let's use a ``lipsum`` *function*: - -.. code-block:: jinja - - {{ lipsum(40) }} - -Here we go. For this specific example, the creation of a function is the -extension point to use. And you can use it anywhere an expression is accepted: - -.. code-block:: jinja - - {{ 'some text' ~ ipsum(40) ~ 'some more text' }} - - {% set ipsum = ipsum(40) %} - -Last but not the least, you can also use a *global* object with a method able -to generate lorem ipsum text: - -.. code-block:: jinja - - {{ text.lipsum(40) }} - -As a rule of thumb, use functions for frequently used features and global -objects for everything else. - -Keep in mind the following when you want to extend Twig: - -========== ========================== ========== ========================= -What? Implementation difficulty? How often? When? -========== ========================== ========== ========================= -*macro* trivial frequent Content generation -*global* trivial frequent Helper object -*function* trivial frequent Content generation -*filter* trivial frequent Value transformation -*tag* complex rare DSL language construct -*test* trivial rare Boolean decision -*operator* trivial rare Values transformation -========== ========================== ========== ========================= - -Globals -------- - -A global variable is like any other template variable, except that it's -available in all templates and macros:: - - $twig = new Twig_Environment($loader); - $twig->addGlobal('text', new Text()); - -You can then use the ``text`` variable anywhere in a template: - -.. code-block:: jinja - - {{ text.lipsum(40) }} - -Filters -------- - -A filter is a regular PHP function or an object method that takes the left -side of the filter (before the pipe ``|``) as first argument and the extra -arguments passed to the filter (within parentheses ``()``) as extra arguments. - -Defining a filter is as easy as associating the filter name with a PHP -callable. For instance, let's say you have the following code in a template: - -.. code-block:: jinja - - {{ 'TWIG'|lower }} - -When compiling this template to PHP, Twig looks for the PHP callable -associated with the ``lower`` filter. The ``lower`` filter is a built-in Twig -filter, and it is simply mapped to the PHP ``strtolower()`` function. After -compilation, the generated PHP code is roughly equivalent to: - -.. code-block:: html+php - - - -As you can see, the ``'TWIG'`` string is passed as a first argument to the PHP -function. - -A filter can also take extra arguments like in the following example: - -.. code-block:: jinja - - {{ now|date('d/m/Y') }} - -In this case, the extra arguments are passed to the function after the main -argument, and the compiled code is equivalent to: - -.. code-block:: html+php - - - -Let's see how to create a new filter. - -In this section, we will create a ``rot13`` filter, which should return the -`rot13`_ transformation of a string. Here is an example of its usage and the -expected output: - -.. code-block:: jinja - - {{ "Twig"|rot13 }} - - {# should displays Gjvt #} - -Adding a filter is as simple as calling the ``addFilter()`` method on the -``Twig_Environment`` instance:: - - $twig = new Twig_Environment($loader); - $twig->addFilter('rot13', new Twig_Filter_Function('str_rot13')); - -The second argument of ``addFilter()`` is an instance of ``Twig_Filter``. -Here, we use ``Twig_Filter_Function`` as the filter is a PHP function. The -first argument passed to the ``Twig_Filter_Function`` constructor is the name -of the PHP function to call, here ``str_rot13``, a native PHP function. - -Let's say I now want to be able to add a prefix before the converted string: - -.. code-block:: jinja - - {{ "Twig"|rot13('prefix_') }} - - {# should displays prefix_Gjvt #} - -As the PHP ``str_rot13()`` function does not support this requirement, let's -create a new PHP function:: - - function project_compute_rot13($string, $prefix = '') - { - return $prefix.str_rot13($string); - } - -As you can see, the ``prefix`` argument of the filter is passed as an extra -argument to the ``project_compute_rot13()`` function. - -Adding this filter is as easy as before:: - - $twig->addFilter('rot13', new Twig_Filter_Function('project_compute_rot13')); - -For better encapsulation, a filter can also be defined as a static method of a -class. The ``Twig_Filter_Function`` class can also be used to register such -static methods as filters:: - - $twig->addFilter('rot13', new Twig_Filter_Function('SomeClass::rot13Filter')); - -.. tip:: - - In an extension, you can also define a filter as a static method of the - extension class. - -Environment aware Filters -~~~~~~~~~~~~~~~~~~~~~~~~~ - -The ``Twig_Filter`` classes take options as their last argument. For instance, -if you want access to the current environment instance in your filter, set the -``needs_environment`` option to ``true``:: - - $filter = new Twig_Filter_Function('str_rot13', array('needs_environment' => true)); - -Twig will then pass the current environment as the first argument to the -filter call:: - - function twig_compute_rot13(Twig_Environment $env, $string) - { - // get the current charset for instance - $charset = $env->getCharset(); - - return str_rot13($string); - } - -Automatic Escaping -~~~~~~~~~~~~~~~~~~ - -If automatic escaping is enabled, the output of the filter may be escaped -before printing. If your filter acts as an escaper (or explicitly outputs HTML -or JavaScript code), you will want the raw output to be printed. In such a -case, set the ``is_safe`` option:: - - $filter = new Twig_Filter_Function('nl2br', array('is_safe' => array('html'))); - -Some filters may need to work on input that is already escaped or safe, for -example when adding (safe) HTML tags to originally unsafe output. In such a -case, set the ``pre_escape`` option to escape the input data before it is run -through your filter:: - - $filter = new Twig_Filter_Function('somefilter', array('pre_escape' => 'html', 'is_safe' => array('html'))); - -Dynamic Filters -~~~~~~~~~~~~~~~ - -.. versionadded:: 1.5 - Dynamic filters support was added in Twig 1.5. - -A filter name containing the special ``*`` character is a dynamic filter as -the ``*`` can be any string:: - - $twig->addFilter('*_path_*', new Twig_Filter_Function('twig_path')); - - function twig_path($name, $arguments) - { - // ... - } - -The following filters will be matched by the above defined dynamic filter: - -* ``product_path`` -* ``category_path`` - -A dynamic filter can define more than one dynamic parts:: - - $twig->addFilter('*_path_*', new Twig_Filter_Function('twig_path')); - - function twig_path($name, $suffix, $arguments) - { - // ... - } - -The filter will receive all dynamic part values before the normal filters -arguments. For instance, a call to ``'foo'|a_path_b()`` will result in the -following PHP call: ``twig_path('a', 'b', 'foo')``. - -Functions ---------- - -A function is a regular PHP function or an object method that can be called from -templates. - -.. code-block:: jinja - - {{ constant("DATE_W3C") }} - -When compiling this template to PHP, Twig looks for the PHP callable -associated with the ``constant`` function. The ``constant`` function is a built-in Twig -function, and it is simply mapped to the PHP ``constant()`` function. After -compilation, the generated PHP code is roughly equivalent to: - -.. code-block:: html+php - - - -Adding a function is similar to adding a filter. This can be done by calling the -``addFunction()`` method on the ``Twig_Environment`` instance:: - - $twig = new Twig_Environment($loader); - $twig->addFunction('functionName', new Twig_Function_Function('someFunction')); - -You can also expose extension methods as functions in your templates:: - - // $this is an object that implements Twig_ExtensionInterface. - $twig = new Twig_Environment($loader); - $twig->addFunction('otherFunction', new Twig_Function_Method($this, 'someMethod')); - -Functions also support ``needs_environment`` and ``is_safe`` parameters. - -Dynamic Functions -~~~~~~~~~~~~~~~~~ - -.. versionadded:: 1.5 - Dynamic functions support was added in Twig 1.5. - -A function name containing the special ``*`` character is a dynamic function -as the ``*`` can be any string:: - - $twig->addFunction('*_path', new Twig_Function_Function('twig_path')); - - function twig_path($name, $arguments) - { - // ... - } - -The following functions will be matched by the above defined dynamic function: - -* ``product_path`` -* ``category_path`` - -A dynamic function can define more than one dynamic parts:: - - $twig->addFilter('*_path_*', new Twig_Filter_Function('twig_path')); - - function twig_path($name, $suffix, $arguments) - { - // ... - } - -The function will receive all dynamic part values before the normal functions -arguments. For instance, a call to ``a_path_b('foo')`` will result in the -following PHP call: ``twig_path('a', 'b', 'foo')``. - -Tags ----- - -One of the most exciting feature of a template engine like Twig is the -possibility to define new language constructs. This is also the most complex -feature as you need to understand how Twig's internals work. - -Let's create a simple ``set`` tag that allows the definition of simple -variables from within a template. The tag can be used like follows: - -.. code-block:: jinja - - {% set name = "value" %} - - {{ name }} - - {# should output value #} - -.. note:: - - The ``set`` tag is part of the Core extension and as such is always - available. The built-in version is slightly more powerful and supports - multiple assignments by default (cf. the template designers chapter for - more information). - -Three steps are needed to define a new tag: - -* Defining a Token Parser class (responsible for parsing the template code); - -* Defining a Node class (responsible for converting the parsed code to PHP); - -* Registering the tag. - -Registering a new tag -~~~~~~~~~~~~~~~~~~~~~ - -Adding a tag is as simple as calling the ``addTokenParser`` method on the -``Twig_Environment`` instance:: - - $twig = new Twig_Environment($loader); - $twig->addTokenParser(new Project_Set_TokenParser()); - -Defining a Token Parser -~~~~~~~~~~~~~~~~~~~~~~~ - -Now, let's see the actual code of this class:: - - class Project_Set_TokenParser extends Twig_TokenParser - { - public function parse(Twig_Token $token) - { - $lineno = $token->getLine(); - $name = $this->parser->getStream()->expect(Twig_Token::NAME_TYPE)->getValue(); - $this->parser->getStream()->expect(Twig_Token::OPERATOR_TYPE, '='); - $value = $this->parser->getExpressionParser()->parseExpression(); - - $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); - - return new Project_Set_Node($name, $value, $lineno, $this->getTag()); - } - - public function getTag() - { - return 'set'; - } - } - -The ``getTag()`` method must return the tag we want to parse, here ``set``. - -The ``parse()`` method is invoked whenever the parser encounters a ``set`` -tag. It should return a ``Twig_Node`` instance that represents the node (the -``Project_Set_Node`` calls creating is explained in the next section). - -The parsing process is simplified thanks to a bunch of methods you can call -from the token stream (``$this->parser->getStream()``): - -* ``getCurrent()``: Gets the current token in the stream. - -* ``next()``: Moves to the next token in the stream, *but returns the old one*. - -* ``test($type)``, ``test($value)`` or ``test($type, $value)``: Determines whether - the current token is of a particular type or value (or both). The value may be an - array of several possible values. - -* ``expect($type[, $value[, $message]])``: If the current token isn't of the given - type/value a syntax error is thrown. Otherwise, if the type and value are correct, - the token is returned and the stream moves to the next token. - -* ``look()``: Looks a the next token without consuming it. - -Parsing expressions is done by calling the ``parseExpression()`` like we did for -the ``set`` tag. - -.. tip:: - - Reading the existing ``TokenParser`` classes is the best way to learn all - the nitty-gritty details of the parsing process. - -Defining a Node -~~~~~~~~~~~~~~~ - -The ``Project_Set_Node`` class itself is rather simple:: - - class Project_Set_Node extends Twig_Node - { - public function __construct($name, Twig_Node_Expression $value, $lineno, $tag = null) - { - parent::__construct(array('value' => $value), array('name' => $name), $lineno, $tag); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler - ->addDebugInfo($this) - ->write('$context[\''.$this->getAttribute('name').'\'] = ') - ->subcompile($this->getNode('value')) - ->raw(";\n") - ; - } - } - -The compiler implements a fluid interface and provides methods that helps the -developer generate beautiful and readable PHP code: - -* ``subcompile()``: Compiles a node. - -* ``raw()``: Writes the given string as is. - -* ``write()``: Writes the given string by adding indentation at the beginning - of each line. - -* ``string()``: Writes a quoted string. - -* ``repr()``: Writes a PHP representation of a given value (see - ``Twig_Node_For`` for a usage example). - -* ``addDebugInfo()``: Adds the line of the original template file related to - the current node as a comment. - -* ``indent()``: Indents the generated code (see ``Twig_Node_Block`` for a - usage example). - -* ``outdent()``: Outdents the generated code (see ``Twig_Node_Block`` for a - usage example). - -.. _creating_extensions: - -Creating an Extension ---------------------- - -The main motivation for writing an extension is to move often used code into a -reusable class like adding support for internationalization. An extension can -define tags, filters, tests, operators, global variables, functions, and node -visitors. - -Creating an extension also makes for a better separation of code that is -executed at compilation time and code needed at runtime. As such, it makes -your code faster. - -Most of the time, it is useful to create a single extension for your project, -to host all the specific tags and filters you want to add to Twig. - -.. tip:: - - When packaging your code into an extension, Twig is smart enough to - recompile your templates whenever you make a change to it (when the - ``auto_reload`` is enabled). - -.. note:: - - Before writing your own extensions, have a look at the Twig official - extension repository: http://github.com/twigphp/Twig-extensions. - -An extension is a class that implements the following interface:: - - interface Twig_ExtensionInterface - { - /** - * Initializes the runtime environment. - * - * This is where you can load some file that contains filter functions for instance. - * - * @param Twig_Environment $environment The current Twig_Environment instance - */ - function initRuntime(Twig_Environment $environment); - - /** - * Returns the token parser instances to add to the existing list. - * - * @return array An array of Twig_TokenParserInterface or Twig_TokenParserBrokerInterface instances - */ - function getTokenParsers(); - - /** - * Returns the node visitor instances to add to the existing list. - * - * @return array An array of Twig_NodeVisitorInterface instances - */ - function getNodeVisitors(); - - /** - * Returns a list of filters to add to the existing list. - * - * @return array An array of filters - */ - function getFilters(); - - /** - * Returns a list of tests to add to the existing list. - * - * @return array An array of tests - */ - function getTests(); - - /** - * Returns a list of functions to add to the existing list. - * - * @return array An array of functions - */ - function getFunctions(); - - /** - * Returns a list of operators to add to the existing list. - * - * @return array An array of operators - */ - function getOperators(); - - /** - * Returns a list of global variables to add to the existing list. - * - * @return array An array of global variables - */ - function getGlobals(); - - /** - * Returns the name of the extension. - * - * @return string The extension name - */ - function getName(); - } - -To keep your extension class clean and lean, it can inherit from the built-in -``Twig_Extension`` class instead of implementing the whole interface. That -way, you just need to implement the ``getName()`` method as the -``Twig_Extension`` provides empty implementations for all other methods. - -The ``getName()`` method must return a unique identifier for your extension. - -Now, with this information in mind, let's create the most basic extension -possible:: - - class Project_Twig_Extension extends Twig_Extension - { - public function getName() - { - return 'project'; - } - } - -.. note:: - - Of course, this extension does nothing for now. We will customize it in - the next sections. - -Twig does not care where you save your extension on the filesystem, as all -extensions must be registered explicitly to be available in your templates. - -You can register an extension by using the ``addExtension()`` method on your -main ``Environment`` object:: - - $twig = new Twig_Environment($loader); - $twig->addExtension(new Project_Twig_Extension()); - -Of course, you need to first load the extension file by either using -``require_once()`` or by using an autoloader (see `spl_autoload_register()`_). - -.. tip:: - - The bundled extensions are great examples of how extensions work. - -Globals -~~~~~~~ - -Global variables can be registered in an extension via the ``getGlobals()`` -method:: - - class Project_Twig_Extension extends Twig_Extension - { - public function getGlobals() - { - return array( - 'text' => new Text(), - ); - } - - // ... - } - -Functions -~~~~~~~~~ - -Functions can be registered in an extension via the ``getFunctions()`` -method:: - - class Project_Twig_Extension extends Twig_Extension - { - public function getFunctions() - { - return array( - 'lipsum' => new Twig_Function_Function('generate_lipsum'), - ); - } - - // ... - } - -Filters -~~~~~~~ - -To add a filter to an extension, you need to override the ``getFilters()`` -method. This method must return an array of filters to add to the Twig -environment:: - - class Project_Twig_Extension extends Twig_Extension - { - public function getFilters() - { - return array( - 'rot13' => new Twig_Filter_Function('str_rot13'), - ); - } - - // ... - } - -As you can see in the above code, the ``getFilters()`` method returns an array -where keys are the name of the filters (``rot13``) and the values the -definition of the filter (``new Twig_Filter_Function('str_rot13')``). - -As seen in the previous chapter, you can also define filters as static methods -on the extension class:: - -$twig->addFilter('rot13', new Twig_Filter_Function('Project_Twig_Extension::rot13Filter')); - -You can also use ``Twig_Filter_Method`` instead of ``Twig_Filter_Function`` -when defining a filter to use a method:: - - class Project_Twig_Extension extends Twig_Extension - { - public function getFilters() - { - return array( - 'rot13' => new Twig_Filter_Method($this, 'rot13Filter'), - ); - } - - public function rot13Filter($string) - { - return str_rot13($string); - } - - // ... - } - -The first argument of the ``Twig_Filter_Method`` constructor is always -``$this``, the current extension object. The second one is the name of the -method to call. - -Using methods for filters is a great way to package your filter without -polluting the global namespace. This also gives the developer more flexibility -at the cost of a small overhead. - -Overriding default Filters -.......................... - -If some default core filters do not suit your needs, you can easily override -them by creating your own extension. Just use the same names as the one you -want to override:: - - class MyCoreExtension extends Twig_Extension - { - public function getFilters() - { - return array( - 'date' => new Twig_Filter_Method($this, 'dateFilter'), - // ... - ); - } - - public function dateFilter($timestamp, $format = 'F j, Y H:i') - { - return '...'.twig_date_format_filter($timestamp, $format); - } - - public function getName() - { - return 'project'; - } - } - -Here, we override the ``date`` filter with a custom one. Using this extension -is as simple as registering the ``MyCoreExtension`` extension by calling the -``addExtension()`` method on the environment instance:: - - $twig = new Twig_Environment($loader); - $twig->addExtension(new MyCoreExtension()); - -Tags -~~~~ - -Adding a tag in an extension can be done by overriding the -``getTokenParsers()`` method. This method must return an array of tags to add -to the Twig environment:: - - class Project_Twig_Extension extends Twig_Extension - { - public function getTokenParsers() - { - return array(new Project_Set_TokenParser()); - } - - // ... - } - -In the above code, we have added a single new tag, defined by the -``Project_Set_TokenParser`` class. The ``Project_Set_TokenParser`` class is -responsible for parsing the tag and compiling it to PHP. - -Operators -~~~~~~~~~ - -The ``getOperators()`` methods allows to add new operators. Here is how to add -``!``, ``||``, and ``&&`` operators:: - - class Project_Twig_Extension extends Twig_Extension - { - public function getOperators() - { - return array( - array( - '!' => array('precedence' => 50, 'class' => 'Twig_Node_Expression_Unary_Not'), - ), - array( - '||' => array('precedence' => 10, 'class' => 'Twig_Node_Expression_Binary_Or', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), - '&&' => array('precedence' => 15, 'class' => 'Twig_Node_Expression_Binary_And', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), - ), - ); - } - - // ... - } - -Tests -~~~~~ - -The ``getTests()`` methods allows to add new test functions:: - - class Project_Twig_Extension extends Twig_Extension - { - public function getTests() - { - return array( - 'even' => new Twig_Test_Function('twig_test_even'), - ); - } - - // ... - } - -Testing an Extension --------------------- - -.. versionadded:: 1.10 - Support for functional tests was added in Twig 1.10. - -Functional Tests -~~~~~~~~~~~~~~~~ - -You can create functional tests for extensions simply by creating the -following file structure in your test directory:: - - Fixtures/ - filters/ - foo.test - bar.test - functions/ - foo.test - bar.test - tags/ - foo.test - bar.test - IntegrationTest.php - -The ``IntegrationTest.php`` file should look like this:: - - class Project_Tests_IntegrationTest extends Twig_Test_IntegrationTestCase - { - public function getExtensions() - { - return array( - new Project_Twig_Extension1(), - new Project_Twig_Extension2(), - ); - } - - public function getFixturesDir() - { - return dirname(__FILE__).'/Fixtures/'; - } - } - -Fixtures examples can be found within the Twig repository -`tests/Twig/Fixtures`_ directory. - -Node Tests -~~~~~~~~~~ - -Testing the node visitors can be complex, so extend your test cases from -``Twig_Test_NodeTestCase``. Examples can be found in the Twig repository -`tests/Twig/Node`_ directory. - -.. _`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/twigphp/Twig/tree/master/test/Twig/Tests/Fixtures -.. _`tests/Twig/Node`: https://github.com/twigphp/Twig/tree/master/test/Twig/Tests/Node diff --git a/core/vendor/twig/twig/doc/api.rst b/core/vendor/twig/twig/doc/api.rst index f367db0..f8d0cf9 100644 --- a/core/vendor/twig/twig/doc/api.rst +++ b/core/vendor/twig/twig/doc/api.rst @@ -21,8 +21,7 @@ are in use. The simplest way to configure Twig to load templates for your application looks roughly like this:: - require_once '/path/to/lib/Twig/Autoloader.php'; - Twig_Autoloader::register(); + require_once '/path/to/vendor/autoload.php'; $loader = new Twig_Loader_Filesystem('/path/to/templates'); $twig = new Twig_Environment($loader, array( @@ -106,23 +105,16 @@ The following options are available: replace them with a ``null`` value. When set to ``true``, Twig throws an exception instead (default to ``false``). -* ``autoescape`` *string|boolean* +* ``autoescape`` *string* - 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 (this - strategy does not incur any overhead at runtime as auto-escaping is done at - compilation time.) + Sets the default auto-escaping strategy (``filename``, + ``html``, ``js``, ``css``, ``url``, ``html_attr``, or a PHP callback that + takes the template "filename" and returns the escaping strategy to use -- the + callback cannot be a function name to avoid collision with built-in escaping + strategies); set it to ``false`` to disable auto-escaping. The ``filename`` + escaping strategy determines the escaping strategy to use for a template + based on the template filename extension (this strategy does not incur any + overhead at runtime as auto-escaping is done at compilation time.) * ``optimizations`` *integer* @@ -153,9 +145,6 @@ Here is a list of the built-in loaders Twig provides: ``Twig_Loader_Filesystem`` .......................... -.. versionadded:: 1.10 - The ``prependPath()`` and support for namespaces were added in Twig 1.10. - ``Twig_Loader_Filesystem`` loads templates from the file system. This loader can find templates in folders on the file system and is the preferred way to load them:: @@ -208,7 +197,7 @@ projects where storing all templates in a single PHP file might make sense. .. tip:: - When using the ``Array`` or ``String`` loaders with a cache mechanism, you + When using the ``Array`` 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 @@ -253,37 +242,51 @@ All loaders implement the ``Twig_LoaderInterface``:: /** * Gets the source code of a template, given its name. * - * @param string $name string The name of the template to load + * @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); + public function getSource($name); /** * Gets the cache key to use for the cache for a given template name. * - * @param string $name string The name of the template to load + * @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); + public 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 bool true if the template is fresh, false otherwise + * + * @throws Twig_Error_Loader When $name is not found */ - function isFresh($name, $time); + public function isFresh($name, $time); + + /** + * Check if we have the source code of a template, given its name. + * + * @param string $name The name of the template to check if we can load + * + * @return bool If the template source code is handled by this loader or not + */ + public function exists($name); } The ``isFresh()`` method must return ``true`` if the current cached template is still fresh, given the last modification time, or ``false`` otherwise. -.. tip:: - - As of Twig 1.11.0, you can also implement ``Twig_ExistsLoaderInterface`` - to make your loader faster when used with the chain loader. +The ``exists()`` method make your loader faster when used with the chain loader. Using Extensions ---------------- @@ -303,8 +306,7 @@ 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_Profiler*: Enabled the built-in Twig profiler. * *Twig_Extension_Optimizer*: Optimizes the node tree before compilation. @@ -350,9 +352,7 @@ escaping strategy), except those using the ``raw`` filter: {{ article.to_html|raw }} -You can also change the escaping mode locally by using the ``autoescape`` tag -(see the :doc:`autoescape` doc for the syntax used before -Twig 1.8): +You can also change the escaping mode locally by using the ``autoescape`` tag: .. code-block:: jinja @@ -477,9 +477,6 @@ the extension constructor:: 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:: diff --git a/core/vendor/twig/twig/doc/deprecated.rst b/core/vendor/twig/twig/doc/deprecated.rst deleted file mode 100644 index 1489174..0000000 --- a/core/vendor/twig/twig/doc/deprecated.rst +++ /dev/null @@ -1,148 +0,0 @@ -Deprecated Features -=================== - -This document lists all deprecated features in Twig. Deprecated features are -kept for backward compatibility and removed in the next major release (a -feature that was deprecated in Twig 1.x is removed in Twig 2.0). - -Deprecation Notices -------------------- - -As of Twig 1.21, Twig generates deprecation notices when a template uses -deprecated features. See :ref:`deprecation-notices` for more information. - -Token Parsers -------------- - -* As of Twig 1.x, the token parser broker sub-system is deprecated. The - following class and interface will be removed in 2.0: - - * ``Twig_TokenParserBrokerInterface`` - * ``Twig_TokenParserBroker`` - -Extensions ----------- - -* As of Twig 1.x, the ability to remove an extension is deprecated and the - ``Twig_Environment::removeExtension()`` method will be removed in 2.0. - -PEAR ----- - -PEAR support has been discontinued in Twig 1.15.1, and no PEAR packages are -provided anymore. Use Composer instead. - -Filters -------- - -* As of Twig 1.x, use ``Twig_SimpleFilter`` to add a filter. The following - classes and interfaces will be removed in 2.0: - - * ``Twig_FilterInterface`` - * ``Twig_FilterCallableInterface`` - * ``Twig_Filter`` - * ``Twig_Filter_Function`` - * ``Twig_Filter_Method`` - * ``Twig_Filter_Node`` - -* As of Twig 2.x, the ``Twig_SimpleFilter`` class is deprecated and will be - removed in Twig 3.x (use ``Twig_Filter`` instead). In Twig 2.x, - ``Twig_SimpleFilter`` is just an alias for ``Twig_Filter``. - -Functions ---------- - -* As of Twig 1.x, use ``Twig_SimpleFunction`` to add a function. The following - classes and interfaces will be removed in 2.0: - - * ``Twig_FunctionInterface`` - * ``Twig_FunctionCallableInterface`` - * ``Twig_Function`` - * ``Twig_Function_Function`` - * ``Twig_Function_Method`` - * ``Twig_Function_Node`` - -* As of Twig 2.x, the ``Twig_SimpleFunction`` class is deprecated and will be - removed in Twig 3.x (use ``Twig_Function`` instead). In Twig 2.x, - ``Twig_SimpleFunction`` is just an alias for ``Twig_Function``. - -Tests ------ - -* As of Twig 1.x, use ``Twig_SimpleTest`` to add a test. The following classes - and interfaces will be removed in 2.0: - - * ``Twig_TestInterface`` - * ``Twig_TestCallableInterface`` - * ``Twig_Test`` - * ``Twig_Test_Function`` - * ``Twig_Test_Method`` - * ``Twig_Test_Node`` - -* As of Twig 2.x, the ``Twig_SimpleTest`` class is deprecated and will be - removed in Twig 3.x (use ``Twig_Test`` instead). In Twig 2.x, - ``Twig_SimpleTest`` is just an alias for ``Twig_Test``. - -* The ``sameas`` and ``divisibleby`` tests are deprecated in favor of ``same - as`` and ``divisible by`` respectively. - -Tags ----- - -* As of Twig 1.x, the ``raw`` tag is deprecated. You should use ``verbatim`` - instead. - -Nodes ------ - -* As of Twig 1.x, ``Node::toXml()`` is deprecated and will be removed in Twig - 2.0. - -Interfaces ----------- - -* As of Twig 2.x, the following interfaces are deprecated and empty (they will - be removed in Twig 3.0): - -* ``Twig_CompilerInterface`` (use ``Twig_Compiler`` instead) -* ``Twig_LexerInterface`` (use ``Twig_Lexer`` instead) -* ``Twig_NodeInterface`` (use ``Twig_Node`` instead) -* ``Twig_ParserInterface`` (use ``Twig_Parser`` instead) -* ``Twig_ExistsLoaderInterface`` (merged with ``Twig_LoaderInterface``) -* ``Twig_TemplateInterface`` (use ``Twig_Template`` instead, and use - those constants Twig_Template::ANY_CALL, Twig_Template::ARRAY_CALL, - Twig_Template::METHOD_CALL) - -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. diff --git a/core/vendor/twig/twig/doc/filters/batch.rst b/core/vendor/twig/twig/doc/filters/batch.rst index f8b6fa9..f26feba 100644 --- a/core/vendor/twig/twig/doc/filters/batch.rst +++ b/core/vendor/twig/twig/doc/filters/batch.rst @@ -1,9 +1,6 @@ ``batch`` ========= -.. versionadded:: 1.12.3 - 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. A second parameter can be provided and used to fill in missing items: diff --git a/core/vendor/twig/twig/doc/filters/convert_encoding.rst b/core/vendor/twig/twig/doc/filters/convert_encoding.rst index f4ebe58..82ea3a7 100644 --- a/core/vendor/twig/twig/doc/filters/convert_encoding.rst +++ b/core/vendor/twig/twig/doc/filters/convert_encoding.rst @@ -1,9 +1,6 @@ ``convert_encoding`` ==================== -.. versionadded:: 1.4 - The ``convert_encoding`` filter was added in Twig 1.4. - The ``convert_encoding`` filter converts a string from one encoding to another. The first argument is the expected output charset and the second one is the input charset: @@ -16,7 +13,7 @@ is the input charset: This filter relies on the `iconv`_ or `mbstring`_ extension, so one of them must be installed. In case both are installed, `mbstring`_ is used by - default (Twig before 1.8.1 uses `iconv`_ by default). + default. Arguments --------- diff --git a/core/vendor/twig/twig/doc/filters/date.rst b/core/vendor/twig/twig/doc/filters/date.rst index c86d42b..97b1f06 100644 --- a/core/vendor/twig/twig/doc/filters/date.rst +++ b/core/vendor/twig/twig/doc/filters/date.rst @@ -1,18 +1,6 @@ ``date`` ======== -.. versionadded:: 1.1 - The timezone support has been added in Twig 1.1. - -.. versionadded:: 1.5 - The default date format support has been added in Twig 1.5. - -.. versionadded:: 1.6.1 - The default timezone support has been added in Twig 1.6.1. - -.. versionadded:: 1.11.0 - The introduction of the false value for the timezone was introduced in Twig 1.11.0 - The ``date`` filter formats a date to a given format: .. code-block:: jinja diff --git a/core/vendor/twig/twig/doc/filters/date_modify.rst b/core/vendor/twig/twig/doc/filters/date_modify.rst index add40b5..4db9dfb 100644 --- a/core/vendor/twig/twig/doc/filters/date_modify.rst +++ b/core/vendor/twig/twig/doc/filters/date_modify.rst @@ -1,9 +1,6 @@ ``date_modify`` =============== -.. versionadded:: 1.9.0 - The date_modify filter has been added in Twig 1.9.0. - The ``date_modify`` filter modifies a date with a given modifier string: .. code-block:: jinja diff --git a/core/vendor/twig/twig/doc/filters/escape.rst b/core/vendor/twig/twig/doc/filters/escape.rst index fc9771a..75695cd 100644 --- a/core/vendor/twig/twig/doc/filters/escape.rst +++ b/core/vendor/twig/twig/doc/filters/escape.rst @@ -1,13 +1,6 @@ ``escape`` ========== -.. versionadded:: 1.9.0 - The ``css``, ``url``, and ``html_attr`` strategies were added in Twig - 1.9.0. - -.. versionadded:: 1.14.0 - The ability to define custom escapers was added in Twig 1.14.0. - The ``escape`` filter escapes a string for safe insertion into the final output. It supports different escaping strategies depending on the template context. diff --git a/core/vendor/twig/twig/doc/filters/first.rst b/core/vendor/twig/twig/doc/filters/first.rst index 674c1f9..30eb217 100644 --- a/core/vendor/twig/twig/doc/filters/first.rst +++ b/core/vendor/twig/twig/doc/filters/first.rst @@ -1,9 +1,6 @@ ``first`` ========= -.. versionadded:: 1.12.2 - The ``first`` filter was added in Twig 1.12.2. - The ``first`` filter returns the first "element" of a sequence, a mapping, or a string: diff --git a/core/vendor/twig/twig/doc/filters/last.rst b/core/vendor/twig/twig/doc/filters/last.rst index 345b657..9c05974 100644 --- a/core/vendor/twig/twig/doc/filters/last.rst +++ b/core/vendor/twig/twig/doc/filters/last.rst @@ -1,9 +1,6 @@ ``last`` ======== -.. versionadded:: 1.12.2 - The ``last`` filter was added in Twig 1.12.2. - The ``last`` filter returns the last "element" of a sequence, a mapping, or a string: diff --git a/core/vendor/twig/twig/doc/filters/merge.rst b/core/vendor/twig/twig/doc/filters/merge.rst index cb8b1b2..88780dd 100644 --- a/core/vendor/twig/twig/doc/filters/merge.rst +++ b/core/vendor/twig/twig/doc/filters/merge.rst @@ -42,6 +42,7 @@ overridden. .. note:: - Internally, Twig uses the PHP `array_merge`_ function. + Internally, Twig uses the PHP `array_merge`_ function. It supports + Traversable objects by transforming those to arrays. .. _`array_merge`: http://php.net/array_merge diff --git a/core/vendor/twig/twig/doc/filters/nl2br.rst b/core/vendor/twig/twig/doc/filters/nl2br.rst index 5c923e1..366ca83 100644 --- a/core/vendor/twig/twig/doc/filters/nl2br.rst +++ b/core/vendor/twig/twig/doc/filters/nl2br.rst @@ -1,9 +1,6 @@ ``nl2br`` ========= -.. versionadded:: 1.5 - The ``nl2br`` filter was added in Twig 1.5. - The ``nl2br`` filter inserts HTML line breaks before all newlines in a string: .. code-block:: jinja diff --git a/core/vendor/twig/twig/doc/filters/number_format.rst b/core/vendor/twig/twig/doc/filters/number_format.rst index 3114e84..df8ef7f 100644 --- a/core/vendor/twig/twig/doc/filters/number_format.rst +++ b/core/vendor/twig/twig/doc/filters/number_format.rst @@ -1,9 +1,6 @@ ``number_format`` ================= -.. versionadded:: 1.5 - The ``number_format`` filter was added in Twig 1.5 - The ``number_format`` filter formats numbers. It is a wrapper around PHP's `number_format`_ function: diff --git a/core/vendor/twig/twig/doc/filters/reverse.rst b/core/vendor/twig/twig/doc/filters/reverse.rst index 76fd2c1..7e9508f 100644 --- a/core/vendor/twig/twig/doc/filters/reverse.rst +++ b/core/vendor/twig/twig/doc/filters/reverse.rst @@ -1,9 +1,6 @@ ``reverse`` =========== -.. versionadded:: 1.6 - Support for strings has been added in Twig 1.6. - The ``reverse`` filter reverses a sequence, a mapping, or a string: .. code-block:: jinja diff --git a/core/vendor/twig/twig/doc/filters/round.rst b/core/vendor/twig/twig/doc/filters/round.rst index 2521cf1..c14a7a9 100644 --- a/core/vendor/twig/twig/doc/filters/round.rst +++ b/core/vendor/twig/twig/doc/filters/round.rst @@ -1,9 +1,6 @@ ``round`` ========= -.. versionadded:: 1.15.0 - The ``round`` filter was added in Twig 1.15.0. - The ``round`` filter rounds a number to a given precision: .. code-block:: jinja diff --git a/core/vendor/twig/twig/doc/filters/slice.rst b/core/vendor/twig/twig/doc/filters/slice.rst index 70bf139..c255756 100644 --- a/core/vendor/twig/twig/doc/filters/slice.rst +++ b/core/vendor/twig/twig/doc/filters/slice.rst @@ -1,9 +1,6 @@ ``slice`` =========== -.. versionadded:: 1.6 - The ``slice`` filter was added in Twig 1.6. - The ``slice`` filter extracts a slice of a sequence, a mapping, or a string: .. code-block:: jinja diff --git a/core/vendor/twig/twig/doc/filters/sort.rst b/core/vendor/twig/twig/doc/filters/sort.rst index 3331152..350207f 100644 --- a/core/vendor/twig/twig/doc/filters/sort.rst +++ b/core/vendor/twig/twig/doc/filters/sort.rst @@ -12,6 +12,7 @@ The ``sort`` filter sorts an array: .. note:: Internally, Twig uses the PHP `asort`_ function to maintain index - association. + association. It supports Traversable objects by transforming + those to arrays. .. _`asort`: http://php.net/asort diff --git a/core/vendor/twig/twig/doc/filters/split.rst b/core/vendor/twig/twig/doc/filters/split.rst index bbc6d79..cb82948 100644 --- a/core/vendor/twig/twig/doc/filters/split.rst +++ b/core/vendor/twig/twig/doc/filters/split.rst @@ -1,9 +1,6 @@ ``split`` ========= -.. versionadded:: 1.10.3 - The ``split`` filter was added in Twig 1.10.3. - The ``split`` filter splits a string by the given delimiter and returns a list of strings: diff --git a/core/vendor/twig/twig/doc/filters/trim.rst b/core/vendor/twig/twig/doc/filters/trim.rst index 4ddb208..815895b 100644 --- a/core/vendor/twig/twig/doc/filters/trim.rst +++ b/core/vendor/twig/twig/doc/filters/trim.rst @@ -1,9 +1,6 @@ ``trim`` ======== -.. versionadded:: 1.6.2 - The ``trim`` filter was added in Twig 1.6.2. - The ``trim`` filter strips whitespace (or other characters) from the beginning and end of a string: diff --git a/core/vendor/twig/twig/doc/filters/url_encode.rst b/core/vendor/twig/twig/doc/filters/url_encode.rst index 5944e59..d8b8af3 100644 --- a/core/vendor/twig/twig/doc/filters/url_encode.rst +++ b/core/vendor/twig/twig/doc/filters/url_encode.rst @@ -1,13 +1,6 @@ ``url_encode`` ============== -.. versionadded:: 1.12.3 - Support for encoding an array as query string was added in Twig 1.12.3. - -.. versionadded:: 1.16.0 - The ``raw`` argument was removed in Twig 1.16.0. Twig now always encodes - according to RFC 3986. - The ``url_encode`` filter percent encodes a given string as URL segment or an array as query string: @@ -24,11 +17,6 @@ or an array as query string: .. note:: - Internally, Twig uses the PHP `urlencode`_ (or `rawurlencode`_ if you pass - ``true`` as the first parameter) or the `http_build_query`_ function. Note - that as of Twig 1.16.0, ``urlencode`` **always** uses ``rawurlencode`` (the - ``raw`` argument was removed.) + Internally, Twig uses the PHP ``rawurlencode``. -.. _`urlencode`: http://php.net/urlencode .. _`rawurlencode`: http://php.net/rawurlencode -.. _`http_build_query`: http://php.net/http_build_query diff --git a/core/vendor/twig/twig/doc/functions/attribute.rst b/core/vendor/twig/twig/doc/functions/attribute.rst index ceba96b..5ba2532 100644 --- a/core/vendor/twig/twig/doc/functions/attribute.rst +++ b/core/vendor/twig/twig/doc/functions/attribute.rst @@ -1,9 +1,6 @@ ``attribute`` ============= -.. versionadded:: 1.2 - The ``attribute`` function was added in Twig 1.2. - The ``attribute`` function can be used to access a "dynamic" attribute of a variable: diff --git a/core/vendor/twig/twig/doc/functions/constant.rst b/core/vendor/twig/twig/doc/functions/constant.rst index bea0e9f..bc72e23 100644 --- a/core/vendor/twig/twig/doc/functions/constant.rst +++ b/core/vendor/twig/twig/doc/functions/constant.rst @@ -1,9 +1,6 @@ ``constant`` ============ -.. versionadded: 1.12.1 - constant now accepts object instances as the second argument. - ``constant`` returns the constant value for a given string: .. code-block:: jinja @@ -11,7 +8,7 @@ {{ some_date|date(constant('DATE_W3C')) }} {{ constant('Namespace\\Classname::CONSTANT_NAME') }} -As of 1.12.1 you can read constants from object instances as well: +You can read constants from object instances as well: .. code-block:: jinja diff --git a/core/vendor/twig/twig/doc/functions/date.rst b/core/vendor/twig/twig/doc/functions/date.rst index 714e08c..fe41385 100644 --- a/core/vendor/twig/twig/doc/functions/date.rst +++ b/core/vendor/twig/twig/doc/functions/date.rst @@ -1,12 +1,6 @@ ``date`` ======== -.. versionadded:: 1.6 - The date function has been added in Twig 1.6. - -.. versionadded:: 1.6.1 - The default timezone support has been added in Twig 1.6.1. - Converts an argument to a date to allow date comparison: .. code-block:: jinja diff --git a/core/vendor/twig/twig/doc/functions/dump.rst b/core/vendor/twig/twig/doc/functions/dump.rst index a231f08..434a3a9 100644 --- a/core/vendor/twig/twig/doc/functions/dump.rst +++ b/core/vendor/twig/twig/doc/functions/dump.rst @@ -1,9 +1,6 @@ ``dump`` ======== -.. versionadded:: 1.5 - The ``dump`` function was added in Twig 1.5. - The ``dump`` function dumps information about a template variable. This is mostly useful to debug a template that does not behave as expected by introspecting its variables: diff --git a/core/vendor/twig/twig/doc/functions/include.rst b/core/vendor/twig/twig/doc/functions/include.rst index 33bd56d..b436ea2 100644 --- a/core/vendor/twig/twig/doc/functions/include.rst +++ b/core/vendor/twig/twig/doc/functions/include.rst @@ -1,9 +1,6 @@ ``include`` =========== -.. versionadded:: 1.12 - The ``include`` function was added in Twig 1.12. - The ``include`` function returns the rendered content of a template: .. code-block:: jinja diff --git a/core/vendor/twig/twig/doc/functions/max.rst b/core/vendor/twig/twig/doc/functions/max.rst index 6f3cfc5..bf72843 100644 --- a/core/vendor/twig/twig/doc/functions/max.rst +++ b/core/vendor/twig/twig/doc/functions/max.rst @@ -1,9 +1,6 @@ ``max`` ======= -.. versionadded:: 1.15 - The ``max`` function was added in Twig 1.15. - ``max`` returns the biggest value of a sequence or a set of values: .. code-block:: jinja diff --git a/core/vendor/twig/twig/doc/functions/min.rst b/core/vendor/twig/twig/doc/functions/min.rst index 7b6a65e..3235191 100644 --- a/core/vendor/twig/twig/doc/functions/min.rst +++ b/core/vendor/twig/twig/doc/functions/min.rst @@ -1,9 +1,6 @@ ``min`` ======= -.. versionadded:: 1.15 - The ``min`` function was added in Twig 1.15. - ``min`` returns the lowest value of a sequence or a set of values: .. code-block:: jinja diff --git a/core/vendor/twig/twig/doc/functions/random.rst b/core/vendor/twig/twig/doc/functions/random.rst index 168e74f..7f2a571 100644 --- a/core/vendor/twig/twig/doc/functions/random.rst +++ b/core/vendor/twig/twig/doc/functions/random.rst @@ -1,12 +1,6 @@ ``random`` ========== -.. versionadded:: 1.5 - The ``random`` function was added in Twig 1.5. - -.. versionadded:: 1.6 - String and integer handling was added in Twig 1.6. - The ``random`` function returns a random value depending on the supplied parameter type: diff --git a/core/vendor/twig/twig/doc/functions/source.rst b/core/vendor/twig/twig/doc/functions/source.rst index 3c921b1..16601cb 100644 --- a/core/vendor/twig/twig/doc/functions/source.rst +++ b/core/vendor/twig/twig/doc/functions/source.rst @@ -1,12 +1,6 @@ ``source`` ========== -.. 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 diff --git a/core/vendor/twig/twig/doc/functions/template_from_string.rst b/core/vendor/twig/twig/doc/functions/template_from_string.rst index ce6a60d..8bc6c78 100644 --- a/core/vendor/twig/twig/doc/functions/template_from_string.rst +++ b/core/vendor/twig/twig/doc/functions/template_from_string.rst @@ -1,9 +1,6 @@ ``template_from_string`` ======================== -.. versionadded:: 1.11 - The ``template_from_string`` function was added in Twig 1.11. - The ``template_from_string`` function loads a template from a string: .. code-block:: jinja diff --git a/core/vendor/twig/twig/doc/index.rst b/core/vendor/twig/twig/doc/index.rst index 358bd73..efebcc4 100644 --- a/core/vendor/twig/twig/doc/index.rst +++ b/core/vendor/twig/twig/doc/index.rst @@ -10,7 +10,6 @@ Twig api advanced internals - deprecated recipes coding_standards tags/index diff --git a/core/vendor/twig/twig/doc/installation.rst b/core/vendor/twig/twig/doc/installation.rst index afdcf16..ce3ca7e 100644 --- a/core/vendor/twig/twig/doc/installation.rst +++ b/core/vendor/twig/twig/doc/installation.rst @@ -30,25 +30,9 @@ Installing the development version git clone git://github.com/twigphp/Twig.git -Installing the PEAR package -~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -.. note:: - - Using PEAR for installing Twig is deprecated and Twig 1.15.1 was the last - version published on the PEAR channel; use Composer instead. - -.. code-block:: bash - - pear channel-discover pear.twig-project.org - pear install twig/Twig - Installing the C extension -------------------------- -.. versionadded:: 1.4 - The C extension was added in Twig 1.4. - .. note:: The C extension is **optional** but it brings some nice performance @@ -67,17 +51,6 @@ runtime engine; install it like any other PHP extensions: make make install -.. note:: - - You can also install the C extension via PEAR (note that this method is - deprecated and newer versions of Twig are not available on the PEAR - channel): - - .. code-block:: bash - - pear channel-discover pear.twig-project.org - pear install twig/CTwig - For Windows: 1. Setup the build environment following the `PHP documentation`_ diff --git a/core/vendor/twig/twig/doc/internals.rst b/core/vendor/twig/twig/doc/internals.rst index ef1174d..288dcd4 100644 --- a/core/vendor/twig/twig/doc/internals.rst +++ b/core/vendor/twig/twig/doc/internals.rst @@ -38,7 +38,7 @@ an instance of ``Twig_Token``, and the stream is an instance of * ``Twig_Token::STRING_TYPE``: A string in an expression; * ``Twig_Token::OPERATOR_TYPE``: An operator; * ``Twig_Token::PUNCTUATION_TYPE``: A punctuation sign; -* ``Twig_Token::INTERPOLATION_START_TYPE``, ``Twig_Token::INTERPOLATION_END_TYPE`` (as of Twig 1.5): Delimiters for string interpolation; +* ``Twig_Token::INTERPOLATION_START_TYPE``, ``Twig_Token::INTERPOLATION_END_TYPE``: Delimiters for string interpolation; * ``Twig_Token::EOF_TYPE``: Ends of template. You can manually convert a source code into a token stream by calling the diff --git a/core/vendor/twig/twig/doc/intro.rst b/core/vendor/twig/twig/doc/intro.rst index 9b38c97..df33b09 100644 --- a/core/vendor/twig/twig/doc/intro.rst +++ b/core/vendor/twig/twig/doc/intro.rst @@ -28,7 +28,7 @@ Slim, Yii, Laravel, Codeigniter, and Kohana, just to name a few. Prerequisites ------------- -Twig needs at least **PHP 5.2.7** to run. +Twig needs at least **PHP 5.5.0** to run. Installation ------------ @@ -37,7 +37,7 @@ The recommended way to install Twig is via Composer: .. code-block:: bash - composer require "twig/twig:~1.0" + composer require "twig/twig:~2.0" .. note:: @@ -76,10 +76,3 @@ filesystem loader:: )); echo $twig->render('index.html', array('name' => 'Fabien')); - -.. tip:: - - If you are not using Composer, use the Twig built-in autoloader:: - - require_once '/path/to/lib/Twig/Autoloader.php'; - Twig_Autoloader::register(); diff --git a/core/vendor/twig/twig/doc/recipes.rst b/core/vendor/twig/twig/doc/recipes.rst index b863e10..2d24b85 100644 --- a/core/vendor/twig/twig/doc/recipes.rst +++ b/core/vendor/twig/twig/doc/recipes.rst @@ -6,9 +6,6 @@ Recipes Displaying Deprecation Notices ------------------------------ -.. versionadded:: 1.21 - This works as of Twig 1.21. - Deprecated features generate deprecation notices (via a call to the ``trigger_error()`` PHP function). By default, they are silenced and never displayed nor logged. @@ -161,7 +158,7 @@ syntax. But for specific projects, it can make sense to change the defaults. To change the block delimiters, you need to create your own lexer object:: - $twig = new Twig_Environment(); + $twig = new Twig_Environment(...); $lexer = new Twig_Lexer($twig, array( 'tag_comment' => array('{#', '#}'), @@ -349,7 +346,7 @@ cache:: // Compile cached file into bytecode cache if (extension_loaded('Zend OPcache') && ini_get('opcache.enable')) { - opcache_compile_file($file); + opcache_invalidate($file); } elseif (extension_loaded('apc') && ini_get('apc.enabled')) { apc_compile_file($file); } @@ -367,7 +364,7 @@ This can be easily achieved with the following code:: protected $someTemplateState = array(); - public function enterNode(Twig_NodeInterface $node, Twig_Environment $env) + public function enterNode(Twig_Node $node, Twig_Environment $env) { if ($node instanceof Twig_Node_Module) { // reset the state as we are entering a new template @@ -404,7 +401,7 @@ We have created a simple ``templates`` table that hosts two templates: Now, let's define a loader able to use this database:: - class DatabaseTwigLoader implements Twig_LoaderInterface, Twig_ExistsLoaderInterface + class DatabaseTwigLoader implements Twig_LoaderInterface { protected $dbh; @@ -422,7 +419,6 @@ Now, let's define a loader able to use this database:: return $source; } - // Twig_ExistsLoaderInterface as of Twig 1.11 public function exists($name) { return $name === $this->getValue('name', $name); @@ -485,4 +481,22 @@ logical name, and not the path from the filesystem:: Now that the ``base.twig`` templates is defined in an array loader, you can remove it from the database, and everything else will still work as before. +Rendering a Template Stored in a String +--------------------------------------- + +The ``template_from_string`` Twig function allows a template stored in a string +to be rendered from another template: + +.. code-block:: jinja + + {{ include(template_from_string("Hello {{ name }}")) }} + +Doing the same in PHP is also possible:: + + $twig = new \Twig_Environment(new \Twig_Loader_Array(array())); + + $template = $twig->createTemplate('Hello {{ name }}'); + + $rendered = $template->render(array('name' => 'Bob')); + .. _callback: http://www.php.net/manual/en/function.is-callable.php diff --git a/core/vendor/twig/twig/doc/tags/autoescape.rst b/core/vendor/twig/twig/doc/tags/autoescape.rst index 4208d1a..4887f59 100644 --- a/core/vendor/twig/twig/doc/tags/autoescape.rst +++ b/core/vendor/twig/twig/doc/tags/autoescape.rst @@ -6,8 +6,6 @@ template to be escaped or not by using the ``autoescape`` tag: .. code-block:: jinja - {# The following syntax works as of Twig 1.8 -- see the note below for previous versions #} - {% autoescape %} Everything will be automatically escaped in this block using the HTML strategy @@ -27,26 +25,6 @@ template to be escaped or not by using the ``autoescape`` tag: Everything will be outputted as is in this block {% endautoescape %} -.. note:: - - Before Twig 1.8, the syntax was different: - - .. code-block:: jinja - - {% autoescape true %} - Everything will be automatically escaped in this block - using the HTML strategy - {% endautoescape %} - - {% autoescape false %} - Everything will be outputted as is in this block - {% endautoescape %} - - {% autoescape true js %} - Everything will be automatically escaped in this block - using the js escaping strategy - {% endautoescape %} - When automatic escaping is enabled everything is escaped by default except for values explicitly marked as safe. Those can be marked in the template by using the :doc:`raw<../filters/raw>` filter: diff --git a/core/vendor/twig/twig/doc/tags/do.rst b/core/vendor/twig/twig/doc/tags/do.rst index 1c344e3..54be615 100644 --- a/core/vendor/twig/twig/doc/tags/do.rst +++ b/core/vendor/twig/twig/doc/tags/do.rst @@ -1,9 +1,6 @@ ``do`` ====== -.. versionadded:: 1.5 - The ``do`` tag was added in Twig 1.5. - The ``do`` tag works exactly like the regular variable expression (``{{ ... }}``) just that it doesn't print anything: diff --git a/core/vendor/twig/twig/doc/tags/embed.rst b/core/vendor/twig/twig/doc/tags/embed.rst index 5a6a029..ef75384 100644 --- a/core/vendor/twig/twig/doc/tags/embed.rst +++ b/core/vendor/twig/twig/doc/tags/embed.rst @@ -1,9 +1,6 @@ ``embed`` ========= -.. versionadded:: 1.8 - The ``embed`` tag was added in Twig 1.8. - The ``embed`` tag combines the behaviour of :doc:`include` and :doc:`extends`. It allows you to include another template's contents, just like ``include`` diff --git a/core/vendor/twig/twig/doc/tags/extends.rst b/core/vendor/twig/twig/doc/tags/extends.rst index 1ad2b12..99c1ba3 100644 --- a/core/vendor/twig/twig/doc/tags/extends.rst +++ b/core/vendor/twig/twig/doc/tags/extends.rst @@ -162,9 +162,6 @@ the parent template:: $twig->display('template.twig', array('layout' => $layout)); -.. versionadded:: 1.2 - The possibility to pass an array of templates has been added in Twig 1.2. - You can also provide a list of templates that are checked for existence. The first template that exists will be used as a parent: diff --git a/core/vendor/twig/twig/doc/tags/flush.rst b/core/vendor/twig/twig/doc/tags/flush.rst index 55ef593..22f09b1 100644 --- a/core/vendor/twig/twig/doc/tags/flush.rst +++ b/core/vendor/twig/twig/doc/tags/flush.rst @@ -1,9 +1,6 @@ ``flush`` ========= -.. versionadded:: 1.5 - The flush tag was added in Twig 1.5. - The ``flush`` tag tells Twig to flush the output buffer: .. code-block:: jinja diff --git a/core/vendor/twig/twig/doc/tags/for.rst b/core/vendor/twig/twig/doc/tags/for.rst index 0673b55..038ef8b 100644 --- a/core/vendor/twig/twig/doc/tags/for.rst +++ b/core/vendor/twig/twig/doc/tags/for.rst @@ -81,9 +81,6 @@ Variable Description implement the ``Countable`` interface. They are also not available when looping with a condition. -.. versionadded:: 1.2 - The ``if`` modifier support has been added in Twig 1.2. - Adding a condition ------------------ diff --git a/core/vendor/twig/twig/doc/tags/include.rst b/core/vendor/twig/twig/doc/tags/include.rst index da18dc6..b3bec69 100644 --- a/core/vendor/twig/twig/doc/tags/include.rst +++ b/core/vendor/twig/twig/doc/tags/include.rst @@ -59,9 +59,6 @@ directly:: $twig->loadTemplate('template.twig')->display(array('template' => $template)); -.. versionadded:: 1.2 - The ``ignore missing`` feature has been added in Twig 1.2. - You can mark an include with ``ignore missing`` in which case Twig will ignore the statement if the template to be included does not exist. It has to be placed just after the template name. Here some valid examples: @@ -72,9 +69,6 @@ placed just after the template name. Here some valid examples: {% include 'sidebar.html' ignore missing with {'foo': 'bar'} %} {% include 'sidebar.html' ignore missing only %} -.. versionadded:: 1.2 - The possibility to pass an array of templates has been added in Twig 1.2. - You can also provide a list of templates that are checked for existence before inclusion. The first template that exists will be included: diff --git a/core/vendor/twig/twig/doc/tags/macro.rst b/core/vendor/twig/twig/doc/tags/macro.rst index 60a1567..97cd14d 100644 --- a/core/vendor/twig/twig/doc/tags/macro.rst +++ b/core/vendor/twig/twig/doc/tags/macro.rst @@ -59,13 +59,6 @@ special ``_self`` variable to import them:

{{ forms.input('username') }}

-.. warning:: - - When you define a macro in the template where you are going to use it, you - might be tempted to call the macro directly via ``_self.input()`` instead - of importing it; even if seems to work, this is just a side-effect of the - current implementation and it won't work anymore in Twig 2.x. - When you want to use a macro in another macro from the same file, you need to import it locally: diff --git a/core/vendor/twig/twig/doc/tags/use.rst b/core/vendor/twig/twig/doc/tags/use.rst index 071b197..168cdcb 100644 --- a/core/vendor/twig/twig/doc/tags/use.rst +++ b/core/vendor/twig/twig/doc/tags/use.rst @@ -1,9 +1,6 @@ ``use`` ======= -.. versionadded:: 1.1 - Horizontal reuse was added in Twig 1.1. - .. note:: Horizontal reuse is an advanced Twig feature that is hardly ever needed in @@ -80,9 +77,6 @@ is ignored. To avoid name conflicts, you can rename imported blocks: {% block title %}{% endblock %} {% block content %}{% endblock %} -.. versionadded:: 1.3 - The ``parent()`` support was added in Twig 1.3. - The ``parent()`` function automatically determines the correct inheritance tree, so it can be used when overriding a block defined in an imported template: @@ -105,8 +99,7 @@ the ``blocks.html`` template. .. tip:: - In Twig 1.2, renaming allows you to simulate inheritance by calling the - "parent" block: + Renaming allows you to simulate inheritance by calling the "parent" block: .. code-block:: jinja diff --git a/core/vendor/twig/twig/doc/tags/verbatim.rst b/core/vendor/twig/twig/doc/tags/verbatim.rst index fe61ca1..64fef20 100644 --- a/core/vendor/twig/twig/doc/tags/verbatim.rst +++ b/core/vendor/twig/twig/doc/tags/verbatim.rst @@ -1,9 +1,6 @@ ``verbatim`` ============ -.. versionadded:: 1.12 - The ``verbatim`` tag was added in Twig 1.12 (it was named ``raw`` before). - The ``verbatim`` tag marks sections as being raw text that should not be parsed. For example to put Twig syntax as example into a template you can use this snippet: @@ -17,8 +14,3 @@ this snippet: {% endfor %} {% endverbatim %} - -.. note:: - - The ``verbatim`` tag works in the exact same way as the old ``raw`` tag, - but was renamed to avoid confusion with the ``raw`` filter. \ No newline at end of file diff --git a/core/vendor/twig/twig/doc/templates.rst b/core/vendor/twig/twig/doc/templates.rst index 2d59b1a..d90749c 100644 --- a/core/vendor/twig/twig/doc/templates.rst +++ b/core/vendor/twig/twig/doc/templates.rst @@ -127,7 +127,6 @@ Global Variables The following variables are always available in templates: -* ``_self``: references the current template (deprecated since Twig 1.20); * ``_context``: references the current context; * ``_charset``: references the current charset. @@ -198,9 +197,6 @@ built-in functions. Named Arguments --------------- -.. versionadded:: 1.12 - Support for named arguments was added in Twig 1.12. - .. code-block:: jinja {% for i in range(low=1, high=10, step=2) %} @@ -497,9 +493,6 @@ For bigger sections it makes sense to mark a block Macros ------ -.. versionadded:: 1.12 - Support for default argument values was added in Twig 1.12. - Macros are comparable with functions in regular programming languages. They are useful to reuse often used HTML fragments to not repeat yourself. @@ -576,9 +569,6 @@ even if you're not working with PHP you should feel comfortable with it. Literals ~~~~~~~~ -.. versionadded:: 1.5 - Support for hash keys as names and expressions was added in Twig 1.5. - The simplest form of expressions are literals. Literals are representations for PHP types such as strings, numbers, and arrays. The following literals exist: @@ -604,13 +594,13 @@ exist: {# keys as string #} { 'foo': 'foo', 'bar': 'bar' } - {# keys as names (equivalent to the previous hash) -- as of Twig 1.5 #} + {# keys as names (equivalent to the previous hash) #} { foo: 'foo', bar: 'bar' } {# keys as integer #} { 2: 'foo', 4: 'bar' } - {# keys as expressions (the expression must be enclosed into parentheses) -- as of Twig 1.5 #} + {# keys as expressions (the expression must be enclosed into parentheses) #} { (1 + 1): 'foo', (a ~ 'b'): 'bar' } * ``true`` / ``false``: ``true`` represents the true value, ``false`` @@ -768,9 +758,6 @@ tests. Other Operators ~~~~~~~~~~~~~~~ -.. versionadded:: 1.12.0 - Support for the extended ternary operator was added in Twig 1.12.0. - The following operators are very useful but don't fit into any of the other categories: @@ -791,17 +778,12 @@ categories: .. code-block:: jinja {{ foo ? 'yes' : 'no' }} - - {# as of Twig 1.12.0 #} {{ foo ?: 'no' }} is the same as {{ foo ? foo : 'no' }} {{ foo ? 'yes' }} is the same as {{ foo ? 'yes' : '' }} String Interpolation ~~~~~~~~~~~~~~~~~~~~ -.. versionadded:: 1.5 - String interpolation was added in Twig 1.5. - String interpolation (`#{expression}`) allows any valid expression to appear within a *double-quoted string*. The result of evaluating that expression is inserted into the string: @@ -816,9 +798,6 @@ inserted into the string: Whitespace Control ------------------ -.. versionadded:: 1.1 - Tag level whitespace control was added in Twig 1.1. - The first newline after a template tag is removed automatically (like in PHP.) Whitespace is not further modified by the template engine, so each whitespace (spaces, tabs, newlines etc.) is returned unchanged. diff --git a/core/vendor/twig/twig/doc/tests/constant.rst b/core/vendor/twig/twig/doc/tests/constant.rst index 8d0724a..79f37c1 100644 --- a/core/vendor/twig/twig/doc/tests/constant.rst +++ b/core/vendor/twig/twig/doc/tests/constant.rst @@ -1,9 +1,6 @@ ``constant`` ============ -.. versionadded: 1.13.1 - constant now accepts object instances as the second argument. - ``constant`` checks if a variable has the exact same value as a constant. You can use either global constants or class constants: diff --git a/core/vendor/twig/twig/doc/tests/divisibleby.rst b/core/vendor/twig/twig/doc/tests/divisibleby.rst index 6c693b2..a125840 100644 --- a/core/vendor/twig/twig/doc/tests/divisibleby.rst +++ b/core/vendor/twig/twig/doc/tests/divisibleby.rst @@ -1,10 +1,6 @@ ``divisible by`` ================ -.. versionadded:: 1.14.2 - The ``divisible by`` test was added in Twig 1.14.2 as an alias for - ``divisibleby``. - ``divisible by`` checks if a variable is divisible by a number: .. code-block:: jinja diff --git a/core/vendor/twig/twig/doc/tests/empty.rst b/core/vendor/twig/twig/doc/tests/empty.rst index e5b5599..71f5482 100644 --- a/core/vendor/twig/twig/doc/tests/empty.rst +++ b/core/vendor/twig/twig/doc/tests/empty.rst @@ -5,7 +5,7 @@ .. code-block:: jinja - {# evaluates to true if the foo variable is null, false, an empty array, or the empty string #} + {# evaluates to true if the foo variable is null, false, an empty array, or an empty string #} {% if foo is empty %} ... {% endif %} diff --git a/core/vendor/twig/twig/doc/tests/iterable.rst b/core/vendor/twig/twig/doc/tests/iterable.rst index 89a172f..f562ccc 100644 --- a/core/vendor/twig/twig/doc/tests/iterable.rst +++ b/core/vendor/twig/twig/doc/tests/iterable.rst @@ -1,9 +1,6 @@ ``iterable`` ============ -.. versionadded:: 1.7 - The iterable test was added in Twig 1.7. - ``iterable`` checks if a variable is an array or a traversable object: .. code-block:: jinja diff --git a/core/vendor/twig/twig/doc/tests/sameas.rst b/core/vendor/twig/twig/doc/tests/sameas.rst index 16f904d..e4151ca 100644 --- a/core/vendor/twig/twig/doc/tests/sameas.rst +++ b/core/vendor/twig/twig/doc/tests/sameas.rst @@ -1,9 +1,6 @@ ``same as`` =========== -.. versionadded:: 1.14.2 - The ``same as`` test was added in Twig 1.14.2 as an alias for ``sameas``. - ``same as`` checks if a variable is the same as another variable. This is the equivalent to ``===`` in PHP: diff --git a/core/vendor/twig/twig/ext/twig/php_twig.h b/core/vendor/twig/twig/ext/twig/php_twig.h index 0423b1d..b06c494 100644 --- a/core/vendor/twig/twig/ext/twig/php_twig.h +++ b/core/vendor/twig/twig/ext/twig/php_twig.h @@ -15,7 +15,7 @@ #ifndef PHP_TWIG_H #define PHP_TWIG_H -#define PHP_TWIG_VERSION "1.21.1" +#define PHP_TWIG_VERSION "2.0.0-DEV" #include "php.h" diff --git a/core/vendor/twig/twig/ext/twig/twig.c b/core/vendor/twig/twig/ext/twig/twig.c index 92d1add..3700f66 100644 --- a/core/vendor/twig/twig/ext/twig/twig.c +++ b/core/vendor/twig/twig/ext/twig/twig.c @@ -609,7 +609,6 @@ 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) { - zend_class_entry *ce; zval *retval; char *item; size_t item_len; @@ -620,23 +619,12 @@ static int twig_add_method_to_class(void *pDest APPLY_TSRMLS_DC, int num_args, v return 0; } - ce = *va_arg(args, zend_class_entry**); retval = va_arg(args, zval*); item_len = strlen(mptr->common.function_name); item = estrndup(mptr->common.function_name, item_len); php_strtolower(item, item_len); - if (strcmp("getenvironment", item) == 0) { - zend_class_entry **twig_template_ce; - if (zend_lookup_class("Twig_Template", strlen("Twig_Template"), &twig_template_ce TSRMLS_CC) == FAILURE) { - return 0; - } - if (instanceof_function(ce, *twig_template_ce TSRMLS_CC)) { - return 0; - } - } - add_assoc_stringl_ex(retval, item, item_len+1, item, item_len, 0); return 0; @@ -682,7 +670,7 @@ static void twig_add_class_to_cache(zval *cache, zval *object, char *class_name array_init(class_methods); array_init(class_properties); // add all methods to self::cache[$class]['methods'] - zend_hash_apply_with_arguments(&class_ce->function_table APPLY_TSRMLS_CC, twig_add_method_to_class, 2, &class_ce, class_methods); + zend_hash_apply_with_arguments(&class_ce->function_table APPLY_TSRMLS_CC, twig_add_method_to_class, 1, class_methods); zend_hash_apply_with_arguments(&class_ce->properties_info APPLY_TSRMLS_CC, twig_add_property_to_class, 2, &class_ce, class_properties); add_assoc_zval(class_info, "methods", class_methods); @@ -956,12 +944,7 @@ PHP_FUNCTION(twig_template_get_attributes) $methods = array(); foreach ($ref->getMethods(ReflectionMethod::IS_PUBLIC) as $refMethod) { - $methodName = strtolower($refMethod->name); - - // Accessing the environment from templates is forbidden to prevent untrusted changes to the environment - if ('getenvironment' !== $methodName) { - $methods[$methodName] = true; - } + $methods[strtolower($refMethod->name)] = true; } self::$cache[$class]['methods'] = $methods; @@ -1098,7 +1081,7 @@ PHP_FUNCTION(twig_template_get_attributes) /* // useful when calling a template method from a template // this is not supported but unfortunately heavily used in the Symfony profiler - if ($object instanceof Twig_TemplateInterface) { + if ($object instanceof Twig_Template) { return $ret === '' ? '' : new Twig_Markup($ret, $this->env->getCharset()); } @@ -1107,7 +1090,7 @@ PHP_FUNCTION(twig_template_get_attributes) efree(item); // ret can be null, if e.g. the called method throws an exception if (ret) { - if (TWIG_INSTANCE_OF_USERLAND(object, "Twig_TemplateInterface" TSRMLS_CC)) { + if (TWIG_INSTANCE_OF_USERLAND(object, "Twig_Template" TSRMLS_CC)) { if (Z_STRLEN_P(ret) != 0) { zval *charset = TWIG_CALL_USER_FUNC_ARRAY(TWIG_PROPERTY_CHAR(template, "env" TSRMLS_CC), "getCharset", NULL TSRMLS_CC); TWIG_NEW(return_value, "Twig_Markup", ret, charset TSRMLS_CC); diff --git a/core/vendor/twig/twig/lib/Twig/Autoloader.php b/core/vendor/twig/twig/lib/Twig/Autoloader.php deleted file mode 100644 index d47583f..0000000 --- a/core/vendor/twig/twig/lib/Twig/Autoloader.php +++ /dev/null @@ -1,54 +0,0 @@ - - * - * @deprecated Use Composer instead. Will be removed in Twig 2.0. - */ -class Twig_Autoloader -{ - /** - * Registers Twig_Autoloader as an SPL autoloader. - * - * @param bool $prepend Whether to prepend the autoloader or not. - */ - public static function register($prepend = false) - { - @trigger_error('Using Twig_Autoloader is deprecated. Use Composer instead.', E_USER_DEPRECATED); - - if (PHP_VERSION_ID < 50300) { - spl_autoload_register(array(__CLASS__, 'autoload')); - } else { - spl_autoload_register(array(__CLASS__, 'autoload'), true, $prepend); - } - } - - /** - * Handles autoloading of classes. - * - * @param string $class A class name. - */ - public static function autoload($class) - { - if (0 !== strpos($class, 'Twig')) { - return; - } - - if (is_file($file = dirname(__FILE__).'/../'.str_replace(array('_', "\0"), array('/', ''), $class).'.php')) { - require $file; - } - } -} diff --git a/core/vendor/twig/twig/lib/Twig/BaseNodeVisitor.php b/core/vendor/twig/twig/lib/Twig/BaseNodeVisitor.php index 3c6ef66..9ba3342 100644 --- a/core/vendor/twig/twig/lib/Twig/BaseNodeVisitor.php +++ b/core/vendor/twig/twig/lib/Twig/BaseNodeVisitor.php @@ -19,24 +19,16 @@ /** * {@inheritdoc} */ - final public function enterNode(Twig_NodeInterface $node, Twig_Environment $env) + final public function enterNode(Twig_Node $node, Twig_Environment $env) { - if (!$node instanceof Twig_Node) { - throw new LogicException('Twig_BaseNodeVisitor only supports Twig_Node instances.'); - } - return $this->doEnterNode($node, $env); } /** * {@inheritdoc} */ - final public function leaveNode(Twig_NodeInterface $node, Twig_Environment $env) + final public function leaveNode(Twig_Node $node, Twig_Environment $env) { - if (!$node instanceof Twig_Node) { - throw new LogicException('Twig_BaseNodeVisitor only supports Twig_Node instances.'); - } - return $this->doLeaveNode($node, $env); } diff --git a/core/vendor/twig/twig/lib/Twig/Compiler.php b/core/vendor/twig/twig/lib/Twig/Compiler.php index abea3aa..0636f1b 100644 --- a/core/vendor/twig/twig/lib/Twig/Compiler.php +++ b/core/vendor/twig/twig/lib/Twig/Compiler.php @@ -15,16 +15,16 @@ * * @author Fabien Potencier */ -class Twig_Compiler implements Twig_CompilerInterface +class Twig_Compiler { - protected $lastLine; - protected $source; - protected $indentation; - protected $env; - protected $debugInfo = array(); - protected $sourceOffset; - protected $sourceLine; - protected $filename; + private $lastLine; + private $source; + private $indentation; + private $env; + private $debugInfo = array(); + private $sourceOffset; + private $sourceLine; + private $filename; /** * Constructor. @@ -64,12 +64,12 @@ public function getSource() /** * Compiles a node. * - * @param Twig_NodeInterface $node The node to compile - * @param int $indentation The current indentation + * @param Twig_Node $node The node to compile + * @param int $indentation The current indentation * * @return Twig_Compiler The current compiler instance */ - public function compile(Twig_NodeInterface $node, $indentation = 0) + public function compile(Twig_Node $node, $indentation = 0) { $this->lastLine = null; $this->source = ''; @@ -88,7 +88,7 @@ public function compile(Twig_NodeInterface $node, $indentation = 0) return $this; } - public function subcompile(Twig_NodeInterface $node, $raw = true) + public function subcompile(Twig_Node $node, $raw = true) { if (false === $raw) { $this->addIndentation(); @@ -201,11 +201,11 @@ public function repr($value) /** * Adds debugging information. * - * @param Twig_NodeInterface $node The related twig node + * @param Twig_Node $node The related twig node * * @return Twig_Compiler The current compiler instance */ - public function addDebugInfo(Twig_NodeInterface $node) + public function addDebugInfo(Twig_Node $node) { if ($node->getLine() != $this->lastLine) { $this->write(sprintf("// line %d\n", $node->getLine())); diff --git a/core/vendor/twig/twig/lib/Twig/CompilerInterface.php b/core/vendor/twig/twig/lib/Twig/CompilerInterface.php deleted file mode 100644 index 272c767..0000000 --- a/core/vendor/twig/twig/lib/Twig/CompilerInterface.php +++ /dev/null @@ -1,36 +0,0 @@ - - * - * @deprecated since 1.12 (to be removed in 3.0) - */ -interface Twig_CompilerInterface -{ - /** - * Compiles a node. - * - * @param Twig_NodeInterface $node The node to compile - * - * @return Twig_CompilerInterface The current compiler instance - */ - public function compile(Twig_NodeInterface $node); - - /** - * Gets the current PHP code after compilation. - * - * @return string The PHP code - */ - public function getSource(); -} diff --git a/core/vendor/twig/twig/lib/Twig/Environment.php b/core/vendor/twig/twig/lib/Twig/Environment.php index 7687d5b..79726ec 100644 --- a/core/vendor/twig/twig/lib/Twig/Environment.php +++ b/core/vendor/twig/twig/lib/Twig/Environment.php @@ -16,34 +16,34 @@ */ class Twig_Environment { - const VERSION = '1.21.1'; - - protected $charset; - protected $loader; - protected $debug; - protected $autoReload; - protected $cache; - protected $lexer; - protected $parser; - protected $compiler; - protected $baseTemplateClass; - protected $extensions; - protected $parsers; - protected $visitors; - protected $filters; - protected $tests; - protected $functions; - protected $globals; - protected $runtimeInitialized = false; - protected $extensionInitialized = false; - protected $loadedTemplates; - protected $strictVariables; - protected $unaryOperators; - protected $binaryOperators; - protected $templateClassPrefix = '__TwigTemplate_'; - protected $functionCallbacks = array(); - protected $filterCallbacks = array(); - protected $staging; + const VERSION = '2.0.0-DEV'; + + private $charset; + private $loader; + private $debug; + private $autoReload; + private $cache; + private $lexer; + private $parser; + private $compiler; + private $baseTemplateClass; + private $extensions; + private $parsers; + private $visitors; + private $filters; + private $tests; + private $functions; + private $globals; + private $runtimeInitialized = false; + private $extensionInitialized = false; + private $loadedTemplates; + private $strictVariables; + private $unaryOperators; + private $binaryOperators; + private $templateClassPrefix = '__TwigTemplate_'; + private $functionCallbacks = array(); + private $filterCallbacks = array(); + private $staging; /** * Constructor. @@ -70,7 +70,6 @@ class Twig_Environment * * * autoescape: Whether to enable auto-escaping (default to html): * * 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" @@ -82,13 +81,9 @@ class Twig_Environment * @param Twig_LoaderInterface $loader A Twig_LoaderInterface instance * @param array $options An array of options */ - public function __construct(Twig_LoaderInterface $loader = null, $options = array()) + public function __construct(Twig_LoaderInterface $loader, $options = array()) { - if (null !== $loader) { - $this->setLoader($loader); - } else { - @trigger_error('Not passing a Twig_LoaderInterface as the first constructor argument of Twig_Environment is deprecated.', E_USER_DEPRECATED); - } + $this->setLoader($loader); $options = array_merge(array( 'debug' => false, @@ -312,7 +307,7 @@ public function display($name, array $context = array()) * @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 + * @return Twig_Template A template instance representing the given template name * * @throws Twig_Error_Loader When the template cannot be found * @throws Twig_Error_Syntax When an error occurred during compilation @@ -368,12 +363,9 @@ public function createTemplate($template) $this->setLoader($loader); try { $template = $this->loadTemplate($name); - } catch (Exception $e) { + } finally { $this->setLoader($current); - - throw $e; } - $this->setLoader($current); return $template; } @@ -405,7 +397,7 @@ public function isTemplateFresh($name, $time) /** * Tries to load a template consecutively from an array. * - * Similar to loadTemplate() but it also accepts Twig_TemplateInterface instances and an array + * Similar to loadTemplate() but it also accepts Twig_Template instances and an array * of templates where each is tried to be loaded. * * @param string|Twig_Template|array $names A template or an array of templates to try consecutively @@ -440,18 +432,6 @@ public function resolveTemplate($names) } /** - * Clears the internal template cache. - * - * @deprecated since 1.18.3 (to be removed in 2.0) - */ - public function clearTemplateCache() - { - @trigger_error(sprintf('The %s method is deprecated and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED); - - $this->loadedTemplates = array(); - } - - /** * Clears the template cache files on the filesystem. */ public function clearCacheFiles() @@ -470,7 +450,7 @@ public function clearCacheFiles() /** * Gets the Lexer instance. * - * @return Twig_LexerInterface A Twig_LexerInterface instance + * @return Twig_Lexer A Twig_Lexer instance */ public function getLexer() { @@ -484,9 +464,9 @@ public function getLexer() /** * Sets the Lexer instance. * - * @param Twig_LexerInterface $lexer A Twig_LexerInterface instance + * @param Twig_Lexer $lexer A Twig_Lexer instance */ - public function setLexer(Twig_LexerInterface $lexer) + public function setLexer(Twig_Lexer $lexer) { $this->lexer = $lexer; } @@ -509,7 +489,7 @@ public function tokenize($source, $name = null) /** * Gets the Parser instance. * - * @return Twig_ParserInterface A Twig_ParserInterface instance + * @return Twig_Parser A Twig_Parser instance */ public function getParser() { @@ -523,9 +503,9 @@ public function getParser() /** * Sets the Parser instance. * - * @param Twig_ParserInterface $parser A Twig_ParserInterface instance + * @param Twig_Parser $parser A Twig_Parser instance */ - public function setParser(Twig_ParserInterface $parser) + public function setParser(Twig_Parser $parser) { $this->parser = $parser; } @@ -547,7 +527,7 @@ public function parse(Twig_TokenStream $stream) /** * Gets the Compiler instance. * - * @return Twig_CompilerInterface A Twig_CompilerInterface instance + * @return Twig_Compiler A Twig_Compiler instance */ public function getCompiler() { @@ -561,9 +541,9 @@ public function getCompiler() /** * Sets the Compiler instance. * - * @param Twig_CompilerInterface $compiler A Twig_CompilerInterface instance + * @param Twig_Compiler $compiler A Twig_Compiler instance */ - public function setCompiler(Twig_CompilerInterface $compiler) + public function setCompiler(Twig_Compiler $compiler) { $this->compiler = $compiler; } @@ -571,11 +551,11 @@ public function setCompiler(Twig_CompilerInterface $compiler) /** * Compiles a node and returns the PHP code. * - * @param Twig_NodeInterface $node A Twig_NodeInterface instance + * @param Twig_Node $node A Twig_Node instance * * @return string The compiled PHP source code */ - public function compile(Twig_NodeInterface $node) + public function compile(Twig_Node $node) { return $this->getCompiler()->compile($node)->getSource(); } @@ -619,10 +599,6 @@ public function setLoader(Twig_LoaderInterface $loader) */ public function getLoader() { - if (null === $this->loader) { - throw new LogicException('You must set a loader first.'); - } - return $this->loader; } @@ -701,26 +677,6 @@ public function addExtension(Twig_ExtensionInterface $extension) } /** - * Removes an extension by name. - * - * This method is deprecated and you should not use it. - * - * @param string $name The extension name - * - * @deprecated since 1.12 (to be removed in 2.0) - */ - public function removeExtension($name) - { - @trigger_error(sprintf('The %s method is deprecated and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED); - - if ($this->extensionInitialized) { - throw new LogicException(sprintf('Unable to remove extension "%s" as extensions have already been initialized.', $name)); - } - - unset($this->extensions[$name]); - } - - /** * Registers an array of extensions. * * @param array $extensions An array of extensions @@ -759,7 +715,7 @@ public function addTokenParser(Twig_TokenParserInterface $parser) /** * Gets the registered Token Parsers. * - * @return Twig_TokenParserBrokerInterface A broker containing token parsers + * @return Twig_TokenParserInterface[] An array of Twig_TokenParserInterface */ public function getTokenParsers() { @@ -773,17 +729,13 @@ public function getTokenParsers() /** * Gets registered tags. * - * Be warned that this method cannot return tags defined by Twig_TokenParserBrokerInterface classes. - * * @return Twig_TokenParserInterface[] An array of Twig_TokenParserInterface instances */ public function getTags() { $tags = array(); - foreach ($this->getTokenParsers()->getParsers() as $parser) { - if ($parser instanceof Twig_TokenParserInterface) { - $tags[$parser->getTag()] = $parser; - } + foreach ($this->getTokenParsers() as $parser) { + $tags[$parser->getTag()] = $parser; } return $tags; @@ -820,27 +772,15 @@ public function getNodeVisitors() /** * Registers a Filter. * - * @param string|Twig_SimpleFilter $name The filter name or a Twig_SimpleFilter instance - * @param Twig_FilterInterface|Twig_SimpleFilter $filter A Twig_FilterInterface instance or a Twig_SimpleFilter instance + * @param Twig_Filter $filter A Twig_Filter instance */ - public function addFilter($name, $filter = null) + public function addFilter(Twig_Filter $filter) { - if (!$name instanceof Twig_SimpleFilter && !($filter instanceof Twig_SimpleFilter || $filter instanceof Twig_FilterInterface)) { - throw new LogicException('A filter must be an instance of Twig_FilterInterface or Twig_SimpleFilter'); - } - - if ($name instanceof Twig_SimpleFilter) { - $filter = $name; - $name = $filter->getName(); - } else { - @trigger_error(sprintf('Passing a name as a first argument to the %s method is deprecated. Pass an instance of "Twig_SimpleFilter" instead when defining filter "%s".', __METHOD__, $name), E_USER_DEPRECATED); - } - if ($this->extensionInitialized) { - throw new LogicException(sprintf('Unable to add filter "%s" as extensions have already been initialized.', $name)); + throw new LogicException(sprintf('Unable to add filter "%s" as extensions have already been initialized.', $filter->getName())); } - $this->staging->addFilter($name, $filter); + $this->staging->addFilter($filter); } /** @@ -877,7 +817,7 @@ public function getFilter($name) } foreach ($this->filterCallbacks as $callback) { - if (false !== $filter = call_user_func($callback, $name)) { + if (false !== $filter = $callback($name)) { return $filter; } } @@ -885,7 +825,7 @@ public function getFilter($name) return false; } - public function registerUndefinedFilterCallback($callable) + public function registerUndefinedFilterCallback(callable $callable) { $this->filterCallbacks[] = $callable; } @@ -895,7 +835,7 @@ public function registerUndefinedFilterCallback($callable) * * Be warned that this method cannot return filters defined with registerUndefinedFunctionCallback. * - * @return Twig_FilterInterface[] An array of Twig_FilterInterface instances + * @return Twig_Filter[] An array of Twig_Filter instances * * @see registerUndefinedFilterCallback */ @@ -911,33 +851,21 @@ public function getFilters() /** * Registers a Test. * - * @param string|Twig_SimpleTest $name The test name or a Twig_SimpleTest instance - * @param Twig_TestInterface|Twig_SimpleTest $test A Twig_TestInterface instance or a Twig_SimpleTest instance + * @param Twig_Test $test A Twig_Test instance */ - public function addTest($name, $test = null) + public function addTest(Twig_Test $test) { - if (!$name instanceof Twig_SimpleTest && !($test instanceof Twig_SimpleTest || $test instanceof Twig_TestInterface)) { - throw new LogicException('A test must be an instance of Twig_TestInterface or Twig_SimpleTest'); - } - - if ($name instanceof Twig_SimpleTest) { - $test = $name; - $name = $test->getName(); - } else { - @trigger_error(sprintf('Passing a name as a first argument to the %s method is deprecated. Pass an instance of "Twig_SimpleTest" instead when defining test "%s".', __METHOD__, $name), E_USER_DEPRECATED); - } - if ($this->extensionInitialized) { - throw new LogicException(sprintf('Unable to add test "%s" as extensions have already been initialized.', $name)); + throw new LogicException(sprintf('Unable to add test "%s" as extensions have already been initialized.', $test->getName())); } - $this->staging->addTest($name, $test); + $this->staging->addTest($test); } /** * Gets the registered Tests. * - * @return Twig_TestInterface[] An array of Twig_TestInterface instances + * @return Twig_Test[] An array of Twig_Test instances */ public function getTests() { @@ -971,27 +899,15 @@ public function getTest($name) /** * Registers a Function. * - * @param string|Twig_SimpleFunction $name The function name or a Twig_SimpleFunction instance - * @param Twig_FunctionInterface|Twig_SimpleFunction $function A Twig_FunctionInterface instance or a Twig_SimpleFunction instance + * @param Twig_Function $function A Twig_Function instance */ - public function addFunction($name, $function = null) + public function addFunction(Twig_Function $function) { - if (!$name instanceof Twig_SimpleFunction && !($function instanceof Twig_SimpleFunction || $function instanceof Twig_FunctionInterface)) { - throw new LogicException('A function must be an instance of Twig_FunctionInterface or Twig_SimpleFunction'); - } - - if ($name instanceof Twig_SimpleFunction) { - $function = $name; - $name = $function->getName(); - } else { - @trigger_error(sprintf('Passing a name as a first argument to the %s method is deprecated. Pass an instance of "Twig_SimpleFunction" instead when defining function "%s".', __METHOD__, $name), E_USER_DEPRECATED); - } - if ($this->extensionInitialized) { - throw new LogicException(sprintf('Unable to add function "%s" as extensions have already been initialized.', $name)); + throw new LogicException(sprintf('Unable to add function "%s" as extensions have already been initialized.', $function->getName())); } - $this->staging->addFunction($name, $function); + $this->staging->addFunction($function); } /** @@ -1028,7 +944,7 @@ public function getFunction($name) } foreach ($this->functionCallbacks as $callback) { - if (false !== $function = call_user_func($callback, $name)) { + if (false !== $function = $callback($name)) { return $function; } } @@ -1036,7 +952,7 @@ public function getFunction($name) return false; } - public function registerUndefinedFunctionCallback($callable) + public function registerUndefinedFunctionCallback(callable $callable) { $this->functionCallbacks[] = $callable; } @@ -1046,7 +962,7 @@ public function registerUndefinedFunctionCallback($callable) * * Be warned that this method cannot return functions defined with registerUndefinedFunctionCallback. * - * @return Twig_FunctionInterface[] An array of Twig_FunctionInterface instances + * @return Twig_Function[] An array of Twig_Function instances * * @see registerUndefinedFunctionCallback */ @@ -1076,9 +992,7 @@ public function addGlobal($name, $value) } if (!array_key_exists($name, $this->globals)) { - // The deprecation notice must be turned into the following exception in Twig 2.0 - @trigger_error(sprintf('Registering global variable "%s" at runtime or when the extensions have already been initialized is deprecated.', $name), E_USER_DEPRECATED); - //throw new LogicException(sprintf('Unable to add global "%s" as the runtime or the extensions have already been initialized.', $name)); + throw new LogicException(sprintf('Unable to add global "%s" as the runtime or the extensions have already been initialized.', $name)); } } @@ -1170,7 +1084,7 @@ public function computeAlternatives($name, $items) return array_keys($alternatives); } - protected function initGlobals() + private function initGlobals() { $globals = array(); foreach ($this->extensions as $extension) { @@ -1187,14 +1101,14 @@ protected function initGlobals() return call_user_func_array('array_merge', $globals); } - protected function initExtensions() + private function initExtensions() { if ($this->extensionInitialized) { return; } $this->extensionInitialized = true; - $this->parsers = new Twig_TokenParserBroker(array(), array(), false); + $this->parsers = array(); $this->filters = array(); $this->functions = array(); $this->tests = array(); @@ -1208,52 +1122,30 @@ protected function initExtensions() $this->initExtension($this->staging); } - protected function initExtension(Twig_ExtensionInterface $extension) + private function initExtension(Twig_ExtensionInterface $extension) { // filters - foreach ($extension->getFilters() as $name => $filter) { - if ($filter instanceof Twig_SimpleFilter) { - $name = $filter->getName(); - } else { - @trigger_error(sprintf('Using an instance of "%s" for filter "%s" is deprecated. Use Twig_SimpleFilter instead.', get_class($filter), $name), E_USER_DEPRECATED); - } - - $this->filters[$name] = $filter; + foreach ($extension->getFilters() as $filter) { + $this->filters[$filter->getName()] = $filter; } // functions - foreach ($extension->getFunctions() as $name => $function) { - if ($function instanceof Twig_SimpleFunction) { - $name = $function->getName(); - } else { - @trigger_error(sprintf('Using an instance of "%s" for function "%s" is deprecated. Use Twig_SimpleFunction instead.', get_class($function), $name), E_USER_DEPRECATED); - } - - $this->functions[$name] = $function; + foreach ($extension->getFunctions() as $function) { + $this->functions[$function->getName()] = $function; } // tests - foreach ($extension->getTests() as $name => $test) { - if ($test instanceof Twig_SimpleTest) { - $name = $test->getName(); - } else { - @trigger_error(sprintf('Using an instance of "%s" for test "%s" is deprecated. Use Twig_SimpleTest instead.', get_class($test), $name), E_USER_DEPRECATED); - } - - $this->tests[$name] = $test; + foreach ($extension->getTests() as $test) { + $this->tests[$test->getName()] = $test; } // token parsers foreach ($extension->getTokenParsers() as $parser) { - if ($parser instanceof Twig_TokenParserInterface) { - $this->parsers->addTokenParser($parser); - } elseif ($parser instanceof Twig_TokenParserBrokerInterface) { - @trigger_error('Registering a Twig_TokenParserBrokerInterface instance is deprecated.', E_USER_DEPRECATED); - - $this->parsers->addTokenParserBroker($parser); - } else { - throw new LogicException('getTokenParsers() must return an array of Twig_TokenParserInterface or Twig_TokenParserBrokerInterface instances'); + if (!$parser instanceof Twig_TokenParserInterface) { + throw new LogicException('getTokenParsers() must return an array of Twig_TokenParserInterface'); } + + $this->parsers[] = $parser; } // node visitors diff --git a/core/vendor/twig/twig/lib/Twig/Error.php b/core/vendor/twig/twig/lib/Twig/Error.php index 90650c5..6aa1f7a 100644 --- a/core/vendor/twig/twig/lib/Twig/Error.php +++ b/core/vendor/twig/twig/lib/Twig/Error.php @@ -33,10 +33,9 @@ */ class Twig_Error extends Exception { - protected $lineno; - protected $filename; - protected $rawMessage; - protected $previous; + private $lineno; + private $filename; + private $rawMessage; /** * Constructor. @@ -57,12 +56,7 @@ class Twig_Error extends Exception */ public function __construct($message, $lineno = -1, $filename = null, Exception $previous = null) { - if (PHP_VERSION_ID < 50300) { - $this->previous = $previous; - parent::__construct(''); - } else { - parent::__construct('', 0, $previous); - } + parent::__construct('', 0, $previous); $this->lineno = $lineno; $this->filename = $filename; @@ -136,26 +130,7 @@ public function guess() $this->updateRepr(); } - /** - * For PHP < 5.3.0, provides access to the getPrevious() method. - * - * @param string $method The method name - * @param array $arguments The parameters to be passed to the method - * - * @return Exception The previous exception or null - * - * @throws BadMethodCallException - */ - public function __call($method, $arguments) - { - if ('getprevious' == strtolower($method)) { - return $this->previous; - } - - throw new BadMethodCallException(sprintf('Method "Twig_Error::%s()" does not exist.', $method)); - } - - protected function updateRepr() + private function updateRepr() { $this->message = $this->rawMessage; @@ -183,17 +158,12 @@ protected function updateRepr() } } - protected function guessTemplateInfo() + private function guessTemplateInfo() { $template = null; $templateClass = null; - if (PHP_VERSION_ID >= 50306) { - $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT); - } else { - $backtrace = debug_backtrace(); - } - + $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT); foreach ($backtrace as $trace) { if (isset($trace['object']) && $trace['object'] instanceof Twig_Template && 'Twig_Template' !== get_class($trace['object'])) { $currentClass = get_class($trace['object']); @@ -223,7 +193,7 @@ protected function guessTemplateInfo() } $exceptions = array($e = $this); - while (($e instanceof self || method_exists($e, 'getPrevious')) && $e = $e->getPrevious()) { + while ($e = $e->getPrevious()) { $exceptions[] = $e; } diff --git a/core/vendor/twig/twig/lib/Twig/ExistsLoaderInterface.php b/core/vendor/twig/twig/lib/Twig/ExistsLoaderInterface.php index b168c3c..a4fb500 100644 --- a/core/vendor/twig/twig/lib/Twig/ExistsLoaderInterface.php +++ b/core/vendor/twig/twig/lib/Twig/ExistsLoaderInterface.php @@ -10,20 +10,10 @@ */ /** - * Adds an exists() method for loaders. + * Empty interface for Twig 1.x compatibility. * - * @author Florin Patan - * - * @deprecated since 1.12 (to be removed in 3.0) + * @deprecated to be removed in 3.0 */ -interface Twig_ExistsLoaderInterface +interface Twig_ExistsLoaderInterface extends Twig_LoaderInterface { - /** - * Check if we have the source code of a template, given its name. - * - * @param string $name The name of the template to check if we can load - * - * @return bool If the template source code is handled by this loader or not - */ - public function exists($name); } diff --git a/core/vendor/twig/twig/lib/Twig/ExpressionParser.php b/core/vendor/twig/twig/lib/Twig/ExpressionParser.php index 085588c..675fdb2 100644 --- a/core/vendor/twig/twig/lib/Twig/ExpressionParser.php +++ b/core/vendor/twig/twig/lib/Twig/ExpressionParser.php @@ -25,9 +25,9 @@ class Twig_ExpressionParser const OPERATOR_LEFT = 1; const OPERATOR_RIGHT = 2; - protected $parser; - protected $unaryOperators; - protected $binaryOperators; + private $parser; + private $unaryOperators; + private $binaryOperators; public function __construct(Twig_Parser $parser, array $unaryOperators, array $binaryOperators) { @@ -45,7 +45,7 @@ public function parseExpression($precedence = 0) $this->parser->getStream()->next(); if (isset($op['callable'])) { - $expr = call_user_func($op['callable'], $this->parser, $expr); + $expr = $op['callable']($this->parser, $expr); } else { $expr1 = $this->parseExpression(self::OPERATOR_LEFT === $op['associativity'] ? $op['precedence'] + 1 : $op['precedence']); $class = $op['class']; @@ -62,7 +62,7 @@ public function parseExpression($precedence = 0) return $expr; } - protected function getPrimary() + private function getPrimary() { $token = $this->parser->getCurrentToken(); @@ -84,7 +84,7 @@ protected function getPrimary() return $this->parsePrimaryExpression(); } - protected function parseConditionalExpression($expr) + private function parseConditionalExpression($expr) { while ($this->parser->getStream()->nextIf(Twig_Token::PUNCTUATION_TYPE, '?')) { if (!$this->parser->getStream()->nextIf(Twig_Token::PUNCTUATION_TYPE, ':')) { @@ -105,12 +105,12 @@ protected function parseConditionalExpression($expr) return $expr; } - protected function isUnary(Twig_Token $token) + private function isUnary(Twig_Token $token) { return $token->test(Twig_Token::OPERATOR_TYPE) && isset($this->unaryOperators[$token->getValue()]); } - protected function isBinary(Twig_Token $token) + private function isBinary(Twig_Token $token) { return $token->test(Twig_Token::OPERATOR_TYPE) && isset($this->binaryOperators[$token->getValue()]); } @@ -373,7 +373,7 @@ public function parseSubscriptExpression($node) $arg = new Twig_Node_Expression_Constant($token->getValue(), $lineno); if ($stream->test(Twig_Token::PUNCTUATION_TYPE, '(')) { - $type = Twig_TemplateInterface::METHOD_CALL; + $type = Twig_Template::METHOD_CALL; foreach ($this->parseArguments() as $n) { $arguments->addElement($n); } @@ -389,11 +389,7 @@ public function parseSubscriptExpression($node) $name = $arg->getAttribute('value'); - if ($this->parser->isReservedMacroName($name)) { - throw new Twig_Error_Syntax(sprintf('"%s" cannot be called as macro as it is a reserved keyword', $name), $token->getLine(), $this->parser->getFilename()); - } - - $node = new Twig_Node_Expression_MethodCall($node, 'get'.$name, $arguments, $lineno); + $node = new Twig_Node_Expression_MethodCall($node, 'macro_'.$name, $arguments, $lineno); $node->setAttribute('safe', true); return $node; @@ -565,7 +561,7 @@ public function parseMultitargetExpression() return new Twig_Node($targets); } - protected function getFunctionNodeClass($name, $line) + private function getFunctionNodeClass($name, $line) { $env = $this->parser->getEnvironment(); @@ -578,9 +574,9 @@ protected function getFunctionNodeClass($name, $line) throw new Twig_Error_Syntax($message, $line, $this->parser->getFilename()); } - if ($function instanceof Twig_SimpleFunction && $function->isDeprecated()) { + if ($function->isDeprecated()) { $message = sprintf('Twig Function "%s" is deprecated', $function->getName()); - if ($test->getAlternative()) { + if ($function->getAlternative()) { $message .= sprintf('. Use "%s" instead', $function->getAlternative()); } $message .= sprintf(' in %s at line %d.', $this->parser->getFilename(), $line); @@ -588,14 +584,10 @@ protected function getFunctionNodeClass($name, $line) @trigger_error($message, E_USER_DEPRECATED); } - if ($function instanceof Twig_SimpleFunction) { - return $function->getNodeClass(); - } - - return $function instanceof Twig_Function_Node ? $function->getClass() : 'Twig_Node_Expression_Function'; + return $function->getNodeClass(); } - protected function getFilterNodeClass($name, $line) + private function getFilterNodeClass($name, $line) { $env = $this->parser->getEnvironment(); @@ -608,9 +600,9 @@ protected function getFilterNodeClass($name, $line) throw new Twig_Error_Syntax($message, $line, $this->parser->getFilename()); } - if ($filter instanceof Twig_SimpleFilter && $filter->isDeprecated()) { + if ($filter->isDeprecated()) { $message = sprintf('Twig Filter "%s" is deprecated', $filter->getName()); - if ($test->getAlternative()) { + if ($filter->getAlternative()) { $message .= sprintf('. Use "%s" instead', $filter->getAlternative()); } $message .= sprintf(' in %s at line %d.', $this->parser->getFilename(), $line); @@ -618,15 +610,11 @@ protected function getFilterNodeClass($name, $line) @trigger_error($message, E_USER_DEPRECATED); } - if ($filter instanceof Twig_SimpleFilter) { - return $filter->getNodeClass(); - } - - return $filter instanceof Twig_Filter_Node ? $filter->getClass() : 'Twig_Node_Expression_Filter'; + return $filter->getNodeClass(); } // checks that the node only contains "constant" elements - protected function checkConstantExpression(Twig_NodeInterface $node) + private function checkConstantExpression(Twig_Node $node) { if (!($node instanceof Twig_Node_Expression_Constant || $node instanceof Twig_Node_Expression_Array || $node instanceof Twig_Node_Expression_Unary_Neg || $node instanceof Twig_Node_Expression_Unary_Pos diff --git a/core/vendor/twig/twig/lib/Twig/Extension.php b/core/vendor/twig/twig/lib/Twig/Extension.php index 5c8ad5c..5d3f0bc 100644 --- a/core/vendor/twig/twig/lib/Twig/Extension.php +++ b/core/vendor/twig/twig/lib/Twig/Extension.php @@ -24,7 +24,7 @@ public function initRuntime(Twig_Environment $environment) /** * Returns the token parser instances to add to the existing list. * - * @return array An array of Twig_TokenParserInterface or Twig_TokenParserBrokerInterface instances + * @return array An array of Twig_TokenParserInterface instances */ public function getTokenParsers() { diff --git a/core/vendor/twig/twig/lib/Twig/Extension/Core.php b/core/vendor/twig/twig/lib/Twig/Extension/Core.php index cfffa80..d0281e5 100644 --- a/core/vendor/twig/twig/lib/Twig/Extension/Core.php +++ b/core/vendor/twig/twig/lib/Twig/Extension/Core.php @@ -15,10 +15,10 @@ */ class Twig_Extension_Core extends Twig_Extension { - protected $dateFormats = array('F j, Y H:i', '%d days'); - protected $numberFormat = array(0, '.', ','); - protected $timezone = null; - protected $escapers = array(); + private $dateFormats = array('F j, Y H:i', '%d days'); + private $numberFormat = array(0, '.', ','); + private $timezone = null; + private $escapers = array(); /** * Defines a new escaper to be used via the escape filter. @@ -26,7 +26,7 @@ class Twig_Extension_Core extends Twig_Extension * @param string $strategy The strategy name that should be used as a strategy in the escape call * @param callable $callable A valid PHP callable */ - public function setEscaper($strategy, $callable) + public function setEscaper($strategy, callable $callable) { $this->escapers[$strategy] = $callable; } @@ -34,7 +34,7 @@ public function setEscaper($strategy, $callable) /** * Gets all defined escapers. * - * @return array An array of escapers + * @return callable[] An array of escapers */ public function getEscapers() { @@ -149,54 +149,54 @@ public function getFilters() { $filters = array( // formatting filters - new Twig_SimpleFilter('date', 'twig_date_format_filter', array('needs_environment' => true)), - new Twig_SimpleFilter('date_modify', 'twig_date_modify_filter', array('needs_environment' => true)), - new Twig_SimpleFilter('format', 'sprintf'), - new Twig_SimpleFilter('replace', 'strtr'), - new Twig_SimpleFilter('number_format', 'twig_number_format_filter', array('needs_environment' => true)), - new Twig_SimpleFilter('abs', 'abs'), - new Twig_SimpleFilter('round', 'twig_round'), + new Twig_Filter('date', 'twig_date_format_filter', array('needs_environment' => true)), + new Twig_Filter('date_modify', 'twig_date_modify_filter', array('needs_environment' => true)), + new Twig_Filter('format', 'sprintf'), + new Twig_Filter('replace', 'twig_replace_filter'), + new Twig_Filter('number_format', 'twig_number_format_filter', array('needs_environment' => true)), + new Twig_Filter('abs', 'abs'), + new Twig_Filter('round', 'twig_round'), // encoding - new Twig_SimpleFilter('url_encode', 'twig_urlencode_filter'), - new Twig_SimpleFilter('json_encode', 'twig_jsonencode_filter'), - new Twig_SimpleFilter('convert_encoding', 'twig_convert_encoding'), + new Twig_Filter('url_encode', 'twig_urlencode_filter'), + new Twig_Filter('json_encode', 'twig_jsonencode_filter'), + new Twig_Filter('convert_encoding', 'twig_convert_encoding'), // string filters - new Twig_SimpleFilter('title', 'twig_title_string_filter', array('needs_environment' => true)), - new Twig_SimpleFilter('capitalize', 'twig_capitalize_string_filter', array('needs_environment' => true)), - new Twig_SimpleFilter('upper', 'strtoupper'), - new Twig_SimpleFilter('lower', 'strtolower'), - new Twig_SimpleFilter('striptags', 'strip_tags'), - new Twig_SimpleFilter('trim', 'trim'), - new Twig_SimpleFilter('nl2br', 'nl2br', array('pre_escape' => 'html', 'is_safe' => array('html'))), + new Twig_Filter('title', 'twig_title_string_filter', array('needs_environment' => true)), + new Twig_Filter('capitalize', 'twig_capitalize_string_filter', array('needs_environment' => true)), + new Twig_Filter('upper', 'strtoupper'), + new Twig_Filter('lower', 'strtolower'), + new Twig_Filter('striptags', 'strip_tags'), + new Twig_Filter('trim', 'trim'), + new Twig_Filter('nl2br', 'nl2br', array('pre_escape' => 'html', 'is_safe' => array('html'))), // array helpers - new Twig_SimpleFilter('join', 'twig_join_filter'), - new Twig_SimpleFilter('split', 'twig_split_filter', array('needs_environment' => true)), - new Twig_SimpleFilter('sort', 'twig_sort_filter'), - new Twig_SimpleFilter('merge', 'twig_array_merge'), - new Twig_SimpleFilter('batch', 'twig_array_batch'), + new Twig_Filter('join', 'twig_join_filter'), + new Twig_Filter('split', 'twig_split_filter', array('needs_environment' => true)), + new Twig_Filter('sort', 'twig_sort_filter'), + new Twig_Filter('merge', 'twig_array_merge'), + new Twig_Filter('batch', 'twig_array_batch'), // string/array filters - new Twig_SimpleFilter('reverse', 'twig_reverse_filter', array('needs_environment' => true)), - new Twig_SimpleFilter('length', 'twig_length_filter', array('needs_environment' => true)), - new Twig_SimpleFilter('slice', 'twig_slice', array('needs_environment' => true)), - new Twig_SimpleFilter('first', 'twig_first', array('needs_environment' => true)), - new Twig_SimpleFilter('last', 'twig_last', array('needs_environment' => true)), + new Twig_Filter('reverse', 'twig_reverse_filter', array('needs_environment' => true)), + new Twig_Filter('length', 'twig_length_filter', array('needs_environment' => true)), + new Twig_Filter('slice', 'twig_slice', array('needs_environment' => true)), + new Twig_Filter('first', 'twig_first', array('needs_environment' => true)), + new Twig_Filter('last', 'twig_last', array('needs_environment' => true)), // iteration and runtime - new Twig_SimpleFilter('default', '_twig_default_filter', array('node_class' => 'Twig_Node_Expression_Filter_Default')), - new Twig_SimpleFilter('keys', 'twig_get_array_keys_filter'), + new Twig_Filter('default', '_twig_default_filter', array('node_class' => 'Twig_Node_Expression_Filter_Default')), + new Twig_Filter('keys', 'twig_get_array_keys_filter'), // escaping - new Twig_SimpleFilter('escape', 'twig_escape_filter', array('needs_environment' => true, 'is_safe_callback' => 'twig_escape_filter_is_safe')), - new Twig_SimpleFilter('e', 'twig_escape_filter', array('needs_environment' => true, 'is_safe_callback' => 'twig_escape_filter_is_safe')), + new Twig_Filter('escape', 'twig_escape_filter', array('needs_environment' => true, 'is_safe_callback' => 'twig_escape_filter_is_safe')), + new Twig_Filter('e', 'twig_escape_filter', array('needs_environment' => true, 'is_safe_callback' => 'twig_escape_filter_is_safe')), ); if (function_exists('mb_get_info')) { - $filters[] = new Twig_SimpleFilter('upper', 'twig_upper_filter', array('needs_environment' => true)); - $filters[] = new Twig_SimpleFilter('lower', 'twig_lower_filter', array('needs_environment' => true)); + $filters[] = new Twig_Filter('upper', 'twig_upper_filter', array('needs_environment' => true)); + $filters[] = new Twig_Filter('lower', 'twig_lower_filter', array('needs_environment' => true)); } return $filters; @@ -210,15 +210,15 @@ public function getFilters() public function getFunctions() { return array( - new Twig_SimpleFunction('max', 'max'), - new Twig_SimpleFunction('min', 'min'), - new Twig_SimpleFunction('range', 'range'), - new Twig_SimpleFunction('constant', 'twig_constant'), - new Twig_SimpleFunction('cycle', 'twig_cycle'), - new Twig_SimpleFunction('random', 'twig_random', array('needs_environment' => true)), - new Twig_SimpleFunction('date', 'twig_date_converter', array('needs_environment' => true)), - new Twig_SimpleFunction('include', 'twig_include', array('needs_environment' => true, 'needs_context' => true, 'is_safe' => array('all'))), - new Twig_SimpleFunction('source', 'twig_source', array('needs_environment' => true, 'is_safe' => array('all'))), + new Twig_Function('max', 'max'), + new Twig_Function('min', 'min'), + new Twig_Function('range', 'range'), + new Twig_Function('constant', 'twig_constant'), + new Twig_Function('cycle', 'twig_cycle'), + new Twig_Function('random', 'twig_random', array('needs_environment' => true)), + new Twig_Function('date', 'twig_date_converter', array('needs_environment' => true)), + new Twig_Function('include', 'twig_include', array('needs_environment' => true, 'needs_context' => true, 'is_safe' => array('all'))), + new Twig_Function('source', 'twig_source', array('needs_environment' => true, 'is_safe' => array('all'))), ); } @@ -230,18 +230,16 @@ public function getFunctions() public function getTests() { return array( - new Twig_SimpleTest('even', null, array('node_class' => 'Twig_Node_Expression_Test_Even')), - new Twig_SimpleTest('odd', null, array('node_class' => 'Twig_Node_Expression_Test_Odd')), - new Twig_SimpleTest('defined', null, array('node_class' => 'Twig_Node_Expression_Test_Defined')), - new Twig_SimpleTest('sameas', null, array('node_class' => 'Twig_Node_Expression_Test_Sameas', 'deprecated' => true, 'alternative' => 'same as')), - new Twig_SimpleTest('same as', null, array('node_class' => 'Twig_Node_Expression_Test_Sameas')), - new Twig_SimpleTest('none', null, array('node_class' => 'Twig_Node_Expression_Test_Null')), - new Twig_SimpleTest('null', null, array('node_class' => 'Twig_Node_Expression_Test_Null')), - new Twig_SimpleTest('divisibleby', null, array('node_class' => 'Twig_Node_Expression_Test_Divisibleby', 'deprecated' => true, 'alternative' => 'divisible by')), - new Twig_SimpleTest('divisible by', null, array('node_class' => 'Twig_Node_Expression_Test_Divisibleby')), - new Twig_SimpleTest('constant', null, array('node_class' => 'Twig_Node_Expression_Test_Constant')), - new Twig_SimpleTest('empty', 'twig_test_empty'), - new Twig_SimpleTest('iterable', 'twig_test_iterable'), + new Twig_Test('even', null, array('node_class' => 'Twig_Node_Expression_Test_Even')), + new Twig_Test('odd', null, array('node_class' => 'Twig_Node_Expression_Test_Odd')), + new Twig_Test('defined', null, array('node_class' => 'Twig_Node_Expression_Test_Defined')), + new Twig_Test('same as', null, array('node_class' => 'Twig_Node_Expression_Test_Sameas')), + new Twig_Test('none', null, array('node_class' => 'Twig_Node_Expression_Test_Null')), + new Twig_Test('null', null, array('node_class' => 'Twig_Node_Expression_Test_Null')), + new Twig_Test('divisible by', null, array('node_class' => 'Twig_Node_Expression_Test_Divisibleby')), + new Twig_Test('constant', null, array('node_class' => 'Twig_Node_Expression_Test_Constant')), + new Twig_Test('empty', 'twig_test_empty'), + new Twig_Test('iterable', 'twig_test_iterable'), ); } @@ -290,43 +288,32 @@ public function getOperators() ); } - public function parseNotTestExpression(Twig_Parser $parser, Twig_NodeInterface $node) + public function parseNotTestExpression(Twig_Parser $parser, Twig_Node $node) { return new Twig_Node_Expression_Unary_Not($this->parseTestExpression($parser, $node), $parser->getCurrentToken()->getLine()); } - public function parseTestExpression(Twig_Parser $parser, Twig_NodeInterface $node) + public function parseTestExpression(Twig_Parser $parser, Twig_Node $node) { $stream = $parser->getStream(); - list($name, $test) = $this->getTest($parser, $node->getLine()); - - if ($test instanceof Twig_SimpleTest && $test->isDeprecated()) { - $message = sprintf('Twig Test "%s" is deprecated', $name); - if ($test->getAlternative()) { - $message .= sprintf('. Use "%s" instead', $test->getAlternative()); - } - $message .= sprintf(' in %s at line %d.', $stream->getFilename(), $stream->getCurrent()->getLine()); - - @trigger_error($message, E_USER_DEPRECATED); - } - - $class = $this->getTestNodeClass($parser, $test); + $test = $this->getTest($parser, $node->getLine()); + $class = $test->getNodeClass(); $arguments = null; if ($stream->test(Twig_Token::PUNCTUATION_TYPE, '(')) { $arguments = $parser->getExpressionParser()->parseArguments(true); } - return new $class($node, $name, $arguments, $parser->getCurrentToken()->getLine()); + return new $class($node, $test->getName(), $arguments, $parser->getCurrentToken()->getLine()); } - protected function getTest(Twig_Parser $parser, $line) + private function getTest(Twig_Parser $parser, $line) { $stream = $parser->getStream(); $name = $stream->expect(Twig_Token::NAME_TYPE)->getValue(); $env = $parser->getEnvironment(); if ($test = $env->getTest($name)) { - return array($name, $test); + return $test; } if ($stream->test(Twig_Token::NAME_TYPE)) { @@ -336,7 +323,7 @@ protected function getTest(Twig_Parser $parser, $line) if ($test = $env->getTest($name)) { $parser->getStream()->next(); - return array($name, $test); + return $test; } } @@ -348,15 +335,6 @@ protected function getTest(Twig_Parser $parser, $line) throw new Twig_Error_Syntax($message, $line, $parser->getFilename()); } - protected function getTestNodeClass(Twig_Parser $parser, $test) - { - if ($test instanceof Twig_SimpleTest) { - return $test->getNodeClass(); - } - - return $test instanceof Twig_Test_Node ? $test->getClass() : 'Twig_Node_Expression_Test'; - } - /** * Returns the name of the extension. * @@ -550,6 +528,25 @@ function twig_date_converter(Twig_Environment $env, $date = null, $timezone = nu } /** + * Replaces strings within a string. + * + * @param string $str String to replace in + * @param array|Traversable $from Replace values + * + * @return string + */ +function twig_replace_filter($str, $from) +{ + if ($from instanceof Traversable) { + $from = iterator_to_array($from); + } elseif (!is_array($from)) { + throw new Twig_Error_Runtime(sprintf('The "replace" filter expects an array or "Traversable" as replace values, got "%s".',is_object($from) ? get_class($from) : gettype($from))); + } + + return strtr($str, $from); +} + +/** * Rounds a number. * * @param int|float $value The value to round @@ -624,51 +621,27 @@ function twig_urlencode_filter($url) return rawurlencode($url); } -if (PHP_VERSION_ID < 50300) { - /** - * JSON encodes a variable. - * - * @param mixed $value The value to encode. - * @param int $options Not used on PHP 5.2.x - * - * @return mixed The JSON encoded value - */ - function twig_jsonencode_filter($value, $options = 0) - { - if ($value instanceof Twig_Markup) { - $value = (string) $value; - } elseif (is_array($value)) { - array_walk_recursive($value, '_twig_markup2string'); - } - - return json_encode($value); - } -} else { - /** - * JSON encodes a variable. - * - * @param mixed $value The value to encode. - * @param int $options Bitmask consisting of JSON_HEX_QUOT, JSON_HEX_TAG, JSON_HEX_AMP, JSON_HEX_APOS, JSON_NUMERIC_CHECK, JSON_PRETTY_PRINT, JSON_UNESCAPED_SLASHES, JSON_FORCE_OBJECT - * - * @return mixed The JSON encoded value - */ - function twig_jsonencode_filter($value, $options = 0) - { - if ($value instanceof Twig_Markup) { - $value = (string) $value; - } elseif (is_array($value)) { - array_walk_recursive($value, '_twig_markup2string'); - } - - return json_encode($value, $options); - } -} - -function _twig_markup2string(&$value) +/** + * JSON encodes a variable. + * + * @param mixed $value The value to encode. + * @param int $options Bitmask consisting of JSON_HEX_QUOT, JSON_HEX_TAG, JSON_HEX_AMP, JSON_HEX_APOS, JSON_NUMERIC_CHECK, JSON_PRETTY_PRINT, JSON_UNESCAPED_SLASHES, JSON_FORCE_OBJECT + * + * @return mixed The JSON encoded value + */ +function twig_jsonencode_filter($value, $options = 0) { if ($value instanceof Twig_Markup) { $value = (string) $value; + } elseif (is_array($value)) { + array_walk_recursive($value, function (&$value) { + if ($value instanceof Twig_Markup) { + $value = (string) $value; + } + }); } + + return json_encode($value, $options); } /** @@ -682,15 +655,23 @@ function _twig_markup2string(&$value) * {# items now contains { 'apple': 'fruit', 'orange': 'fruit', 'peugeot': 'car' } #} * * - * @param array $arr1 An array - * @param array $arr2 An array + * @param array|Traversable $arr1 An array + * @param array|Traversable $arr2 An array * * @return array The merged array */ function twig_array_merge($arr1, $arr2) { - if (!is_array($arr1) || !is_array($arr2)) { - throw new Twig_Error_Runtime(sprintf('The merge filter only works with arrays or hashes; %s and %s given.', gettype($arr1), gettype($arr2))); + if ($arr1 instanceof Traversable) { + $arr1 = iterator_to_array($arr1); + } elseif (!is_array($arr1)) { + throw new Twig_Error_Runtime(sprintf('The merge filter only works with arrays or "Traversable", got "%s" as first argument.', gettype($arr1))); + } + + if ($arr2 instanceof Traversable) { + $arr2 = iterator_to_array($arr2); + } elseif (!is_array($arr2)) { + throw new Twig_Error_Runtime(sprintf('The merge filter only works with arrays or "Traversable", got "%s" as second argument.', gettype($arr2))); } return array_merge($arr1, $arr2); @@ -874,7 +855,7 @@ function _twig_default_filter($value, $default = '') */ function twig_get_array_keys_filter($array) { - if (is_object($array) && $array instanceof Traversable) { + if ($array instanceof Traversable) { return array_keys(iterator_to_array($array)); } @@ -896,7 +877,7 @@ function twig_get_array_keys_filter($array) */ function twig_reverse_filter(Twig_Environment $env, $item, $preserveKeys = false) { - if (is_object($item) && $item instanceof Traversable) { + if ($item instanceof Traversable) { return array_reverse(iterator_to_array($item), $preserveKeys); } @@ -928,12 +909,18 @@ function twig_reverse_filter(Twig_Environment $env, $item, $preserveKeys = false /** * Sorts an array. * - * @param array $array + * @param array|Traversable $array * * @return array */ function twig_sort_filter($array) { + if ($array instanceof Traversable) { + $array = iterator_to_array($array); + } elseif (!is_array($array)) { + throw new Twig_Error_Runtime(sprintf('The sort filter only works with arrays or "Traversable", got "%s".', gettype($array))); + } + asort($array); return $array; @@ -1041,7 +1028,19 @@ function twig_escape_filter(Twig_Environment $env, $string, $strategy = 'html', throw new Twig_Error_Runtime('The string to escape is not a valid UTF-8 string.'); } - $string = preg_replace_callback('#[^a-zA-Z0-9,\._]#Su', '_twig_escape_js_callback', $string); + $string = preg_replace_callback('#[^a-zA-Z0-9,\._]#Su', function ($matches) { + $char = $matches[0]; + + // \xHH + if (!isset($char[1])) { + return '\\x'.strtoupper(substr('00'.bin2hex($char), -2)); + } + + // \uHHHH + $char = twig_convert_encoding($char, 'UTF-16BE', 'UTF-8'); + + return '\\u'.strtoupper(substr('0000'.bin2hex($char), -4)); + }, $string); if ('UTF-8' != $charset) { $string = twig_convert_encoding($string, $charset, 'UTF-8'); @@ -1058,7 +1057,24 @@ function twig_escape_filter(Twig_Environment $env, $string, $strategy = 'html', throw new Twig_Error_Runtime('The string to escape is not a valid UTF-8 string.'); } - $string = preg_replace_callback('#[^a-zA-Z0-9]#Su', '_twig_escape_css_callback', $string); + $string = preg_replace_callback('#[^a-zA-Z0-9]#Su', function ($matches) { + $char = $matches[0]; + + // \xHH + if (!isset($char[1])) { + $hex = ltrim(strtoupper(bin2hex($char)), '0'); + if (0 === strlen($hex)) { + $hex = '0'; + } + + return '\\'.$hex.' '; + } + + // \uHHHH + $char = twig_convert_encoding($char, 'UTF-16BE', 'UTF-8'); + + return '\\'.ltrim(strtoupper(bin2hex($char)), '0').' '; + }, $string); if ('UTF-8' != $charset) { $string = twig_convert_encoding($string, $charset, 'UTF-8'); @@ -1075,7 +1091,59 @@ function twig_escape_filter(Twig_Environment $env, $string, $strategy = 'html', throw new Twig_Error_Runtime('The string to escape is not a valid UTF-8 string.'); } - $string = preg_replace_callback('#[^a-zA-Z0-9,\.\-_]#Su', '_twig_escape_html_attr_callback', $string); + $string = preg_replace_callback('#[^a-zA-Z0-9,\.\-_]#Su', function ($matches) { + /** + * This function is adapted from code coming from Zend Framework. + * + * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + /* + * While HTML supports far more named entities, the lowest common denominator + * has become HTML5's XML Serialisation which is restricted to the those named + * entities that XML supports. Using HTML entities would result in this error: + * XML Parsing Error: undefined entity + */ + static $entityMap = array( + 34 => 'quot', /* quotation mark */ + 38 => 'amp', /* ampersand */ + 60 => 'lt', /* less-than sign */ + 62 => 'gt', /* greater-than sign */ + ); + + $chr = $matches[0]; + $ord = ord($chr); + + /* + * The following replaces characters undefined in HTML with the + * hex entity for the Unicode replacement character. + */ + if (($ord <= 0x1f && $chr != "\t" && $chr != "\n" && $chr != "\r") || ($ord >= 0x7f && $ord <= 0x9f)) { + return '�'; + } + + /* + * Check if the current character to escape has a name entity we should + * replace it with while grabbing the hex value of the character. + */ + if (strlen($chr) == 1) { + $hex = strtoupper(substr('00'.bin2hex($chr), -2)); + } else { + $chr = twig_convert_encoding($chr, 'UTF-16BE', 'UTF-8'); + $hex = strtoupper(substr('0000'.bin2hex($chr), -4)); + } + + $int = hexdec($hex); + if (array_key_exists($int, $entityMap)) { + return sprintf('&%s;', $entityMap[$int]); + } + + /* + * Per OWASP recommendations, we'll use hex entities for any other + * characters where a named entity does not exist. + */ + return sprintf('&#x%s;', $hex); + }, $string); if ('UTF-8' != $charset) { $string = twig_convert_encoding($string, $charset, 'UTF-8'); @@ -1084,10 +1152,6 @@ function twig_escape_filter(Twig_Environment $env, $string, $strategy = 'html', return $string; case 'url': - if (PHP_VERSION_ID < 50300) { - return str_replace('%7E', '~', rawurlencode($string)); - } - return rawurlencode($string); default: @@ -1098,7 +1162,7 @@ function twig_escape_filter(Twig_Environment $env, $string, $strategy = 'html', } if (isset($escapers[$strategy])) { - return call_user_func($escapers[$strategy], $env, $string, $charset); + return $escapers[$strategy]($env, $string, $charset); } $validStrategies = implode(', ', array_merge(array('html', 'js', 'url', 'css', 'html_attr'), array_keys($escapers))); @@ -1138,96 +1202,6 @@ function twig_convert_encoding($string, $to, $from) } } -function _twig_escape_js_callback($matches) -{ - $char = $matches[0]; - - // \xHH - if (!isset($char[1])) { - return '\\x'.strtoupper(substr('00'.bin2hex($char), -2)); - } - - // \uHHHH - $char = twig_convert_encoding($char, 'UTF-16BE', 'UTF-8'); - - return '\\u'.strtoupper(substr('0000'.bin2hex($char), -4)); -} - -function _twig_escape_css_callback($matches) -{ - $char = $matches[0]; - - // \xHH - if (!isset($char[1])) { - $hex = ltrim(strtoupper(bin2hex($char)), '0'); - if (0 === strlen($hex)) { - $hex = '0'; - } - - return '\\'.$hex.' '; - } - - // \uHHHH - $char = twig_convert_encoding($char, 'UTF-16BE', 'UTF-8'); - - return '\\'.ltrim(strtoupper(bin2hex($char)), '0').' '; -} - -/** - * This function is adapted from code coming from Zend Framework. - * - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -function _twig_escape_html_attr_callback($matches) -{ - /* - * While HTML supports far more named entities, the lowest common denominator - * has become HTML5's XML Serialisation which is restricted to the those named - * entities that XML supports. Using HTML entities would result in this error: - * XML Parsing Error: undefined entity - */ - static $entityMap = array( - 34 => 'quot', /* quotation mark */ - 38 => 'amp', /* ampersand */ - 60 => 'lt', /* less-than sign */ - 62 => 'gt', /* greater-than sign */ - ); - - $chr = $matches[0]; - $ord = ord($chr); - - /* - * The following replaces characters undefined in HTML with the - * hex entity for the Unicode replacement character. - */ - if (($ord <= 0x1f && $chr != "\t" && $chr != "\n" && $chr != "\r") || ($ord >= 0x7f && $ord <= 0x9f)) { - return '�'; - } - - /* - * Check if the current character to escape has a name entity we should - * replace it with while grabbing the hex value of the character. - */ - if (strlen($chr) == 1) { - $hex = strtoupper(substr('00'.bin2hex($chr), -2)); - } else { - $chr = twig_convert_encoding($chr, 'UTF-16BE', 'UTF-8'); - $hex = strtoupper(substr('0000'.bin2hex($chr), -4)); - } - - $int = hexdec($hex); - if (array_key_exists($int, $entityMap)) { - return sprintf('&%s;', $entityMap[$int]); - } - - /* - * Per OWASP recommendations, we'll use hex entities for any other - * characters where a named entity does not exist. - */ - return sprintf('&#x%s;', $hex); -} - // add multibyte extensions if possible if (function_exists('mb_get_info')) { /** diff --git a/core/vendor/twig/twig/lib/Twig/Extension/Debug.php b/core/vendor/twig/twig/lib/Twig/Extension/Debug.php index 86d07c2..616c3ad 100644 --- a/core/vendor/twig/twig/lib/Twig/Extension/Debug.php +++ b/core/vendor/twig/twig/lib/Twig/Extension/Debug.php @@ -28,7 +28,7 @@ public function getFunctions() ; return array( - new Twig_SimpleFunction('dump', 'twig_var_dump', array('is_safe' => $isDumpOutputHtmlSafe ? array('html') : array(), 'needs_context' => true, 'needs_environment' => true)), + new Twig_Function('dump', 'twig_var_dump', array('is_safe' => $isDumpOutputHtmlSafe ? array('html') : array(), 'needs_context' => true, 'needs_environment' => true)), ); } diff --git a/core/vendor/twig/twig/lib/Twig/Extension/Escaper.php b/core/vendor/twig/twig/lib/Twig/Extension/Escaper.php index 053a895..3c3ea7c 100644 --- a/core/vendor/twig/twig/lib/Twig/Extension/Escaper.php +++ b/core/vendor/twig/twig/lib/Twig/Extension/Escaper.php @@ -10,7 +10,7 @@ */ class Twig_Extension_Escaper extends Twig_Extension { - protected $defaultStrategy; + private $defaultStrategy; /** * Constructor. @@ -27,7 +27,7 @@ public function __construct($defaultStrategy = 'html') /** * Returns the token parser instances to add to the existing list. * - * @return array An array of Twig_TokenParserInterface or Twig_TokenParserBrokerInterface instances + * @return array An array of Twig_TokenParserInterface instances */ public function getTokenParsers() { @@ -52,7 +52,7 @@ public function getNodeVisitors() public function getFilters() { return array( - new Twig_SimpleFilter('raw', 'twig_raw_filter', array('is_safe' => array('all'))), + new Twig_Filter('raw', 'twig_raw_filter', array('is_safe' => array('all'))), ); } @@ -66,13 +66,6 @@ public function getFilters() */ public function setDefaultStrategy($defaultStrategy) { - // for BC - if (true === $defaultStrategy) { - @trigger_error('Using "true" as the default strategy is deprecated. Use "html" instead.', E_USER_DEPRECATED); - - $defaultStrategy = 'html'; - } - if ('filename' === $defaultStrategy) { $defaultStrategy = array('Twig_FileExtensionEscapingStrategy', 'guess'); } diff --git a/core/vendor/twig/twig/lib/Twig/Extension/Optimizer.php b/core/vendor/twig/twig/lib/Twig/Extension/Optimizer.php index 013fcb6..02b9959 100644 --- a/core/vendor/twig/twig/lib/Twig/Extension/Optimizer.php +++ b/core/vendor/twig/twig/lib/Twig/Extension/Optimizer.php @@ -10,7 +10,7 @@ */ class Twig_Extension_Optimizer extends Twig_Extension { - protected $optimizers; + private $optimizers; public function __construct($optimizers = -1) { diff --git a/core/vendor/twig/twig/lib/Twig/Extension/Sandbox.php b/core/vendor/twig/twig/lib/Twig/Extension/Sandbox.php index 3593e9e..e452833 100644 --- a/core/vendor/twig/twig/lib/Twig/Extension/Sandbox.php +++ b/core/vendor/twig/twig/lib/Twig/Extension/Sandbox.php @@ -10,9 +10,9 @@ */ class Twig_Extension_Sandbox extends Twig_Extension { - protected $sandboxedGlobally; - protected $sandboxed; - protected $policy; + private $sandboxedGlobally; + private $sandboxed; + private $policy; public function __construct(Twig_Sandbox_SecurityPolicyInterface $policy, $sandboxed = false) { @@ -23,7 +23,7 @@ public function __construct(Twig_Sandbox_SecurityPolicyInterface $policy, $sandb /** * Returns the token parser instances to add to the existing list. * - * @return array An array of Twig_TokenParserInterface or Twig_TokenParserBrokerInterface instances + * @return array An array of Twig_TokenParserInterface instances */ public function getTokenParsers() { diff --git a/core/vendor/twig/twig/lib/Twig/Extension/Staging.php b/core/vendor/twig/twig/lib/Twig/Extension/Staging.php index 8ab0f45..18681ea 100644 --- a/core/vendor/twig/twig/lib/Twig/Extension/Staging.php +++ b/core/vendor/twig/twig/lib/Twig/Extension/Staging.php @@ -10,24 +10,23 @@ */ /** - * Internal class. - * - * This class is used by Twig_Environment as a staging area and must not be used directly. + * Used by Twig_Environment as a staging area. * * @author Fabien Potencier + * @internal */ -class Twig_Extension_Staging extends Twig_Extension +final class Twig_Extension_Staging extends Twig_Extension { - protected $functions = array(); - protected $filters = array(); - protected $visitors = array(); - protected $tokenParsers = array(); - protected $globals = array(); - protected $tests = array(); + private $functions = array(); + private $filters = array(); + private $visitors = array(); + private $tokenParsers = array(); + private $globals = array(); + private $tests = array(); - public function addFunction($name, $function) + public function addFunction(Twig_Function $function) { - $this->functions[$name] = $function; + $this->functions[$function->getName()] = $function; } /** @@ -38,9 +37,9 @@ public function getFunctions() return $this->functions; } - public function addFilter($name, $filter) + public function addFilter(Twig_Filter $filter) { - $this->filters[$name] = $filter; + $this->filters[$filter->getName()] = $filter; } /** @@ -90,9 +89,9 @@ public function getGlobals() return $this->globals; } - public function addTest($name, $test) + public function addTest(Twig_Test $test) { - $this->tests[$name] = $test; + $this->tests[$test->getName()] = $test; } /** diff --git a/core/vendor/twig/twig/lib/Twig/Extension/StringLoader.php b/core/vendor/twig/twig/lib/Twig/Extension/StringLoader.php index 4e1a546..d5bbf78 100644 --- a/core/vendor/twig/twig/lib/Twig/Extension/StringLoader.php +++ b/core/vendor/twig/twig/lib/Twig/Extension/StringLoader.php @@ -16,7 +16,7 @@ class Twig_Extension_StringLoader extends Twig_Extension public function getFunctions() { return array( - new Twig_SimpleFunction('template_from_string', 'twig_template_from_string', array('needs_environment' => true)), + new Twig_Function('template_from_string', 'twig_template_from_string', array('needs_environment' => true)), ); } diff --git a/core/vendor/twig/twig/lib/Twig/ExtensionInterface.php b/core/vendor/twig/twig/lib/Twig/ExtensionInterface.php index 49541b0..2d5a52b 100644 --- a/core/vendor/twig/twig/lib/Twig/ExtensionInterface.php +++ b/core/vendor/twig/twig/lib/Twig/ExtensionInterface.php @@ -28,7 +28,7 @@ public function initRuntime(Twig_Environment $environment); /** * Returns the token parser instances to add to the existing list. * - * @return array An array of Twig_TokenParserInterface or Twig_TokenParserBrokerInterface instances + * @return array An array of Twig_TokenParserInterface instances */ public function getTokenParsers(); diff --git a/core/vendor/twig/twig/lib/Twig/FileExtensionEscapingStrategy.php b/core/vendor/twig/twig/lib/Twig/FileExtensionEscapingStrategy.php index b1ace7d..9bda0b4 100644 --- a/core/vendor/twig/twig/lib/Twig/FileExtensionEscapingStrategy.php +++ b/core/vendor/twig/twig/lib/Twig/FileExtensionEscapingStrategy.php @@ -27,15 +27,21 @@ class Twig_FileExtensionEscapingStrategy * * @param string $filename The template file name * - * @return string The escaping strategy name to use + * @return string|false The escaping strategy name to use or false to disable */ public static function guess($filename) { - if (!preg_match('{\.(js|css|txt)(?:\.[^/\\\\]+)?$}', $filename, $match)) { - return 'html'; + if (in_array(substr($filename, -1), array('/', '\\'))) { + return 'html'; // return html for directories } - switch ($match[1]) { + if ('.twig' === substr($filename, -5)) { + $filename = substr($filename, 0, -5); + } + + $extension = pathinfo($filename, PATHINFO_EXTENSION); + + switch ($extension) { case 'js': return 'js'; @@ -44,6 +50,9 @@ public static function guess($filename) case 'txt': return false; + + default: + return 'html'; } } } diff --git a/core/vendor/twig/twig/lib/Twig/Filter.php b/core/vendor/twig/twig/lib/Twig/Filter.php index 101d2e7..a984e2e 100644 --- a/core/vendor/twig/twig/lib/Twig/Filter.php +++ b/core/vendor/twig/twig/lib/Twig/Filter.php @@ -3,39 +3,71 @@ /* * This file is part of Twig. * - * (c) 2009 Fabien Potencier + * (c) 2009-2012 Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -@trigger_error('The Twig_Filter class is deprecated since version 1.12 and will be removed in 2.0. Use Twig_SimpleFilter instead.', E_USER_DEPRECATED); - /** * Represents a template filter. * - * Use Twig_SimpleFilter instead. - * * @author Fabien Potencier * - * @deprecated since 1.12 (to be removed in 2.0) + * @see http://twig.sensiolabs.org/doc/templates.html#filters */ -abstract class Twig_Filter implements Twig_FilterInterface, Twig_FilterCallableInterface +class Twig_Filter { - protected $options; - protected $arguments = array(); + private $name; + private $callable; + private $options; + private $arguments = array(); - public function __construct(array $options = array()) + /** + * Creates a template filter. + * + * @param string $name Name of this filter + * @param callable|null $callable A callable implementing the filter. If null, you need to overwrite the "node_class" option to customize compilation. + * @param array $options Options array + */ + public function __construct($name, callable $callable = null, array $options = array()) { + $this->name = $name; + $this->callable = $callable; $this->options = array_merge(array( 'needs_environment' => false, 'needs_context' => false, + 'is_variadic' => false, + 'is_safe' => null, + 'is_safe_callback' => null, 'pre_escape' => null, 'preserves_safety' => null, - 'callable' => null, + 'node_class' => 'Twig_Node_Expression_Filter', + 'deprecated' => false, + 'alternative' => null, ), $options); } + public function getName() + { + return $this->name; + } + + /** + * Returns the callable to execute for this filter. + * + * @return callable|null + */ + public function getCallable() + { + return $this->callable; + } + + public function getNodeClass() + { + return $this->options['node_class']; + } + public function setArguments($arguments) { $this->arguments = $arguments; @@ -58,12 +90,12 @@ public function needsContext() public function getSafe(Twig_Node $filterArgs) { - if (isset($this->options['is_safe'])) { + if (null !== $this->options['is_safe']) { return $this->options['is_safe']; } - if (isset($this->options['is_safe_callback'])) { - return call_user_func($this->options['is_safe_callback'], $filterArgs); + if (null !== $this->options['is_safe_callback']) { + return $this->options['is_safe_callback']($filterArgs); } } @@ -77,8 +109,18 @@ public function getPreEscape() return $this->options['pre_escape']; } - public function getCallable() + public function isVariadic() + { + return $this->options['is_variadic']; + } + + public function isDeprecated() + { + return $this->options['deprecated']; + } + + public function getAlternative() { - return $this->options['callable']; + return $this->options['alternative']; } } diff --git a/core/vendor/twig/twig/lib/Twig/Filter/Function.php b/core/vendor/twig/twig/lib/Twig/Filter/Function.php deleted file mode 100644 index d679cab..0000000 --- a/core/vendor/twig/twig/lib/Twig/Filter/Function.php +++ /dev/null @@ -1,40 +0,0 @@ - - * - * @deprecated since 1.12 (to be removed in 2.0) - */ -class Twig_Filter_Function extends Twig_Filter -{ - protected $function; - - public function __construct($function, array $options = array()) - { - $options['callable'] = $function; - - parent::__construct($options); - - $this->function = $function; - } - - public function compile() - { - return $this->function; - } -} diff --git a/core/vendor/twig/twig/lib/Twig/Filter/Method.php b/core/vendor/twig/twig/lib/Twig/Filter/Method.php deleted file mode 100644 index 655aab4..0000000 --- a/core/vendor/twig/twig/lib/Twig/Filter/Method.php +++ /dev/null @@ -1,42 +0,0 @@ - - * - * @deprecated since 1.12 (to be removed in 2.0) - */ -class Twig_Filter_Method extends Twig_Filter -{ - protected $extension; - protected $method; - - public function __construct(Twig_ExtensionInterface $extension, $method, array $options = array()) - { - $options['callable'] = array($extension, $method); - - parent::__construct($options); - - $this->extension = $extension; - $this->method = $method; - } - - public function compile() - { - return sprintf('$this->env->getExtension(\'%s\')->%s', $this->extension->getName(), $this->method); - } -} diff --git a/core/vendor/twig/twig/lib/Twig/Filter/Node.php b/core/vendor/twig/twig/lib/Twig/Filter/Node.php deleted file mode 100644 index a922f50..0000000 --- a/core/vendor/twig/twig/lib/Twig/Filter/Node.php +++ /dev/null @@ -1,42 +0,0 @@ - - * - * @deprecated since 1.12 (to be removed in 2.0) - */ -class Twig_Filter_Node extends Twig_Filter -{ - protected $class; - - public function __construct($class, array $options = array()) - { - parent::__construct($options); - - $this->class = $class; - } - - public function getClass() - { - return $this->class; - } - - public function compile() - { - } -} diff --git a/core/vendor/twig/twig/lib/Twig/FilterCallableInterface.php b/core/vendor/twig/twig/lib/Twig/FilterCallableInterface.php deleted file mode 100644 index 5679861..0000000 --- a/core/vendor/twig/twig/lib/Twig/FilterCallableInterface.php +++ /dev/null @@ -1,24 +0,0 @@ - - * - * @deprecated since 1.12 (to be removed in 2.0) - */ -interface Twig_FilterCallableInterface -{ - public function getCallable(); -} diff --git a/core/vendor/twig/twig/lib/Twig/FilterInterface.php b/core/vendor/twig/twig/lib/Twig/FilterInterface.php deleted file mode 100644 index 6b0be0e..0000000 --- a/core/vendor/twig/twig/lib/Twig/FilterInterface.php +++ /dev/null @@ -1,43 +0,0 @@ - - * - * @deprecated since 1.12 (to be removed in 2.0) - */ -interface Twig_FilterInterface -{ - /** - * Compiles a filter. - * - * @return string The PHP code for the filter - */ - public function compile(); - - public function needsEnvironment(); - - public function needsContext(); - - public function getSafe(Twig_Node $filterArgs); - - public function getPreservesSafety(); - - public function getPreEscape(); - - public function setArguments($arguments); - - public function getArguments(); -} diff --git a/core/vendor/twig/twig/lib/Twig/Function.php b/core/vendor/twig/twig/lib/Twig/Function.php index 9fc76a8..09ddc4c 100644 --- a/core/vendor/twig/twig/lib/Twig/Function.php +++ b/core/vendor/twig/twig/lib/Twig/Function.php @@ -3,37 +3,69 @@ /* * This file is part of Twig. * - * (c) 2010 Fabien Potencier + * (c) 2010-2012 Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -@trigger_error('The Twig_Function class is deprecated since version 1.12 and will be removed in 2.0. Use Twig_SimpleFunction instead.', E_USER_DEPRECATED); - /** * Represents a template function. * - * Use Twig_SimpleFunction instead. - * * @author Fabien Potencier * - * @deprecated since 1.12 (to be removed in 2.0) + * @see http://twig.sensiolabs.org/doc/templates.html#functions */ -abstract class Twig_Function implements Twig_FunctionInterface, Twig_FunctionCallableInterface +class Twig_Function { - protected $options; - protected $arguments = array(); + private $name; + private $callable; + private $options; + private $arguments = array(); - public function __construct(array $options = array()) + /** + * Creates a template function. + * + * @param string $name Name of this function + * @param callable|null $callable A callable implementing the function. If null, you need to overwrite the "node_class" option to customize compilation. + * @param array $options Options array + */ + public function __construct($name, callable $callable = null, array $options = array()) { + $this->name = $name; + $this->callable = $callable; $this->options = array_merge(array( 'needs_environment' => false, 'needs_context' => false, - 'callable' => null, + 'is_variadic' => false, + 'is_safe' => null, + 'is_safe_callback' => null, + 'node_class' => 'Twig_Node_Expression_Function', + 'deprecated' => false, + 'alternative' => null, ), $options); } + public function getName() + { + return $this->name; + } + + /** + * Returns the callable to execute for this function. + * + * @return callable|null + */ + public function getCallable() + { + return $this->callable; + } + + public function getNodeClass() + { + return $this->options['node_class']; + } + public function setArguments($arguments) { $this->arguments = $arguments; @@ -56,19 +88,29 @@ public function needsContext() public function getSafe(Twig_Node $functionArgs) { - if (isset($this->options['is_safe'])) { + if (null !== $this->options['is_safe']) { return $this->options['is_safe']; } - if (isset($this->options['is_safe_callback'])) { - return call_user_func($this->options['is_safe_callback'], $functionArgs); + if (null !== $this->options['is_safe_callback']) { + return $this->options['is_safe_callback']($functionArgs); } return array(); } - public function getCallable() + public function isVariadic() + { + return $this->options['is_variadic']; + } + + public function isDeprecated() + { + return $this->options['deprecated']; + } + + public function getAlternative() { - return $this->options['callable']; + return $this->options['alternative']; } } diff --git a/core/vendor/twig/twig/lib/Twig/Function/Function.php b/core/vendor/twig/twig/lib/Twig/Function/Function.php deleted file mode 100644 index ae83e15..0000000 --- a/core/vendor/twig/twig/lib/Twig/Function/Function.php +++ /dev/null @@ -1,41 +0,0 @@ - - * - * @deprecated since 1.12 (to be removed in 2.0) - */ -class Twig_Function_Function extends Twig_Function -{ - protected $function; - - public function __construct($function, array $options = array()) - { - $options['callable'] = $function; - - parent::__construct($options); - - $this->function = $function; - } - - public function compile() - { - return $this->function; - } -} diff --git a/core/vendor/twig/twig/lib/Twig/Function/Method.php b/core/vendor/twig/twig/lib/Twig/Function/Method.php deleted file mode 100644 index ba9945e..0000000 --- a/core/vendor/twig/twig/lib/Twig/Function/Method.php +++ /dev/null @@ -1,43 +0,0 @@ - - * - * @deprecated since 1.12 (to be removed in 2.0) - */ -class Twig_Function_Method extends Twig_Function -{ - protected $extension; - protected $method; - - public function __construct(Twig_ExtensionInterface $extension, $method, array $options = array()) - { - $options['callable'] = array($extension, $method); - - parent::__construct($options); - - $this->extension = $extension; - $this->method = $method; - } - - public function compile() - { - return sprintf('$this->env->getExtension(\'%s\')->%s', $this->extension->getName(), $this->method); - } -} diff --git a/core/vendor/twig/twig/lib/Twig/Function/Node.php b/core/vendor/twig/twig/lib/Twig/Function/Node.php deleted file mode 100644 index 118b0ba..0000000 --- a/core/vendor/twig/twig/lib/Twig/Function/Node.php +++ /dev/null @@ -1,42 +0,0 @@ - - * - * @deprecated since 1.12 (to be removed in 2.0) - */ -class Twig_Function_Node extends Twig_Function -{ - protected $class; - - public function __construct($class, array $options = array()) - { - parent::__construct($options); - - $this->class = $class; - } - - public function getClass() - { - return $this->class; - } - - public function compile() - { - } -} diff --git a/core/vendor/twig/twig/lib/Twig/FunctionCallableInterface.php b/core/vendor/twig/twig/lib/Twig/FunctionCallableInterface.php deleted file mode 100644 index 87d795e..0000000 --- a/core/vendor/twig/twig/lib/Twig/FunctionCallableInterface.php +++ /dev/null @@ -1,24 +0,0 @@ - - * - * @deprecated since 1.12 (to be removed in 2.0) - */ -interface Twig_FunctionCallableInterface -{ - public function getCallable(); -} diff --git a/core/vendor/twig/twig/lib/Twig/FunctionInterface.php b/core/vendor/twig/twig/lib/Twig/FunctionInterface.php deleted file mode 100644 index f449234..0000000 --- a/core/vendor/twig/twig/lib/Twig/FunctionInterface.php +++ /dev/null @@ -1,40 +0,0 @@ - - * - * @deprecated since 1.12 (to be removed in 2.0) - */ -interface Twig_FunctionInterface -{ - /** - * Compiles a function. - * - * @return string The PHP code for the function - */ - public function compile(); - - public function needsEnvironment(); - - public function needsContext(); - - public function getSafe(Twig_Node $filterArgs); - - public function setArguments($arguments); - - public function getArguments(); -} diff --git a/core/vendor/twig/twig/lib/Twig/Lexer.php b/core/vendor/twig/twig/lib/Twig/Lexer.php index 75f763f..e288421 100644 --- a/core/vendor/twig/twig/lib/Twig/Lexer.php +++ b/core/vendor/twig/twig/lib/Twig/Lexer.php @@ -15,23 +15,23 @@ * * @author Fabien Potencier */ -class Twig_Lexer implements Twig_LexerInterface +class Twig_Lexer { - protected $tokens; - protected $code; - protected $cursor; - protected $lineno; - protected $end; - protected $state; - protected $states; - protected $brackets; - protected $env; - protected $filename; - protected $options; - protected $regexes; - protected $position; - protected $positions; - protected $currentVarBlockLine; + private $tokens; + private $code; + private $cursor; + private $lineno; + private $end; + private $state; + private $states; + private $brackets; + private $env; + private $filename; + private $options; + private $regexes; + private $position; + private $positions; + private $currentVarBlockLine; const STATE_DATA = 0; const STATE_BLOCK = 1; @@ -61,10 +61,10 @@ public function __construct(Twig_Environment $env, array $options = array()) $this->regexes = array( 'lex_var' => '/\s*'.preg_quote($this->options['whitespace_trim'].$this->options['tag_variable'][1], '/').'\s*|\s*'.preg_quote($this->options['tag_variable'][1], '/').'/A', 'lex_block' => '/\s*(?:'.preg_quote($this->options['whitespace_trim'].$this->options['tag_block'][1], '/').'\s*|\s*'.preg_quote($this->options['tag_block'][1], '/').')\n?/A', - 'lex_raw_data' => '/('.preg_quote($this->options['tag_block'][0].$this->options['whitespace_trim'], '/').'|'.preg_quote($this->options['tag_block'][0], '/').')\s*(?:end%s)\s*(?:'.preg_quote($this->options['whitespace_trim'].$this->options['tag_block'][1], '/').'\s*|\s*'.preg_quote($this->options['tag_block'][1], '/').')/s', + 'lex_raw_data' => '/('.preg_quote($this->options['tag_block'][0].$this->options['whitespace_trim'], '/').'|'.preg_quote($this->options['tag_block'][0], '/').')\s*(?:endverbatim)\s*(?:'.preg_quote($this->options['whitespace_trim'].$this->options['tag_block'][1], '/').'\s*|\s*'.preg_quote($this->options['tag_block'][1], '/').')/s', 'operator' => $this->getOperatorRegex(), 'lex_comment' => '/(?:'.preg_quote($this->options['whitespace_trim'], '/').preg_quote($this->options['tag_comment'][1], '/').'\s*|'.preg_quote($this->options['tag_comment'][1], '/').')\n?/s', - 'lex_block_raw' => '/\s*(raw|verbatim)\s*(?:'.preg_quote($this->options['whitespace_trim'].$this->options['tag_block'][1], '/').'\s*|\s*'.preg_quote($this->options['tag_block'][1], '/').')/As', + 'lex_block_raw' => '/\s*verbatim\s*(?:'.preg_quote($this->options['whitespace_trim'].$this->options['tag_block'][1], '/').'\s*|\s*'.preg_quote($this->options['tag_block'][1], '/').')/As', 'lex_block_line' => '/\s*line\s+(\d+)\s*'.preg_quote($this->options['tag_block'][1], '/').'/As', 'lex_tokens_start' => '/('.preg_quote($this->options['tag_variable'][0], '/').'|'.preg_quote($this->options['tag_block'][0], '/').'|'.preg_quote($this->options['tag_comment'][0], '/').')('.preg_quote($this->options['whitespace_trim'], '/').')?/s', 'interpolation_start' => '/'.preg_quote($this->options['interpolation'][0], '/').'\s*/A', @@ -139,7 +139,7 @@ public function tokenize($code, $filename = null) return new Twig_TokenStream($this->tokens, $this->filename); } - protected function lexData() + private function lexData() { // if no matches are left we return the rest of the template as simple text token if ($this->position == count($this->positions[0]) - 1) { @@ -175,7 +175,7 @@ protected function lexData() // raw data? if (preg_match($this->regexes['lex_block_raw'], $this->code, $match, null, $this->cursor)) { $this->moveCursor($match[0]); - $this->lexRawData($match[1]); + $this->lexRawData(); // {% line \d+ %} } elseif (preg_match($this->regexes['lex_block_line'], $this->code, $match, null, $this->cursor)) { $this->moveCursor($match[0]); @@ -195,7 +195,7 @@ protected function lexData() } } - protected function lexBlock() + private function lexBlock() { if (empty($this->brackets) && preg_match($this->regexes['lex_block'], $this->code, $match, null, $this->cursor)) { $this->pushToken(Twig_Token::BLOCK_END_TYPE); @@ -206,7 +206,7 @@ protected function lexBlock() } } - protected function lexVar() + private function lexVar() { if (empty($this->brackets) && preg_match($this->regexes['lex_var'], $this->code, $match, null, $this->cursor)) { $this->pushToken(Twig_Token::VAR_END_TYPE); @@ -217,7 +217,7 @@ protected function lexVar() } } - protected function lexExpression() + private function lexExpression() { // whitespace if (preg_match('/\s+/A', $this->code, $match, null, $this->cursor)) { @@ -285,14 +285,10 @@ protected function lexExpression() } } - protected function lexRawData($tag) + private function lexRawData() { - if ('raw' === $tag) { - @trigger_error(sprintf('Twig Tag "raw" is deprecated. Use "verbatim" instead in %s at line %d.', $this->filename, $this->lineno), E_USER_DEPRECATED); - } - - if (!preg_match(str_replace('%s', $tag, $this->regexes['lex_raw_data']), $this->code, $match, PREG_OFFSET_CAPTURE, $this->cursor)) { - throw new Twig_Error_Syntax(sprintf('Unexpected end of file: Unclosed "%s" block', $tag), $this->lineno, $this->filename); + if (!preg_match($this->regexes['lex_raw_data'], $this->code, $match, PREG_OFFSET_CAPTURE, $this->cursor)) { + throw new Twig_Error_Syntax('Unexpected end of file: Unclosed "verbatim" block', $this->lineno, $this->filename); } $text = substr($this->code, $this->cursor, $match[0][1] - $this->cursor); @@ -305,7 +301,7 @@ protected function lexRawData($tag) $this->pushToken(Twig_Token::TEXT_TYPE, $text); } - protected function lexComment() + private function lexComment() { if (!preg_match($this->regexes['lex_comment'], $this->code, $match, PREG_OFFSET_CAPTURE, $this->cursor)) { throw new Twig_Error_Syntax('Unclosed comment', $this->lineno, $this->filename); @@ -314,7 +310,7 @@ protected function lexComment() $this->moveCursor(substr($this->code, $this->cursor, $match[0][1] - $this->cursor).$match[0][0]); } - protected function lexString() + private function lexString() { if (preg_match($this->regexes['interpolation_start'], $this->code, $match, null, $this->cursor)) { $this->brackets[] = array($this->options['interpolation'][0], $this->lineno); @@ -335,7 +331,7 @@ protected function lexString() } } - protected function lexInterpolation() + private function lexInterpolation() { $bracket = end($this->brackets); if ($this->options['interpolation'][0] === $bracket[0] && preg_match($this->regexes['interpolation_end'], $this->code, $match, null, $this->cursor)) { @@ -348,7 +344,7 @@ protected function lexInterpolation() } } - protected function pushToken($type, $value = '') + private function pushToken($type, $value = '') { // do not push empty text tokens if (Twig_Token::TEXT_TYPE === $type && '' === $value) { @@ -358,13 +354,13 @@ protected function pushToken($type, $value = '') $this->tokens[] = new Twig_Token($type, $value, $this->lineno); } - protected function moveCursor($text) + private function moveCursor($text) { $this->cursor += strlen($text); $this->lineno += substr_count($text, "\n"); } - protected function getOperatorRegex() + private function getOperatorRegex() { $operators = array_merge( array('='), @@ -394,13 +390,13 @@ protected function getOperatorRegex() return '/'.implode('|', $regex).'/A'; } - protected function pushState($state) + private function pushState($state) { $this->states[] = $this->state; $this->state = $state; } - protected function popState() + private function popState() { if (0 === count($this->states)) { throw new Exception('Cannot pop state without a previous state'); diff --git a/core/vendor/twig/twig/lib/Twig/LexerInterface.php b/core/vendor/twig/twig/lib/Twig/LexerInterface.php deleted file mode 100644 index 24a9478..0000000 --- a/core/vendor/twig/twig/lib/Twig/LexerInterface.php +++ /dev/null @@ -1,32 +0,0 @@ - - * - * @deprecated since 1.12 (to be removed in 3.0) - */ -interface Twig_LexerInterface -{ - /** - * Tokenizes a source code. - * - * @param string $code The source code - * @param string $filename A unique identifier for the source code - * - * @return Twig_TokenStream A token stream instance - * - * @throws Twig_Error_Syntax When the code is syntactically wrong - */ - public function tokenize($code, $filename = null); -} diff --git a/core/vendor/twig/twig/lib/Twig/Loader/Array.php b/core/vendor/twig/twig/lib/Twig/Loader/Array.php index 90221d5..56070af 100644 --- a/core/vendor/twig/twig/lib/Twig/Loader/Array.php +++ b/core/vendor/twig/twig/lib/Twig/Loader/Array.php @@ -23,7 +23,7 @@ */ class Twig_Loader_Array implements Twig_LoaderInterface, Twig_ExistsLoaderInterface { - protected $templates = array(); + private $templates = array(); /** * Constructor. @@ -43,7 +43,7 @@ public function __construct(array $templates) */ public function setTemplate($name, $template) { - $this->templates[(string) $name] = $template; + $this->templates[$name] = $template; } /** @@ -51,7 +51,6 @@ public function setTemplate($name, $template) */ public function getSource($name) { - $name = (string) $name; if (!isset($this->templates[$name])) { throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name)); } @@ -64,7 +63,7 @@ public function getSource($name) */ public function exists($name) { - return isset($this->templates[(string) $name]); + return isset($this->templates[$name]); } /** @@ -72,7 +71,6 @@ public function exists($name) */ public function getCacheKey($name) { - $name = (string) $name; if (!isset($this->templates[$name])) { throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name)); } @@ -85,7 +83,6 @@ public function getCacheKey($name) */ public function isFresh($name, $time) { - $name = (string) $name; if (!isset($this->templates[$name])) { throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name)); } diff --git a/core/vendor/twig/twig/lib/Twig/Loader/Chain.php b/core/vendor/twig/twig/lib/Twig/Loader/Chain.php index 7919eda..9244cbe 100644 --- a/core/vendor/twig/twig/lib/Twig/Loader/Chain.php +++ b/core/vendor/twig/twig/lib/Twig/Loader/Chain.php @@ -17,7 +17,7 @@ class Twig_Loader_Chain implements Twig_LoaderInterface, Twig_ExistsLoaderInterface { private $hasSourceCache = array(); - protected $loaders = array(); + private $loaders = array(); /** * Constructor. @@ -49,7 +49,7 @@ public function getSource($name) { $exceptions = array(); foreach ($this->loaders as $loader) { - if ($loader instanceof Twig_ExistsLoaderInterface && !$loader->exists($name)) { + if (!$loader->exists($name)) { continue; } @@ -68,26 +68,13 @@ public function getSource($name) */ public function exists($name) { - $name = (string) $name; - if (isset($this->hasSourceCache[$name])) { return $this->hasSourceCache[$name]; } foreach ($this->loaders as $loader) { - if ($loader instanceof Twig_ExistsLoaderInterface) { - if ($loader->exists($name)) { - return $this->hasSourceCache[$name] = true; - } - - continue; - } - - try { - $loader->getSource($name); - + if ($loader->exists($name)) { return $this->hasSourceCache[$name] = true; - } catch (Twig_Error_Loader $e) { } } @@ -101,7 +88,7 @@ public function getCacheKey($name) { $exceptions = array(); foreach ($this->loaders as $loader) { - if ($loader instanceof Twig_ExistsLoaderInterface && !$loader->exists($name)) { + if (!$loader->exists($name)) { continue; } @@ -122,7 +109,7 @@ public function isFresh($name, $time) { $exceptions = array(); foreach ($this->loaders as $loader) { - if ($loader instanceof Twig_ExistsLoaderInterface && !$loader->exists($name)) { + if (!$loader->exists($name)) { continue; } diff --git a/core/vendor/twig/twig/lib/Twig/Loader/Filesystem.php b/core/vendor/twig/twig/lib/Twig/Loader/Filesystem.php index a68876c..179f95a 100644 --- a/core/vendor/twig/twig/lib/Twig/Loader/Filesystem.php +++ b/core/vendor/twig/twig/lib/Twig/Loader/Filesystem.php @@ -165,9 +165,16 @@ public function isFresh($name, $time) return filemtime($this->findTemplate($name)) <= $time; } - protected function findTemplate($name) + /** + * Checks if the template can be found. + * + * @param string $name The template name + * @param Boolean $throw Whether to throw an exception when an error occurs + * + * @return string|false The template name or false + */ + protected function findTemplate($name, $throw = true) { - $throw = func_num_args() > 1 ? func_get_arg(1) : true; $name = $this->normalizeName($name); if (isset($this->cache[$name])) { @@ -215,7 +222,12 @@ protected function findTemplate($name) throw new Twig_Error_Loader($this->errorCache[$name]); } - protected function parseName($name, $default = self::MAIN_NAMESPACE) + private function normalizeName($name) + { + return preg_replace('#/{2,}#', '/', strtr($name, '\\', '/')); + } + + private function parseName($name, $default = self::MAIN_NAMESPACE) { if (isset($name[0]) && '@' == $name[0]) { if (false === $pos = strpos($name, '/')) { @@ -231,12 +243,7 @@ protected function parseName($name, $default = self::MAIN_NAMESPACE) return array($default, $name); } - protected function normalizeName($name) - { - return preg_replace('#/{2,}#', '/', strtr((string) $name, '\\', '/')); - } - - protected function validateName($name) + private function validateName($name) { if (false !== strpos($name, "\0")) { throw new Twig_Error_Loader('A template name cannot contain NUL bytes.'); diff --git a/core/vendor/twig/twig/lib/Twig/Loader/String.php b/core/vendor/twig/twig/lib/Twig/Loader/String.php deleted file mode 100644 index e7fff3e..0000000 --- a/core/vendor/twig/twig/lib/Twig/Loader/String.php +++ /dev/null @@ -1,61 +0,0 @@ - - */ -class Twig_Loader_String implements Twig_LoaderInterface, Twig_ExistsLoaderInterface -{ - /** - * {@inheritdoc} - */ - public function getSource($name) - { - return $name; - } - - /** - * {@inheritdoc} - */ - public function exists($name) - { - return true; - } - - /** - * {@inheritdoc} - */ - public function getCacheKey($name) - { - return $name; - } - - /** - * {@inheritdoc} - */ - public function isFresh($name, $time) - { - return true; - } -} diff --git a/core/vendor/twig/twig/lib/Twig/LoaderInterface.php b/core/vendor/twig/twig/lib/Twig/LoaderInterface.php index 544ea4e..a1ee0ae 100644 --- a/core/vendor/twig/twig/lib/Twig/LoaderInterface.php +++ b/core/vendor/twig/twig/lib/Twig/LoaderInterface.php @@ -50,4 +50,13 @@ public function getCacheKey($name); * @throws Twig_Error_Loader When $name is not found */ public function isFresh($name, $time); + + /** + * Check if we have the source code of a template, given its name. + * + * @param string $name The name of the template to check if we can load + * + * @return bool If the template source code is handled by this loader or not + */ + public function exists($name); } diff --git a/core/vendor/twig/twig/lib/Twig/Markup.php b/core/vendor/twig/twig/lib/Twig/Markup.php index 69871fc..e8e796f 100644 --- a/core/vendor/twig/twig/lib/Twig/Markup.php +++ b/core/vendor/twig/twig/lib/Twig/Markup.php @@ -16,8 +16,8 @@ */ class Twig_Markup implements Countable { - protected $content; - protected $charset; + private $content; + private $charset; public function __construct($content, $charset) { diff --git a/core/vendor/twig/twig/lib/Twig/Node.php b/core/vendor/twig/twig/lib/Twig/Node.php index 40d67fe..a3e067d 100644 --- a/core/vendor/twig/twig/lib/Twig/Node.php +++ b/core/vendor/twig/twig/lib/Twig/Node.php @@ -15,7 +15,7 @@ * * @author Fabien Potencier */ -class Twig_Node implements Twig_NodeInterface +class Twig_Node implements Countable, IteratorAggregate { protected $nodes; protected $attributes; @@ -69,41 +69,6 @@ public function __toString() return implode("\n", $repr); } - /** - * @deprecated since 1.16.1 (to be removed in 2.0) - */ - public function toXml($asDom = false) - { - @trigger_error(sprintf('%s is deprecated.', __METHOD__), E_USER_DEPRECATED); - - $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) { diff --git a/core/vendor/twig/twig/lib/Twig/Node/AutoEscape.php b/core/vendor/twig/twig/lib/Twig/Node/AutoEscape.php index fcabf90..993d6e0 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/AutoEscape.php +++ b/core/vendor/twig/twig/lib/Twig/Node/AutoEscape.php @@ -22,7 +22,7 @@ */ class Twig_Node_AutoEscape extends Twig_Node { - public function __construct($value, Twig_NodeInterface $body, $lineno, $tag = 'autoescape') + public function __construct($value, Twig_Node $body, $lineno, $tag = 'autoescape') { parent::__construct(array('body' => $body), array('value' => $value), $lineno, $tag); } diff --git a/core/vendor/twig/twig/lib/Twig/Node/Block.php b/core/vendor/twig/twig/lib/Twig/Node/Block.php index 989e4a0..b36e951 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/Block.php +++ b/core/vendor/twig/twig/lib/Twig/Node/Block.php @@ -17,7 +17,7 @@ */ class Twig_Node_Block extends Twig_Node { - public function __construct($name, Twig_NodeInterface $body, $lineno, $tag = null) + public function __construct($name, Twig_Node $body, $lineno, $tag = null) { parent::__construct(array('body' => $body), array('name' => $name), $lineno, $tag); } diff --git a/core/vendor/twig/twig/lib/Twig/Node/CheckSecurity.php b/core/vendor/twig/twig/lib/Twig/Node/CheckSecurity.php index b4a436a..3583fc7 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/CheckSecurity.php +++ b/core/vendor/twig/twig/lib/Twig/Node/CheckSecurity.php @@ -14,9 +14,9 @@ */ class Twig_Node_CheckSecurity extends Twig_Node { - protected $usedFilters; - protected $usedTags; - protected $usedFunctions; + private $usedFilters; + private $usedTags; + private $usedFunctions; public function __construct(array $usedFilters, array $usedTags, array $usedFunctions) { diff --git a/core/vendor/twig/twig/lib/Twig/Node/Expression/Array.php b/core/vendor/twig/twig/lib/Twig/Node/Expression/Array.php index 6cf7ca1..f46413a 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/Expression/Array.php +++ b/core/vendor/twig/twig/lib/Twig/Node/Expression/Array.php @@ -10,7 +10,7 @@ */ class Twig_Node_Expression_Array extends Twig_Node_Expression { - protected $index; + private $index; public function __construct(array $elements, $lineno) { diff --git a/core/vendor/twig/twig/lib/Twig/Node/Expression/Binary.php b/core/vendor/twig/twig/lib/Twig/Node/Expression/Binary.php index 5c383d1..a19a93a 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/Expression/Binary.php +++ b/core/vendor/twig/twig/lib/Twig/Node/Expression/Binary.php @@ -11,7 +11,7 @@ */ abstract class Twig_Node_Expression_Binary extends Twig_Node_Expression { - public function __construct(Twig_NodeInterface $left, Twig_NodeInterface $right, $lineno) + public function __construct(Twig_Node $left, Twig_Node $right, $lineno) { parent::__construct(array('left' => $left, 'right' => $right), array(), $lineno); } diff --git a/core/vendor/twig/twig/lib/Twig/Node/Expression/BlockReference.php b/core/vendor/twig/twig/lib/Twig/Node/Expression/BlockReference.php index c25aadd..ec8c75b 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/Expression/BlockReference.php +++ b/core/vendor/twig/twig/lib/Twig/Node/Expression/BlockReference.php @@ -17,7 +17,7 @@ */ class Twig_Node_Expression_BlockReference extends Twig_Node_Expression { - public function __construct(Twig_NodeInterface $name, $asString = false, $lineno, $tag = null) + public function __construct(Twig_Node $name, $asString = false, $lineno, $tag = null) { parent::__construct(array('name' => $name), array('as_string' => $asString, 'output' => false), $lineno, $tag); } diff --git a/core/vendor/twig/twig/lib/Twig/Node/Expression/Call.php b/core/vendor/twig/twig/lib/Twig/Node/Expression/Call.php index 51e2cac..f0269d1 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/Expression/Call.php +++ b/core/vendor/twig/twig/lib/Twig/Node/Expression/Call.php @@ -12,19 +12,22 @@ { protected function compileCallable(Twig_Compiler $compiler) { + $callable = $this->getAttribute('callable'); + $closingParenthesis = false; - if ($this->hasAttribute('callable') && $callable = $this->getAttribute('callable')) { - if (is_string($callable)) { - $compiler->raw($callable); - } elseif (is_array($callable) && $callable[0] instanceof Twig_ExtensionInterface) { - $compiler->raw(sprintf('$this->env->getExtension(\'%s\')->%s', $callable[0]->getName(), $callable[1])); - } else { - $type = ucfirst($this->getAttribute('type')); - $compiler->raw(sprintf('call_user_func_array($this->env->get%s(\'%s\')->getCallable(), array', $type, $this->getAttribute('name'))); - $closingParenthesis = true; - } + if (is_string($callable)) { + $compiler->raw($callable); + } elseif (is_array($callable) && $callable[0] instanceof Twig_ExtensionInterface) { + $compiler->raw(sprintf('$this->env->getExtension(\'%s\')->%s', $callable[0]->getName(), $callable[1])); + } elseif (null !== $callable) { + $closingParenthesis = true; + $compiler->raw(sprintf('call_user_func_array($this->env->get%s(\'%s\')->getCallable(), array', ucfirst($this->getAttribute('type')), $this->getAttribute('name'))); } else { - $compiler->raw($this->getAttribute('thing')->compile()); + throw new LogicException(sprintf( + '%s "%s" cannot be compiled because it does not define a callable to execute. Maybe you want to change compilation with a custom node class.', + ucfirst($this->getAttribute('type')), + $this->getAttribute('name') + )); } $this->compileArguments($compiler); @@ -72,10 +75,8 @@ protected function compileArguments(Twig_Compiler $compiler) } if ($this->hasNode('arguments') && null !== $this->getNode('arguments')) { - $callable = $this->hasAttribute('callable') ? $this->getAttribute('callable') : null; - + $callable = $this->getAttribute('callable'); $arguments = $this->getArguments($callable, $this->getNode('arguments')); - foreach ($arguments as $node) { if (!$first) { $compiler->raw(', '); @@ -88,7 +89,7 @@ protected function compileArguments(Twig_Compiler $compiler) $compiler->raw(')'); } - protected function getArguments($callable, $arguments) + protected function getArguments(callable $callable = null, $arguments) { $callType = $this->getAttribute('type'); $callName = $this->getAttribute('name'); diff --git a/core/vendor/twig/twig/lib/Twig/Node/Expression/Filter.php b/core/vendor/twig/twig/lib/Twig/Node/Expression/Filter.php index a906232..b1008d8 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/Expression/Filter.php +++ b/core/vendor/twig/twig/lib/Twig/Node/Expression/Filter.php @@ -11,7 +11,7 @@ */ class Twig_Node_Expression_Filter extends Twig_Node_Expression_Call { - public function __construct(Twig_NodeInterface $node, Twig_Node_Expression_Constant $filterName, Twig_NodeInterface $arguments, $lineno, $tag = null) + public function __construct(Twig_Node $node, Twig_Node_Expression_Constant $filterName, Twig_Node $arguments, $lineno, $tag = null) { parent::__construct(array('node' => $node, 'filter' => $filterName, 'arguments' => $arguments), array(), $lineno, $tag); } @@ -23,16 +23,11 @@ public function compile(Twig_Compiler $compiler) $this->setAttribute('name', $name); $this->setAttribute('type', 'filter'); - $this->setAttribute('thing', $filter); $this->setAttribute('needs_environment', $filter->needsEnvironment()); $this->setAttribute('needs_context', $filter->needsContext()); $this->setAttribute('arguments', $filter->getArguments()); - if ($filter instanceof Twig_FilterCallableInterface || $filter instanceof Twig_SimpleFilter) { - $this->setAttribute('callable', $filter->getCallable()); - } - if ($filter instanceof Twig_SimpleFilter) { - $this->setAttribute('is_variadic', $filter->isVariadic()); - } + $this->setAttribute('callable', $filter->getCallable()); + $this->setAttribute('is_variadic', $filter->isVariadic()); $this->compileCallable($compiler); } diff --git a/core/vendor/twig/twig/lib/Twig/Node/Expression/Filter/Default.php b/core/vendor/twig/twig/lib/Twig/Node/Expression/Filter/Default.php index 1827c88..dc2fdd8 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/Expression/Filter/Default.php +++ b/core/vendor/twig/twig/lib/Twig/Node/Expression/Filter/Default.php @@ -20,7 +20,7 @@ */ 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) + public function __construct(Twig_Node $node, Twig_Node_Expression_Constant $filterName, Twig_Node $arguments, $lineno, $tag = null) { $default = new Twig_Node_Expression_Filter($node, new Twig_Node_Expression_Constant('default', $node->getLine()), $arguments, $node->getLine()); diff --git a/core/vendor/twig/twig/lib/Twig/Node/Expression/Function.php b/core/vendor/twig/twig/lib/Twig/Node/Expression/Function.php index 7326ede..e19dc5f 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/Expression/Function.php +++ b/core/vendor/twig/twig/lib/Twig/Node/Expression/Function.php @@ -10,7 +10,7 @@ */ class Twig_Node_Expression_Function extends Twig_Node_Expression_Call { - public function __construct($name, Twig_NodeInterface $arguments, $lineno) + public function __construct($name, Twig_Node $arguments, $lineno) { parent::__construct(array('arguments' => $arguments), array('name' => $name), $lineno); } @@ -22,16 +22,11 @@ public function compile(Twig_Compiler $compiler) $this->setAttribute('name', $name); $this->setAttribute('type', 'function'); - $this->setAttribute('thing', $function); $this->setAttribute('needs_environment', $function->needsEnvironment()); $this->setAttribute('needs_context', $function->needsContext()); $this->setAttribute('arguments', $function->getArguments()); - if ($function instanceof Twig_FunctionCallableInterface || $function instanceof Twig_SimpleFunction) { - $this->setAttribute('callable', $function->getCallable()); - } - if ($function instanceof Twig_SimpleFunction) { - $this->setAttribute('is_variadic', $function->isVariadic()); - } + $this->setAttribute('callable', $function->getCallable()); + $this->setAttribute('is_variadic', $function->isVariadic()); $this->compileCallable($compiler); } diff --git a/core/vendor/twig/twig/lib/Twig/Node/Expression/Name.php b/core/vendor/twig/twig/lib/Twig/Node/Expression/Name.php index c062a21..fa2a0e9 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/Expression/Name.php +++ b/core/vendor/twig/twig/lib/Twig/Node/Expression/Name.php @@ -11,8 +11,7 @@ */ class Twig_Node_Expression_Name extends Twig_Node_Expression { - protected $specialVars = array( - '_self' => '$this', + private $specialVars = array( '_context' => '$context', '_charset' => '$this->env->getCharset()', ); @@ -30,19 +29,11 @@ public function compile(Twig_Compiler $compiler) if ($this->getAttribute('is_defined_test')) { if ($this->isSpecial()) { - if ('_self' === $name) { - @trigger_error(sprintf('Global variable "_self" is deprecated in %s at line %d', '?', $this->getLine()), E_USER_DEPRECATED); - } - $compiler->repr(true); } else { $compiler->raw('array_key_exists(')->repr($name)->raw(', $context)'); } } elseif ($this->isSpecial()) { - if ('_self' === $name) { - @trigger_error(sprintf('Global variable "_self" is deprecated in %s at line %d', '?', $this->getLine()), E_USER_DEPRECATED); - } - $compiler->raw($this->specialVars[$name]); } elseif ($this->getAttribute('always_defined')) { $compiler @@ -51,36 +42,30 @@ public function compile(Twig_Compiler $compiler) ->raw(']') ; } 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 (PHP_VERSION_ID >= 50400) { - // PHP 5.4 ternary operator performance was optimized + if ($this->getAttribute('ignore_strict_check') || !$compiler->getEnvironment()->isStrictVariables()) { $compiler ->raw('(isset($context[') ->string($name) ->raw(']) ? $context[') ->string($name) - ->raw('] : ') + ->raw('] : null)') ; - - if ($this->getAttribute('ignore_strict_check') || !$compiler->getEnvironment()->isStrictVariables()) { - $compiler->raw('null)'); - } else { - $compiler->raw('$this->getContext($context, ')->string($name)->raw('))'); - } } else { + // When Twig will require PHP 7.0, the Template::notFound() method + // will be removed and the code inlined like this: + // (function () { throw new Exception(...); })(); $compiler - ->raw('$this->getContext($context, ') + ->raw('(isset($context[') ->string($name) - ; - - if ($this->getAttribute('ignore_strict_check')) { - $compiler->raw(', true'); - } - - $compiler - ->raw(')') + ->raw(']) || array_key_exists(') + ->string($name) + ->raw(', $context) ? $context[') + ->string($name) + ->raw('] : $this->notFound(') + ->string($name) + ->raw(', ') + ->repr($this->lineno) + ->raw('))') ; } } diff --git a/core/vendor/twig/twig/lib/Twig/Node/Expression/Test.php b/core/vendor/twig/twig/lib/Twig/Node/Expression/Test.php index c0358c8..80f4b69 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/Expression/Test.php +++ b/core/vendor/twig/twig/lib/Twig/Node/Expression/Test.php @@ -10,7 +10,7 @@ */ class Twig_Node_Expression_Test extends Twig_Node_Expression_Call { - public function __construct(Twig_NodeInterface $node, $name, Twig_NodeInterface $arguments = null, $lineno) + public function __construct(Twig_Node $node, $name, Twig_Node $arguments = null, $lineno) { parent::__construct(array('node' => $node, 'arguments' => $arguments), array('name' => $name), $lineno); } @@ -22,13 +22,8 @@ public function compile(Twig_Compiler $compiler) $this->setAttribute('name', $name); $this->setAttribute('type', 'test'); - $this->setAttribute('thing', $test); - if ($test instanceof Twig_TestCallableInterface || $test instanceof Twig_SimpleTest) { - $this->setAttribute('callable', $test->getCallable()); - } - if ($test instanceof Twig_SimpleTest) { - $this->setAttribute('is_variadic', $test->isVariadic()); - } + $this->setAttribute('callable', $test->getCallable()); + $this->setAttribute('is_variadic', $test->isVariadic()); $this->compileCallable($compiler); } diff --git a/core/vendor/twig/twig/lib/Twig/Node/Expression/Test/Defined.php b/core/vendor/twig/twig/lib/Twig/Node/Expression/Test/Defined.php index 247b2e2..eb73578 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/Expression/Test/Defined.php +++ b/core/vendor/twig/twig/lib/Twig/Node/Expression/Test/Defined.php @@ -23,7 +23,7 @@ */ class Twig_Node_Expression_Test_Defined extends Twig_Node_Expression_Test { - public function __construct(Twig_NodeInterface $node, $name, Twig_NodeInterface $arguments = null, $lineno) + public function __construct(Twig_Node $node, $name, Twig_Node $arguments = null, $lineno) { parent::__construct($node, $name, $arguments, $lineno); @@ -38,7 +38,7 @@ public function __construct(Twig_NodeInterface $node, $name, Twig_NodeInterface } } - protected function changeIgnoreStrictCheck(Twig_Node_Expression_GetAttr $node) + private function changeIgnoreStrictCheck(Twig_Node_Expression_GetAttr $node) { $node->setAttribute('ignore_strict_check', true); diff --git a/core/vendor/twig/twig/lib/Twig/Node/Expression/Unary.php b/core/vendor/twig/twig/lib/Twig/Node/Expression/Unary.php index 1cf54c3..ee3af70 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/Expression/Unary.php +++ b/core/vendor/twig/twig/lib/Twig/Node/Expression/Unary.php @@ -11,7 +11,7 @@ */ abstract class Twig_Node_Expression_Unary extends Twig_Node_Expression { - public function __construct(Twig_NodeInterface $node, $lineno) + public function __construct(Twig_Node $node, $lineno) { parent::__construct(array('node' => $node), array(), $lineno); } diff --git a/core/vendor/twig/twig/lib/Twig/Node/For.php b/core/vendor/twig/twig/lib/Twig/Node/For.php index 36e9de8..2193e42 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/For.php +++ b/core/vendor/twig/twig/lib/Twig/Node/For.php @@ -17,9 +17,9 @@ */ class Twig_Node_For extends Twig_Node { - protected $loop; + private $loop; - public function __construct(Twig_Node_Expression_AssignName $keyTarget, Twig_Node_Expression_AssignName $valueTarget, Twig_Node_Expression $seq, Twig_Node_Expression $ifexpr = null, Twig_NodeInterface $body, Twig_NodeInterface $else = null, $lineno, $tag = null) + public function __construct(Twig_Node_Expression_AssignName $keyTarget, Twig_Node_Expression_AssignName $valueTarget, Twig_Node_Expression $seq, Twig_Node_Expression $ifexpr = null, Twig_Node $body, Twig_Node $else = null, $lineno, $tag = null) { $body = new Twig_Node(array($body, $this->loop = new Twig_Node_ForLoop($lineno, $tag))); @@ -39,8 +39,7 @@ public function compile(Twig_Compiler $compiler) { $compiler ->addDebugInfo($this) - // the (array) cast bypasses a PHP 5.2.6 bug - ->write("\$context['_parent'] = (array) \$context;\n") + ->write("\$context['_parent'] = \$context;\n") ->write("\$context['_seq'] = twig_ensure_traversable(") ->subcompile($this->getNode('seq')) ->raw(");\n") diff --git a/core/vendor/twig/twig/lib/Twig/Node/If.php b/core/vendor/twig/twig/lib/Twig/Node/If.php index 1b6104d..0902d2c 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/If.php +++ b/core/vendor/twig/twig/lib/Twig/Node/If.php @@ -17,7 +17,7 @@ */ class Twig_Node_If extends Twig_Node { - public function __construct(Twig_NodeInterface $tests, Twig_NodeInterface $else = null, $lineno, $tag = null) + public function __construct(Twig_Node $tests, Twig_Node $else = null, $lineno, $tag = null) { parent::__construct(array('tests' => $tests, 'else' => $else), array(), $lineno, $tag); } diff --git a/core/vendor/twig/twig/lib/Twig/Node/Macro.php b/core/vendor/twig/twig/lib/Twig/Node/Macro.php index 03cf4dd..10152c9 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/Macro.php +++ b/core/vendor/twig/twig/lib/Twig/Node/Macro.php @@ -18,7 +18,7 @@ class Twig_Node_Macro extends Twig_Node { const VARARGS_NAME = 'varargs'; - public function __construct($name, Twig_NodeInterface $body, Twig_NodeInterface $arguments, $lineno, $tag = null) + public function __construct($name, Twig_Node $body, Twig_Node $arguments, $lineno, $tag = null) { foreach ($arguments as $argumentName => $argument) { if (self::VARARGS_NAME === $argumentName) { @@ -38,7 +38,7 @@ public function compile(Twig_Compiler $compiler) { $compiler ->addDebugInfo($this) - ->write(sprintf('public function get%s(', $this->getAttribute('name'))) + ->write(sprintf('public function macro_%s(', $this->getAttribute('name'))) ; $count = count($this->getNode('arguments')); diff --git a/core/vendor/twig/twig/lib/Twig/Node/Module.php b/core/vendor/twig/twig/lib/Twig/Node/Module.php index 1bc4fea..cd3252d 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/Module.php +++ b/core/vendor/twig/twig/lib/Twig/Node/Module.php @@ -21,7 +21,7 @@ */ class Twig_Node_Module extends Twig_Node { - public function __construct(Twig_NodeInterface $body, Twig_Node_Expression $parent = null, Twig_NodeInterface $blocks, Twig_NodeInterface $macros, Twig_NodeInterface $traits, $embeddedTemplates, $filename) + public function __construct(Twig_Node $body, Twig_Node_Expression $parent = null, Twig_Node $blocks, Twig_Node $macros, Twig_Node $traits, $embeddedTemplates, $filename) { // embedded templates are set as attributes so that they are only visited once by the visitors parent::__construct(array( @@ -173,7 +173,17 @@ protected function compileConstructor(Twig_Compiler $compiler) if ($countTraits) { // traits foreach ($this->getNode('traits') as $i => $trait) { - $this->compileLoadTemplate($compiler, $trait->getNode('template'), sprintf('$_trait_%s', $i)); + $node = $trait->getNode('template'); + + $compiler + ->write(sprintf('$_trait_%s = $this->loadTemplate(', $i)) + ->subcompile($node) + ->raw(', ') + ->repr($compiler->getFilename()) + ->raw(', ') + ->repr($node->getLine()) + ->raw(");\n") + ; $compiler ->addDebugInfo($trait->getNode('template')) @@ -388,21 +398,4 @@ protected function compileDebugInfo(Twig_Compiler $compiler) ->write("}\n") ; } - - protected function compileLoadTemplate(Twig_Compiler $compiler, $node, $var) - { - if ($node instanceof Twig_Node_Expression_Constant) { - $compiler - ->write(sprintf('%s = $this->loadTemplate(', $var)) - ->subcompile($node) - ->raw(', ') - ->repr($compiler->getFilename()) - ->raw(', ') - ->repr($node->getLine()) - ->raw(");\n") - ; - } else { - throw new LogicException('Trait templates can only be constant nodes'); - } - } } diff --git a/core/vendor/twig/twig/lib/Twig/Node/Sandbox.php b/core/vendor/twig/twig/lib/Twig/Node/Sandbox.php index 8ca772b..653f37f 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/Sandbox.php +++ b/core/vendor/twig/twig/lib/Twig/Node/Sandbox.php @@ -16,7 +16,7 @@ */ class Twig_Node_Sandbox extends Twig_Node { - public function __construct(Twig_NodeInterface $body, $lineno, $tag = null) + public function __construct(Twig_Node $body, $lineno, $tag = null) { parent::__construct(array('body' => $body), array(), $lineno, $tag); } diff --git a/core/vendor/twig/twig/lib/Twig/Node/SandboxedPrint.php b/core/vendor/twig/twig/lib/Twig/Node/SandboxedPrint.php index 823e7ac..0ba7dbc 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/SandboxedPrint.php +++ b/core/vendor/twig/twig/lib/Twig/Node/SandboxedPrint.php @@ -50,7 +50,7 @@ public function compile(Twig_Compiler $compiler) * * @return Twig_Node */ - protected function removeNodeFilter($node) + private function removeNodeFilter($node) { if ($node instanceof Twig_Node_Expression_Filter) { return $this->removeNodeFilter($node->getNode('node')); diff --git a/core/vendor/twig/twig/lib/Twig/Node/Set.php b/core/vendor/twig/twig/lib/Twig/Node/Set.php index 407d147..fc11f36 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/Set.php +++ b/core/vendor/twig/twig/lib/Twig/Node/Set.php @@ -16,7 +16,7 @@ */ class Twig_Node_Set extends Twig_Node { - public function __construct($capture, Twig_NodeInterface $names, Twig_NodeInterface $values, $lineno, $tag = null) + public function __construct($capture, Twig_Node $names, Twig_Node $values, $lineno, $tag = null) { parent::__construct(array('names' => $names, 'values' => $values), array('capture' => $capture, 'safe' => false), $lineno, $tag); diff --git a/core/vendor/twig/twig/lib/Twig/Node/SetTemp.php b/core/vendor/twig/twig/lib/Twig/Node/SetTemp.php deleted file mode 100644 index 3bdd1cb..0000000 --- a/core/vendor/twig/twig/lib/Twig/Node/SetTemp.php +++ /dev/null @@ -1,35 +0,0 @@ - $name), $lineno); - } - - public function compile(Twig_Compiler $compiler) - { - $name = $this->getAttribute('name'); - $compiler - ->addDebugInfo($this) - ->write('if (isset($context[') - ->string($name) - ->raw('])) { $_') - ->raw($name) - ->raw('_ = $context[') - ->repr($name) - ->raw(']; } else { $_') - ->raw($name) - ->raw("_ = null; }\n") - ; - } -} diff --git a/core/vendor/twig/twig/lib/Twig/Node/Spaceless.php b/core/vendor/twig/twig/lib/Twig/Node/Spaceless.php index 1478c59..b649fac 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/Spaceless.php +++ b/core/vendor/twig/twig/lib/Twig/Node/Spaceless.php @@ -18,7 +18,7 @@ */ class Twig_Node_Spaceless extends Twig_Node { - public function __construct(Twig_NodeInterface $body, $lineno, $tag = 'spaceless') + public function __construct(Twig_Node $body, $lineno, $tag = 'spaceless') { parent::__construct(array('body' => $body), array(), $lineno, $tag); } diff --git a/core/vendor/twig/twig/lib/Twig/NodeInterface.php b/core/vendor/twig/twig/lib/Twig/NodeInterface.php deleted file mode 100644 index 8077349..0000000 --- a/core/vendor/twig/twig/lib/Twig/NodeInterface.php +++ /dev/null @@ -1,31 +0,0 @@ - - * - * @deprecated since 1.12 (to be removed in 3.0) - */ -interface Twig_NodeInterface extends Countable, IteratorAggregate -{ - /** - * Compiles the node to PHP. - * - * @param Twig_Compiler $compiler A Twig_Compiler instance - */ - public function compile(Twig_Compiler $compiler); - - public function getLine(); - - public function getNodeTag(); -} diff --git a/core/vendor/twig/twig/lib/Twig/NodeTraverser.php b/core/vendor/twig/twig/lib/Twig/NodeTraverser.php index 00f7b54..f149265 100644 --- a/core/vendor/twig/twig/lib/Twig/NodeTraverser.php +++ b/core/vendor/twig/twig/lib/Twig/NodeTraverser.php @@ -18,8 +18,8 @@ */ class Twig_NodeTraverser { - protected $env; - protected $visitors = array(); + private $env; + private $visitors = array(); /** * Constructor. @@ -52,11 +52,11 @@ public function addVisitor(Twig_NodeVisitorInterface $visitor) /** * Traverses a node and calls the registered visitors. * - * @param Twig_NodeInterface $node A Twig_NodeInterface instance + * @param Twig_Node $node A Twig_Node instance * - * @return Twig_NodeInterface + * @return Twig_Node */ - public function traverse(Twig_NodeInterface $node) + public function traverse(Twig_Node $node) { ksort($this->visitors); foreach ($this->visitors as $visitors) { @@ -68,7 +68,7 @@ public function traverse(Twig_NodeInterface $node) return $node; } - protected function traverseForVisitor(Twig_NodeVisitorInterface $visitor, Twig_NodeInterface $node = null) + private function traverseForVisitor(Twig_NodeVisitorInterface $visitor, Twig_Node $node = null) { if (null === $node) { return; diff --git a/core/vendor/twig/twig/lib/Twig/NodeVisitor/Escaper.php b/core/vendor/twig/twig/lib/Twig/NodeVisitor/Escaper.php index 5c94977..9c38121 100644 --- a/core/vendor/twig/twig/lib/Twig/NodeVisitor/Escaper.php +++ b/core/vendor/twig/twig/lib/Twig/NodeVisitor/Escaper.php @@ -16,12 +16,12 @@ */ class Twig_NodeVisitor_Escaper extends Twig_BaseNodeVisitor { - protected $statusStack = array(); - protected $blocks = array(); - protected $safeAnalysis; - protected $traverser; - protected $defaultStrategy = false; - protected $safeVars = array(); + private $statusStack = array(); + private $blocks = array(); + private $safeAnalysis; + private $traverser; + private $defaultStrategy = false; + private $safeVars = array(); public function __construct() { @@ -72,7 +72,7 @@ protected function doLeaveNode(Twig_Node $node, Twig_Environment $env) return $node; } - protected function escapePrintNode(Twig_Node_Print $node, Twig_Environment $env, $type) + private function escapePrintNode(Twig_Node_Print $node, Twig_Environment $env, $type) { if (false === $type) { return $node; @@ -92,7 +92,7 @@ protected function escapePrintNode(Twig_Node_Print $node, Twig_Environment $env, ); } - protected function preEscapeFilterNode(Twig_Node_Expression_Filter $filter, Twig_Environment $env) + private function preEscapeFilterNode(Twig_Node_Expression_Filter $filter, Twig_Environment $env) { $name = $filter->getNode('filter')->getAttribute('value'); @@ -111,7 +111,7 @@ protected function preEscapeFilterNode(Twig_Node_Expression_Filter $filter, Twig return $filter; } - protected function isSafeFor($type, Twig_NodeInterface $expression, $env) + private function isSafeFor($type, Twig_Node $expression, $env) { $safe = $this->safeAnalysis->getSafe($expression); @@ -129,7 +129,7 @@ protected function isSafeFor($type, Twig_NodeInterface $expression, $env) return in_array($type, $safe) || in_array('all', $safe); } - protected function needEscaping(Twig_Environment $env) + private function needEscaping(Twig_Environment $env) { if (count($this->statusStack)) { return $this->statusStack[count($this->statusStack) - 1]; @@ -138,7 +138,7 @@ protected function needEscaping(Twig_Environment $env) return $this->defaultStrategy ? $this->defaultStrategy : false; } - protected function getEscaperFilter($type, Twig_NodeInterface $node) + private function getEscaperFilter($type, Twig_Node $node) { $line = $node->getLine(); $name = new Twig_Node_Expression_Constant('escape', $line); diff --git a/core/vendor/twig/twig/lib/Twig/NodeVisitor/Optimizer.php b/core/vendor/twig/twig/lib/Twig/NodeVisitor/Optimizer.php index 872b7fe..8a7cfa1 100644 --- a/core/vendor/twig/twig/lib/Twig/NodeVisitor/Optimizer.php +++ b/core/vendor/twig/twig/lib/Twig/NodeVisitor/Optimizer.php @@ -25,13 +25,12 @@ class Twig_NodeVisitor_Optimizer extends Twig_BaseNodeVisitor const OPTIMIZE_NONE = 0; const OPTIMIZE_FOR = 2; const OPTIMIZE_RAW_FILTER = 4; + // obsolete, does not do anything const OPTIMIZE_VAR_ACCESS = 8; - protected $loops = array(); - protected $loopsTargets = array(); - protected $optimizers; - protected $prependedNodes = array(); - protected $inABody = false; + private $loops = array(); + private $loopsTargets = array(); + private $optimizers; /** * Constructor. @@ -56,20 +55,6 @@ protected function doEnterNode(Twig_Node $node, Twig_Environment $env) $this->enterOptimizeFor($node, $env); } - if (PHP_VERSION_ID < 50400 && self::OPTIMIZE_VAR_ACCESS === (self::OPTIMIZE_VAR_ACCESS & $this->optimizers) && !$env->isStrictVariables() && !$env->hasExtension('sandbox')) { - if ($this->inABody) { - if (!$node instanceof Twig_Node_Expression) { - if (get_class($node) !== 'Twig_Node') { - array_unshift($this->prependedNodes, array()); - } - } else { - $node = $this->optimizeVariables($node, $env); - } - } elseif ($node instanceof Twig_Node_Body) { - $this->inABody = true; - } - } - return $node; } @@ -78,8 +63,6 @@ protected function doEnterNode(Twig_Node $node, Twig_Environment $env) */ protected function doLeaveNode(Twig_Node $node, Twig_Environment $env) { - $expression = $node instanceof Twig_Node_Expression; - if (self::OPTIMIZE_FOR === (self::OPTIMIZE_FOR & $this->optimizers)) { $this->leaveOptimizeFor($node, $env); } @@ -90,33 +73,6 @@ protected function doLeaveNode(Twig_Node $node, Twig_Environment $env) $node = $this->optimizePrintNode($node, $env); - if (self::OPTIMIZE_VAR_ACCESS === (self::OPTIMIZE_VAR_ACCESS & $this->optimizers) && !$env->isStrictVariables() && !$env->hasExtension('sandbox')) { - if ($node instanceof Twig_Node_Body) { - $this->inABody = false; - } elseif ($this->inABody) { - if (!$expression && get_class($node) !== 'Twig_Node' && $prependedNodes = array_shift($this->prependedNodes)) { - $nodes = array(); - foreach (array_unique($prependedNodes) as $name) { - $nodes[] = new Twig_Node_SetTemp($name, $node->getLine()); - } - - $nodes[] = $node; - $node = new Twig_Node($nodes); - } - } - } - - return $node; - } - - protected function optimizeVariables(Twig_NodeInterface $node, Twig_Environment $env) - { - if ('Twig_Node_Expression_Name' === get_class($node) && $node->isSimple()) { - $this->prependedNodes[0][] = $node->getAttribute('name'); - - return new Twig_Node_Expression_TempName($node->getAttribute('name'), $node->getLine()); - } - return $node; } @@ -127,12 +83,12 @@ protected function optimizeVariables(Twig_NodeInterface $node, Twig_Environment * * * "echo $this->render(Parent)Block()" with "$this->display(Parent)Block()" * - * @param Twig_NodeInterface $node A Node - * @param Twig_Environment $env The current Twig environment + * @param Twig_Node $node A Node + * @param Twig_Environment $env The current Twig environment * * @return Twig_NodeInterface */ - protected function optimizePrintNode(Twig_NodeInterface $node, Twig_Environment $env) + private function optimizePrintNode(Twig_Node $node, Twig_Environment $env) { if (!$node instanceof Twig_Node_Print) { return $node; @@ -153,12 +109,12 @@ protected function optimizePrintNode(Twig_NodeInterface $node, Twig_Environment /** * Removes "raw" filters. * - * @param Twig_NodeInterface $node A Node - * @param Twig_Environment $env The current Twig environment + * @param Twig_Node $node A Node + * @param Twig_Environment $env The current Twig environment * - * @return Twig_NodeInterface + * @return Twig_Node */ - protected function optimizeRawFilter(Twig_NodeInterface $node, Twig_Environment $env) + private function optimizeRawFilter(Twig_Node $node, Twig_Environment $env) { if ($node instanceof Twig_Node_Expression_Filter && 'raw' == $node->getNode('filter')->getAttribute('value')) { return $node->getNode('node'); @@ -170,10 +126,10 @@ protected function optimizeRawFilter(Twig_NodeInterface $node, Twig_Environment /** * Optimizes "for" tag by removing the "loop" variable creation whenever possible. * - * @param Twig_NodeInterface $node A Node - * @param Twig_Environment $env The current Twig environment + * @param Twig_Node $node A Node + * @param Twig_Environment $env The current Twig environment */ - protected function enterOptimizeFor(Twig_NodeInterface $node, Twig_Environment $env) + private function enterOptimizeFor(Twig_Node $node, Twig_Environment $env) { if ($node instanceof Twig_Node_For) { // disable the loop variable by default @@ -237,10 +193,10 @@ protected function enterOptimizeFor(Twig_NodeInterface $node, Twig_Environment $ /** * Optimizes "for" tag by removing the "loop" variable creation whenever possible. * - * @param Twig_NodeInterface $node A Node - * @param Twig_Environment $env The current Twig environment + * @param Twig_Node $node A Node + * @param Twig_Environment $env The current Twig environment */ - protected function leaveOptimizeFor(Twig_NodeInterface $node, Twig_Environment $env) + private function leaveOptimizeFor(Twig_Node $node, Twig_Environment $env) { if ($node instanceof Twig_Node_For) { array_shift($this->loops); @@ -249,12 +205,12 @@ protected function leaveOptimizeFor(Twig_NodeInterface $node, Twig_Environment $ } } - protected function addLoopToCurrent() + private function addLoopToCurrent() { $this->loops[0]->setAttribute('with_loop', true); } - protected function addLoopToAll() + private function addLoopToAll() { foreach ($this->loops as $loop) { $loop->setAttribute('with_loop', true); diff --git a/core/vendor/twig/twig/lib/Twig/NodeVisitor/SafeAnalysis.php b/core/vendor/twig/twig/lib/Twig/NodeVisitor/SafeAnalysis.php index 439f5bf..ce04d9a 100644 --- a/core/vendor/twig/twig/lib/Twig/NodeVisitor/SafeAnalysis.php +++ b/core/vendor/twig/twig/lib/Twig/NodeVisitor/SafeAnalysis.php @@ -11,15 +11,15 @@ class Twig_NodeVisitor_SafeAnalysis extends Twig_BaseNodeVisitor { - protected $data = array(); - protected $safeVars = array(); + private $data = array(); + private $safeVars = array(); public function setSafeVars($safeVars) { $this->safeVars = $safeVars; } - public function getSafe(Twig_NodeInterface $node) + public function getSafe(Twig_Node $node) { $hash = spl_object_hash($node); if (!isset($this->data[$hash])) { @@ -39,7 +39,7 @@ public function getSafe(Twig_NodeInterface $node) } } - protected function setSafe(Twig_NodeInterface $node, array $safe) + private function setSafe(Twig_Node $node, array $safe) { $hash = spl_object_hash($node); if (isset($this->data[$hash])) { @@ -114,8 +114,7 @@ protected function doLeaveNode(Twig_Node $node, Twig_Environment $env) } } elseif ($node instanceof Twig_Node_Expression_GetAttr && $node->getNode('node') instanceof Twig_Node_Expression_Name) { $name = $node->getNode('node')->getAttribute('name'); - // attributes on template instances are safe - if ('_self' == $name || in_array($name, $this->safeVars)) { + if (in_array($name, $this->safeVars)) { $this->setSafe($node, array('all')); } else { $this->setSafe($node, array()); @@ -127,7 +126,7 @@ protected function doLeaveNode(Twig_Node $node, Twig_Environment $env) return $node; } - protected function intersectSafe(array $a = null, array $b = null) + private function intersectSafe(array $a = null, array $b = null) { if (null === $a || null === $b) { return array(); diff --git a/core/vendor/twig/twig/lib/Twig/NodeVisitor/Sandbox.php b/core/vendor/twig/twig/lib/Twig/NodeVisitor/Sandbox.php index 7f1b913..5e1e468 100644 --- a/core/vendor/twig/twig/lib/Twig/NodeVisitor/Sandbox.php +++ b/core/vendor/twig/twig/lib/Twig/NodeVisitor/Sandbox.php @@ -16,10 +16,10 @@ */ class Twig_NodeVisitor_Sandbox extends Twig_BaseNodeVisitor { - protected $inAModule = false; - protected $tags; - protected $filters; - protected $functions; + private $inAModule = false; + private $tags; + private $filters; + private $functions; /** * {@inheritdoc} diff --git a/core/vendor/twig/twig/lib/Twig/NodeVisitorInterface.php b/core/vendor/twig/twig/lib/Twig/NodeVisitorInterface.php index f276163..6e11072 100644 --- a/core/vendor/twig/twig/lib/Twig/NodeVisitorInterface.php +++ b/core/vendor/twig/twig/lib/Twig/NodeVisitorInterface.php @@ -19,22 +19,22 @@ /** * Called before child nodes are visited. * - * @param Twig_NodeInterface $node The node to visit - * @param Twig_Environment $env The Twig environment instance + * @param Twig_Node $node The node to visit + * @param Twig_Environment $env The Twig environment instance * - * @return Twig_NodeInterface The modified node + * @return Twig_Node The modified node */ - public function enterNode(Twig_NodeInterface $node, Twig_Environment $env); + public function enterNode(Twig_Node $node, Twig_Environment $env); /** * Called after child nodes are visited. * - * @param Twig_NodeInterface $node The node to visit - * @param Twig_Environment $env The Twig environment instance + * @param Twig_Node $node The node to visit + * @param Twig_Environment $env The Twig environment instance * - * @return Twig_NodeInterface|false The modified node or false if the node must be removed + * @return Twig_Node|false The modified node or false if the node must be removed */ - public function leaveNode(Twig_NodeInterface $node, Twig_Environment $env); + public function leaveNode(Twig_Node $node, Twig_Environment $env); /** * Returns the priority for this visitor. diff --git a/core/vendor/twig/twig/lib/Twig/Parser.php b/core/vendor/twig/twig/lib/Twig/Parser.php index 6f24ee6..0397061 100644 --- a/core/vendor/twig/twig/lib/Twig/Parser.php +++ b/core/vendor/twig/twig/lib/Twig/Parser.php @@ -15,22 +15,21 @@ * * @author Fabien Potencier */ -class Twig_Parser implements Twig_ParserInterface +class Twig_Parser { - protected $stack = array(); - protected $stream; - protected $parent; - protected $handlers; - protected $visitors; - protected $expressionParser; - protected $blocks; - protected $blockStack; - protected $macros; - protected $env; - protected $reservedMacroNames; - protected $importedSymbols; - protected $traits; - protected $embeddedTemplates = array(); + private $stack = array(); + private $stream; + private $parent; + private $handlers; + private $visitors; + private $expressionParser; + private $blocks; + private $blockStack; + private $macros; + private $env; + private $importedSymbols; + private $traits; + private $embeddedTemplates = array(); /** * Constructor. @@ -69,8 +68,12 @@ public function parse(Twig_TokenStream $stream, $test = null, $dropNeedle = fals // tag handlers if (null === $this->handlers) { - $this->handlers = $this->env->getTokenParsers(); - $this->handlers->setParser($this); + $this->handlers = array(); + foreach ($this->env->getTokenParsers() as $handler) { + $handler->setParser($this); + + $this->handlers[$handler->getTag()] = $handler; + } } // node visitors @@ -151,7 +154,7 @@ public function subparse($test, $dropNeedle = false) throw new Twig_Error_Syntax('A block must start with a tag name', $token->getLine(), $this->getFilename()); } - if (null !== $test && call_user_func($test, $token)) { + if (null !== $test && $test($token)) { if ($dropNeedle) { $this->stream->next(); } @@ -163,8 +166,7 @@ public function subparse($test, $dropNeedle = false) return new Twig_Node($rv, array(), $lineno); } - $subparser = $this->handlers->getTokenParser($token->getValue()); - if (null === $subparser) { + if (!isset($this->handlers[$token->getValue()])) { if (null !== $test) { $error = sprintf('Unexpected tag name "%s"', $token->getValue()); if (is_array($test) && isset($test[0]) && $test[0] instanceof Twig_TokenParserInterface) { @@ -184,6 +186,7 @@ public function subparse($test, $dropNeedle = false) $this->stream->next(); + $subparser = $this->handlers[$token->getValue()]; $node = $subparser->parse($token); if (null !== $node) { $rv[] = $node; @@ -254,28 +257,17 @@ public function hasMacro($name) public function setMacro($name, Twig_Node_Macro $node) { - if ($this->isReservedMacroName($name)) { - throw new Twig_Error_Syntax(sprintf('"%s" cannot be used as a macro name as it is a reserved keyword', $name), $node->getLine(), $this->getFilename()); - } - $this->macros[$name] = $node; } + /** + * @deprecated since 2.0. Will be removed in 3.0. There is no reserved macro names anymore + */ public function isReservedMacroName($name) { - if (null === $this->reservedMacroNames) { - $this->reservedMacroNames = array(); - $r = new ReflectionClass($this->env->getBaseTemplateClass()); - foreach ($r->getMethods() as $method) { - $methodName = strtolower($method->getName()); - - if ('get' === substr($methodName, 0, 3) && isset($methodName[3])) { - $this->reservedMacroNames[] = substr($methodName, 3); - } - } - } + @trigger_error('The '.__METHOD__.' method is deprecated since version 2.0 and will be removed in 3.0.', E_USER_DEPRECATED); - return in_array(strtolower($name), $this->reservedMacroNames); + return false; } public function addTrait($trait) @@ -364,7 +356,7 @@ public function getCurrentToken() return $this->stream->getCurrent(); } - protected function filterBodyNodes(Twig_NodeInterface $node) + private function filterBodyNodes(Twig_Node $node) { // check that the body does not contain non-empty output nodes if ( diff --git a/core/vendor/twig/twig/lib/Twig/ParserInterface.php b/core/vendor/twig/twig/lib/Twig/ParserInterface.php deleted file mode 100644 index 8e7cc0a..0000000 --- a/core/vendor/twig/twig/lib/Twig/ParserInterface.php +++ /dev/null @@ -1,31 +0,0 @@ - - * - * @deprecated since 1.12 (to be removed in 3.0) - */ -interface Twig_ParserInterface -{ - /** - * Converts a token stream to a node tree. - * - * @param Twig_TokenStream $stream A token stream instance - * - * @return Twig_Node_Module A node tree - * - * @throws Twig_Error_Syntax When the token stream is syntactically or semantically wrong - */ - public function parse(Twig_TokenStream $stream); -} diff --git a/core/vendor/twig/twig/lib/Twig/Sandbox/SecurityPolicy.php b/core/vendor/twig/twig/lib/Twig/Sandbox/SecurityPolicy.php index c4dd03d..bd04813 100644 --- a/core/vendor/twig/twig/lib/Twig/Sandbox/SecurityPolicy.php +++ b/core/vendor/twig/twig/lib/Twig/Sandbox/SecurityPolicy.php @@ -16,11 +16,11 @@ */ class Twig_Sandbox_SecurityPolicy implements Twig_Sandbox_SecurityPolicyInterface { - protected $allowedTags; - protected $allowedFilters; - protected $allowedMethods; - protected $allowedProperties; - protected $allowedFunctions; + private $allowedTags; + private $allowedFilters; + private $allowedMethods; + private $allowedProperties; + private $allowedFunctions; public function __construct(array $allowedTags = array(), array $allowedFilters = array(), array $allowedMethods = array(), array $allowedProperties = array(), array $allowedFunctions = array()) { @@ -82,7 +82,7 @@ public function checkSecurity($tags, $filters, $functions) public function checkMethodAllowed($obj, $method) { - if ($obj instanceof Twig_TemplateInterface || $obj instanceof Twig_Markup) { + if ($obj instanceof Twig_Template || $obj instanceof Twig_Markup) { return true; } diff --git a/core/vendor/twig/twig/lib/Twig/SimpleFilter.php b/core/vendor/twig/twig/lib/Twig/SimpleFilter.php index cefc4f5..b5aaa39 100644 --- a/core/vendor/twig/twig/lib/Twig/SimpleFilter.php +++ b/core/vendor/twig/twig/lib/Twig/SimpleFilter.php @@ -3,110 +3,17 @@ /* * This file is part of Twig. * - * (c) 2009-2012 Fabien Potencier + * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ /** - * Represents a template filter. + * Empty class for Twig 1.x compatibility. * - * @author Fabien Potencier + * @deprecated to be removed in 3.0 */ -class Twig_SimpleFilter +class Twig_SimpleFilter extends Twig_Filter { - protected $name; - protected $callable; - protected $options; - protected $arguments = array(); - - public function __construct($name, $callable, array $options = array()) - { - $this->name = $name; - $this->callable = $callable; - $this->options = array_merge(array( - 'needs_environment' => false, - 'needs_context' => false, - 'is_variadic' => false, - 'is_safe' => null, - 'is_safe_callback' => null, - 'pre_escape' => null, - 'preserves_safety' => null, - 'node_class' => 'Twig_Node_Expression_Filter', - 'deprecated' => false, - 'alternative' => null, - ), $options); - } - - public function getName() - { - return $this->name; - } - - public function getCallable() - { - return $this->callable; - } - - public function getNodeClass() - { - return $this->options['node_class']; - } - - public function setArguments($arguments) - { - $this->arguments = $arguments; - } - - public function getArguments() - { - return $this->arguments; - } - - public function needsEnvironment() - { - return $this->options['needs_environment']; - } - - public function needsContext() - { - return $this->options['needs_context']; - } - - public function getSafe(Twig_Node $filterArgs) - { - if (null !== $this->options['is_safe']) { - return $this->options['is_safe']; - } - - if (null !== $this->options['is_safe_callback']) { - return call_user_func($this->options['is_safe_callback'], $filterArgs); - } - } - - public function getPreservesSafety() - { - return $this->options['preserves_safety']; - } - - public function getPreEscape() - { - return $this->options['pre_escape']; - } - - public function isVariadic() - { - return $this->options['is_variadic']; - } - - public function isDeprecated() - { - return $this->options['deprecated']; - } - - public function getAlternative() - { - return $this->options['alternative']; - } } diff --git a/core/vendor/twig/twig/lib/Twig/SimpleFunction.php b/core/vendor/twig/twig/lib/Twig/SimpleFunction.php index 7973540..4a716b6 100644 --- a/core/vendor/twig/twig/lib/Twig/SimpleFunction.php +++ b/core/vendor/twig/twig/lib/Twig/SimpleFunction.php @@ -3,100 +3,17 @@ /* * This file is part of Twig. * - * (c) 2010-2012 Fabien Potencier + * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ /** - * Represents a template function. + * Empty class for Twig 1.x compatibility. * - * @author Fabien Potencier + * @deprecated to be removed in 3.0 */ -class Twig_SimpleFunction +class Twig_SimpleFunction extends Twig_Function { - protected $name; - protected $callable; - protected $options; - protected $arguments = array(); - - public function __construct($name, $callable, array $options = array()) - { - $this->name = $name; - $this->callable = $callable; - $this->options = array_merge(array( - 'needs_environment' => false, - 'needs_context' => false, - 'is_variadic' => false, - 'is_safe' => null, - 'is_safe_callback' => null, - 'node_class' => 'Twig_Node_Expression_Function', - 'deprecated' => false, - 'alternative' => null, - ), $options); - } - - public function getName() - { - return $this->name; - } - - public function getCallable() - { - return $this->callable; - } - - public function getNodeClass() - { - return $this->options['node_class']; - } - - public function setArguments($arguments) - { - $this->arguments = $arguments; - } - - public function getArguments() - { - return $this->arguments; - } - - public function needsEnvironment() - { - return $this->options['needs_environment']; - } - - public function needsContext() - { - return $this->options['needs_context']; - } - - public function getSafe(Twig_Node $functionArgs) - { - if (null !== $this->options['is_safe']) { - return $this->options['is_safe']; - } - - if (null !== $this->options['is_safe_callback']) { - return call_user_func($this->options['is_safe_callback'], $functionArgs); - } - - return array(); - } - - public function isVariadic() - { - return $this->options['is_variadic']; - } - - public function isDeprecated() - { - return $this->options['deprecated']; - } - - public function getAlternative() - { - return $this->options['alternative']; - } } diff --git a/core/vendor/twig/twig/lib/Twig/SimpleTest.php b/core/vendor/twig/twig/lib/Twig/SimpleTest.php index 8ba2192..0f49d72 100644 --- a/core/vendor/twig/twig/lib/Twig/SimpleTest.php +++ b/core/vendor/twig/twig/lib/Twig/SimpleTest.php @@ -3,62 +3,17 @@ /* * This file is part of Twig. * - * (c) 2010-2012 Fabien Potencier + * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ /** - * Represents a template test. + * Empty class for Twig 1.x compatibility. * - * @author Fabien Potencier + * @deprecated to be removed in 3.0 */ -class Twig_SimpleTest +class Twig_SimpleTest extends Twig_Test { - protected $name; - protected $callable; - protected $options; - - public function __construct($name, $callable, array $options = array()) - { - $this->name = $name; - $this->callable = $callable; - $this->options = array_merge(array( - 'is_variadic' => false, - 'node_class' => 'Twig_Node_Expression_Test', - 'deprecated' => false, - 'alternative' => null, - ), $options); - } - - public function getName() - { - return $this->name; - } - - public function getCallable() - { - return $this->callable; - } - - public function getNodeClass() - { - return $this->options['node_class']; - } - - public function isVariadic() - { - return $this->options['is_variadic']; - } - - public function isDeprecated() - { - return $this->options['deprecated']; - } - - public function getAlternative() - { - return $this->options['alternative']; - } } diff --git a/core/vendor/twig/twig/lib/Twig/Template.php b/core/vendor/twig/twig/lib/Twig/Template.php index e2ab05a..6bccfe7 100644 --- a/core/vendor/twig/twig/lib/Twig/Template.php +++ b/core/vendor/twig/twig/lib/Twig/Template.php @@ -15,8 +15,12 @@ * * @author Fabien Potencier */ -abstract class Twig_Template implements Twig_TemplateInterface +abstract class Twig_Template { + const ANY_CALL = 'any'; + const ARRAY_CALL = 'array'; + const METHOD_CALL = 'method'; + protected static $cache = array(); protected $parent; @@ -43,16 +47,6 @@ public function __construct(Twig_Environment $env) abstract public function getTemplateName(); /** - * @deprecated since 1.20 (to be removed in 2.0) - */ - public function getEnvironment() - { - @trigger_error('The '.__METHOD__.' method is deprecated since version 1.20 and will be removed in 2.0.', E_USER_DEPRECATED); - - return $this->env; - } - - /** * Returns the parent template. * * This method is for internal use only and should never be called @@ -60,7 +54,7 @@ public function getEnvironment() * * @param array $context * - * @return Twig_TemplateInterface|false The parent template or false if there is no parent + * @return Twig_Template|false The parent template or false if there is no parent */ public function getParent(array $context) { @@ -114,8 +108,6 @@ public function isTraitable() */ public function displayParentBlock($name, array $context, array $blocks = array()) { - $name = (string) $name; - if (isset($this->traits[$name])) { $this->traits[$name][0]->displayBlock($name, $context, $blocks, false); } elseif (false !== $parent = $this->getParent($context)) { @@ -138,8 +130,6 @@ public function displayParentBlock($name, array $context, array $blocks = array( */ public function displayBlock($name, array $context, array $blocks = array(), $useBlocks = true) { - $name = (string) $name; - if ($useBlocks && isset($blocks[$name])) { $template = $blocks[$name][0]; $block = $blocks[$name][1]; @@ -240,7 +230,7 @@ public function renderBlock($name, array $context, array $blocks = array(), $use */ public function hasBlock($name) { - return isset($this->blocks[(string) $name]); + return isset($this->blocks[$name]); } /** @@ -363,35 +353,18 @@ protected function displayWithErrorHandling(array $context, array $blocks = arra abstract protected function doDisplay(array $context, array $blocks = array()); /** - * Returns a variable from the context. + * Throws an exception for an unknown variable. * * This method is for internal use only and should never be called * directly. * - * This method should not be overridden in a sub-class as this is an - * implementation detail that has been introduced to optimize variable - * access for versions of PHP before 5.4. This is not a way to override - * the way to get a variable value. - * - * @param array $context The context - * @param string $item The variable to return from the context - * @param bool $ignoreStrictCheck Whether to ignore the strict variable check or not + * This is an implementation detail due to a PHP limitation before version 7.0. * - * @return mixed The content of the context variable - * - * @throws Twig_Error_Runtime if the variable does not exist and Twig is running in strict mode + * @internal */ - final protected function getContext($context, $item, $ignoreStrictCheck = false) + final protected function notFound($name, $line) { - if (!array_key_exists($item, $context)) { - if ($ignoreStrictCheck || !$this->env->isStrictVariables()) { - return; - } - - throw new Twig_Error_Runtime(sprintf('Variable "%s" does not exist', $item), -1, $this->getTemplateName()); - } - - return $context[$item]; + throw new Twig_Error_Runtime(sprintf('Variable "%s" does not exist', $name), $line, $this->getTemplateName()); } /** @@ -502,12 +475,7 @@ protected function getAttribute($object, $item, array $arguments = array(), $typ $methods = array(); foreach ($ref->getMethods(ReflectionMethod::IS_PUBLIC) as $refMethod) { - $methodName = strtolower($refMethod->name); - - // Accessing the environment from templates is forbidden to prevent untrusted changes to the environment - if ('getenvironment' !== $methodName) { - $methods[$methodName] = true; - } + $methods[strtolower($refMethod->name)] = true; } self::$cache[$class]['methods'] = $methods; @@ -560,7 +528,7 @@ protected function getAttribute($object, $item, array $arguments = array(), $typ // useful when calling a template method from a template // this is not supported but unfortunately heavily used in the Symfony profiler - if ($object instanceof Twig_TemplateInterface) { + if ($object instanceof self) { return $ret === '' ? '' : new Twig_Markup($ret, $this->env->getCharset()); } diff --git a/core/vendor/twig/twig/lib/Twig/TemplateInterface.php b/core/vendor/twig/twig/lib/Twig/TemplateInterface.php deleted file mode 100644 index 3274640..0000000 --- a/core/vendor/twig/twig/lib/Twig/TemplateInterface.php +++ /dev/null @@ -1,48 +0,0 @@ - - * - * @deprecated since 1.12 (to be removed in 3.0) - */ -interface Twig_TemplateInterface -{ - const ANY_CALL = 'any'; - const ARRAY_CALL = 'array'; - const METHOD_CALL = 'method'; - - /** - * Renders the template with the given context and returns it as string. - * - * @param array $context An array of parameters to pass to the template - * - * @return string The rendered template - */ - public function render(array $context); - - /** - * Displays the template with the given context. - * - * @param array $context An array of parameters to pass to the template - * @param array $blocks An array of blocks to pass to the template - */ - public function display(array $context, array $blocks = array()); - - /** - * Returns the bound environment for this template. - * - * @return Twig_Environment The current environment - */ - public function getEnvironment(); -} diff --git a/core/vendor/twig/twig/lib/Twig/TemplateIterator.php b/core/vendor/twig/twig/lib/Twig/TemplateIterator.php new file mode 100644 index 0000000..5672963 --- /dev/null +++ b/core/vendor/twig/twig/lib/Twig/TemplateIterator.php @@ -0,0 +1,45 @@ + + */ +class Twig_TemplateIterator implements IteratorAggregate +{ + private $loader; + + public function __construct(Twig_LoaderInterface $loader) + { + $this->loader = $loader; + + $templates = array(); + if ($loader instanceof Twig_Loader_Filesystem) { + foreach ($loader->getNamespaces() as $namespace) { + $paths = $loader->getPaths($namespace); + foreach ($paths as $path) { + foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator(realpath($path)), RecursiveIteratorIterator::LEAVES_ONLY) as $file) { + if (Twig_Loader_Filesystem::MAIN_NAMESPACE === $namespace) { + $templates[] = substr($file->getPathname(), strlen($path) + 1); + } else { + $templates[] = '@'.$namespace.'/'.$file->getPathname(); + } + } + } + } + } + + print_r($templates); + } + + public function getIterator() + { + } +} diff --git a/core/vendor/twig/twig/lib/Twig/Test.php b/core/vendor/twig/twig/lib/Twig/Test.php index 3c2d859..a39d922 100644 --- a/core/vendor/twig/twig/lib/Twig/Test.php +++ b/core/vendor/twig/twig/lib/Twig/Test.php @@ -3,35 +3,76 @@ /* * This file is part of Twig. * - * (c) 2012 Fabien Potencier + * (c) 2010-2012 Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -@trigger_error('The Twig_Test class is deprecated since version 1.12 and will be removed in 2.0. Use Twig_SimpleTest instead.', E_USER_DEPRECATED); - /** * Represents a template test. * * @author Fabien Potencier * - * @deprecated since 1.12 (to be removed in 2.0) + * @see http://twig.sensiolabs.org/doc/templates.html#test-operator */ -abstract class Twig_Test implements Twig_TestInterface, Twig_TestCallableInterface +class Twig_Test { - protected $options; - protected $arguments = array(); + private $name; + private $callable; + private $options; - public function __construct(array $options = array()) + /** + * Creates a template test. + * + * @param string $name Name of this test + * @param callable|null $callable A callable implementing the test. If null, you need to overwrite the "node_class" option to customize compilation. + * @param array $options Options array + */ + public function __construct($name, callable $callable = null, array $options = array()) { + $this->name = $name; + $this->callable = $callable; $this->options = array_merge(array( - 'callable' => null, + 'is_variadic' => false, + 'node_class' => 'Twig_Node_Expression_Test', + 'deprecated' => false, + 'alternative' => null, ), $options); } + public function getName() + { + return $this->name; + } + + /** + * Returns the callable to execute for this test. + * + * @return callable|null + */ public function getCallable() { - return $this->options['callable']; + return $this->callable; + } + + public function getNodeClass() + { + return $this->options['node_class']; + } + + public function isVariadic() + { + return $this->options['is_variadic']; + } + + public function isDeprecated() + { + return $this->options['deprecated']; + } + + public function getAlternative() + { + return $this->options['alternative']; } } diff --git a/core/vendor/twig/twig/lib/Twig/Test/Function.php b/core/vendor/twig/twig/lib/Twig/Test/Function.php deleted file mode 100644 index 5e76c71..0000000 --- a/core/vendor/twig/twig/lib/Twig/Test/Function.php +++ /dev/null @@ -1,38 +0,0 @@ - - * - * @deprecated since 1.12 (to be removed in 2.0) - */ -class Twig_Test_Function extends Twig_Test -{ - protected $function; - - public function __construct($function, array $options = array()) - { - $options['callable'] = $function; - - parent::__construct($options); - - $this->function = $function; - } - - public function compile() - { - return $this->function; - } -} diff --git a/core/vendor/twig/twig/lib/Twig/Test/IntegrationTestCase.php b/core/vendor/twig/twig/lib/Twig/Test/IntegrationTestCase.php index 96892a4..8549c92 100644 --- a/core/vendor/twig/twig/lib/Twig/Test/IntegrationTestCase.php +++ b/core/vendor/twig/twig/lib/Twig/Test/IntegrationTestCase.php @@ -108,12 +108,9 @@ protected function doIntegrationTest($file, $message, $condition, $templates, $e } // avoid using the same PHP class name for different cases - // only for PHP 5.2+ - if (PHP_VERSION_ID >= 50300) { - $p = new ReflectionProperty($twig, 'templateClassPrefix'); - $p->setAccessible(true); - $p->setValue($twig, '__TwigTemplate_'.hash('sha256', uniqid(mt_rand(), true), false).'_'); - } + $p = new ReflectionProperty($twig, 'templateClassPrefix'); + $p->setAccessible(true); + $p->setValue($twig, '__TwigTemplate_'.hash('sha256', uniqid(mt_rand(), true), false).'_'); try { $template = $twig->loadTemplate('index.twig'); diff --git a/core/vendor/twig/twig/lib/Twig/Test/Method.php b/core/vendor/twig/twig/lib/Twig/Test/Method.php deleted file mode 100644 index 2779986..0000000 --- a/core/vendor/twig/twig/lib/Twig/Test/Method.php +++ /dev/null @@ -1,40 +0,0 @@ - - * - * @deprecated since 1.12 (to be removed in 2.0) - */ -class Twig_Test_Method extends Twig_Test -{ - protected $extension; - protected $method; - - public function __construct(Twig_ExtensionInterface $extension, $method, array $options = array()) - { - $options['callable'] = array($extension, $method); - - parent::__construct($options); - - $this->extension = $extension; - $this->method = $method; - } - - public function compile() - { - return sprintf('$this->env->getExtension(\'%s\')->%s', $this->extension->getName(), $this->method); - } -} diff --git a/core/vendor/twig/twig/lib/Twig/Test/Node.php b/core/vendor/twig/twig/lib/Twig/Test/Node.php deleted file mode 100644 index baef49c..0000000 --- a/core/vendor/twig/twig/lib/Twig/Test/Node.php +++ /dev/null @@ -1,40 +0,0 @@ - - * - * @deprecated since 1.12 (to be removed in 2.0) - */ -class Twig_Test_Node extends Twig_Test -{ - protected $class; - - public function __construct($class, array $options = array()) - { - parent::__construct($options); - - $this->class = $class; - } - - public function getClass() - { - return $this->class; - } - - public function compile() - { - } -} diff --git a/core/vendor/twig/twig/lib/Twig/Test/NodeTestCase.php b/core/vendor/twig/twig/lib/Twig/Test/NodeTestCase.php index 908ef61..d75e984 100644 --- a/core/vendor/twig/twig/lib/Twig/Test/NodeTestCase.php +++ b/core/vendor/twig/twig/lib/Twig/Test/NodeTestCase.php @@ -42,11 +42,7 @@ protected function getVariableGetter($name, $line = false) { $line = $line > 0 ? "// line {$line}\n" : ''; - if (PHP_VERSION_ID >= 50400) { - return sprintf('%s(isset($context["%s"]) ? $context["%s"] : null)', $line, $name, $name); - } - - return sprintf('%s$this->getContext($context, "%s")', $line, $name); + return sprintf('%s(isset($context["%s"]) ? $context["%s"] : null)', $line, $name, $name); } protected function getAttributeGetter() diff --git a/core/vendor/twig/twig/lib/Twig/TestCallableInterface.php b/core/vendor/twig/twig/lib/Twig/TestCallableInterface.php deleted file mode 100644 index 98d3457..0000000 --- a/core/vendor/twig/twig/lib/Twig/TestCallableInterface.php +++ /dev/null @@ -1,22 +0,0 @@ - - * - * @deprecated since 1.12 (to be removed in 2.0) - */ -interface Twig_TestCallableInterface -{ - public function getCallable(); -} diff --git a/core/vendor/twig/twig/lib/Twig/TestInterface.php b/core/vendor/twig/twig/lib/Twig/TestInterface.php deleted file mode 100644 index 2fa821c..0000000 --- a/core/vendor/twig/twig/lib/Twig/TestInterface.php +++ /dev/null @@ -1,27 +0,0 @@ - - * - * @deprecated since 1.12 (to be removed in 2.0) - */ -interface Twig_TestInterface -{ - /** - * Compiles a test. - * - * @return string The PHP code for the test - */ - public function compile(); -} diff --git a/core/vendor/twig/twig/lib/Twig/Token.php b/core/vendor/twig/twig/lib/Twig/Token.php index a0a029b..2a2c2f3 100644 --- a/core/vendor/twig/twig/lib/Twig/Token.php +++ b/core/vendor/twig/twig/lib/Twig/Token.php @@ -17,9 +17,9 @@ */ class Twig_Token { - protected $value; - protected $type; - protected $lineno; + private $value; + private $type; + private $lineno; const EOF_TYPE = -1; const TEXT_TYPE = 0; diff --git a/core/vendor/twig/twig/lib/Twig/TokenParser/AutoEscape.php b/core/vendor/twig/twig/lib/Twig/TokenParser/AutoEscape.php index a8a3d7a..e166bcd 100644 --- a/core/vendor/twig/twig/lib/Twig/TokenParser/AutoEscape.php +++ b/core/vendor/twig/twig/lib/Twig/TokenParser/AutoEscape.php @@ -11,21 +11,6 @@ /** * Marks a section of a template to be escaped or not. - * - *
- * {% autoescape true %}
- *   Everything will be automatically escaped in this block
- * {% endautoescape %}
- *
- * {% autoescape false %}
- *   Everything will be outputed as is in this block
- * {% endautoescape %}
- *
- * {% autoescape true js %}
- *   Everything will be automatically escaped in this block
- *   using the js escaping strategy
- * {% endautoescape %}
- * 
*/ class Twig_TokenParser_AutoEscape extends Twig_TokenParser { @@ -34,7 +19,7 @@ class Twig_TokenParser_AutoEscape extends Twig_TokenParser * * @param Twig_Token $token A Twig_Token instance * - * @return Twig_NodeInterface A Twig_NodeInterface instance + * @return Twig_Node A Twig_Node instance */ public function parse(Twig_Token $token) { @@ -46,25 +31,9 @@ public function parse(Twig_Token $token) } else { $expr = $this->parser->getExpressionParser()->parseExpression(); if (!$expr instanceof Twig_Node_Expression_Constant) { - throw new Twig_Error_Syntax('An escaping strategy must be a string or a Boolean.', $stream->getCurrent()->getLine(), $stream->getFilename()); + throw new Twig_Error_Syntax('An escaping strategy must be a string or false.', $stream->getCurrent()->getLine(), $stream->getFilename()); } $value = $expr->getAttribute('value'); - - $compat = true === $value || false === $value; - - if (true === $value) { - $value = 'html'; - } - - if ($compat && $stream->test(Twig_Token::NAME_TYPE)) { - @trigger_error('Using the autoescape tag with "true" or "false" before the strategy name is deprecated.', E_USER_DEPRECATED); - - if (false === $value) { - throw new Twig_Error_Syntax('Unexpected escaping strategy as you set autoescaping to false.', $stream->getCurrent()->getLine(), $stream->getFilename()); - } - - $value = $stream->next()->getValue(); - } } $stream->expect(Twig_Token::BLOCK_END_TYPE); diff --git a/core/vendor/twig/twig/lib/Twig/TokenParser/Block.php b/core/vendor/twig/twig/lib/Twig/TokenParser/Block.php index 0a46200..26e5fdb 100644 --- a/core/vendor/twig/twig/lib/Twig/TokenParser/Block.php +++ b/core/vendor/twig/twig/lib/Twig/TokenParser/Block.php @@ -27,7 +27,7 @@ class Twig_TokenParser_Block extends Twig_TokenParser * * @param Twig_Token $token A Twig_Token instance * - * @return Twig_NodeInterface A Twig_NodeInterface instance + * @return Twig_Node A Twig_Node instance */ public function parse(Twig_Token $token) { diff --git a/core/vendor/twig/twig/lib/Twig/TokenParser/Do.php b/core/vendor/twig/twig/lib/Twig/TokenParser/Do.php index f50939d..ae20dc9 100644 --- a/core/vendor/twig/twig/lib/Twig/TokenParser/Do.php +++ b/core/vendor/twig/twig/lib/Twig/TokenParser/Do.php @@ -19,7 +19,7 @@ class Twig_TokenParser_Do extends Twig_TokenParser * * @param Twig_Token $token A Twig_Token instance * - * @return Twig_NodeInterface A Twig_NodeInterface instance + * @return Twig_Node A Twig_Node instance */ public function parse(Twig_Token $token) { diff --git a/core/vendor/twig/twig/lib/Twig/TokenParser/Embed.php b/core/vendor/twig/twig/lib/Twig/TokenParser/Embed.php index 69cb5f3..18348eb 100644 --- a/core/vendor/twig/twig/lib/Twig/TokenParser/Embed.php +++ b/core/vendor/twig/twig/lib/Twig/TokenParser/Embed.php @@ -19,7 +19,7 @@ class Twig_TokenParser_Embed extends Twig_TokenParser_Include * * @param Twig_Token $token A Twig_Token instance * - * @return Twig_NodeInterface A Twig_NodeInterface instance + * @return Twig_Node A Twig_Node instance */ public function parse(Twig_Token $token) { diff --git a/core/vendor/twig/twig/lib/Twig/TokenParser/Extends.php b/core/vendor/twig/twig/lib/Twig/TokenParser/Extends.php index f5ecee2..c044bba 100644 --- a/core/vendor/twig/twig/lib/Twig/TokenParser/Extends.php +++ b/core/vendor/twig/twig/lib/Twig/TokenParser/Extends.php @@ -24,7 +24,7 @@ class Twig_TokenParser_Extends extends Twig_TokenParser * * @param Twig_Token $token A Twig_Token instance * - * @return Twig_NodeInterface A Twig_NodeInterface instance + * @return Twig_Node A Twig_Node instance */ public function parse(Twig_Token $token) { diff --git a/core/vendor/twig/twig/lib/Twig/TokenParser/Filter.php b/core/vendor/twig/twig/lib/Twig/TokenParser/Filter.php index 2b97475..61000b7 100644 --- a/core/vendor/twig/twig/lib/Twig/TokenParser/Filter.php +++ b/core/vendor/twig/twig/lib/Twig/TokenParser/Filter.php @@ -25,7 +25,7 @@ class Twig_TokenParser_Filter extends Twig_TokenParser * * @param Twig_Token $token A Twig_Token instance * - * @return Twig_NodeInterface A Twig_NodeInterface instance + * @return Twig_Node A Twig_Node instance */ public function parse(Twig_Token $token) { diff --git a/core/vendor/twig/twig/lib/Twig/TokenParser/Flush.php b/core/vendor/twig/twig/lib/Twig/TokenParser/Flush.php index 4e15e78..bd0ef77 100644 --- a/core/vendor/twig/twig/lib/Twig/TokenParser/Flush.php +++ b/core/vendor/twig/twig/lib/Twig/TokenParser/Flush.php @@ -21,7 +21,7 @@ class Twig_TokenParser_Flush extends Twig_TokenParser * * @param Twig_Token $token A Twig_Token instance * - * @return Twig_NodeInterface A Twig_NodeInterface instance + * @return Twig_Node A Twig_Node instance */ public function parse(Twig_Token $token) { diff --git a/core/vendor/twig/twig/lib/Twig/TokenParser/For.php b/core/vendor/twig/twig/lib/Twig/TokenParser/For.php index 5c07d63..2c65d83 100644 --- a/core/vendor/twig/twig/lib/Twig/TokenParser/For.php +++ b/core/vendor/twig/twig/lib/Twig/TokenParser/For.php @@ -28,7 +28,7 @@ class Twig_TokenParser_For extends Twig_TokenParser * * @param Twig_Token $token A Twig_Token instance * - * @return Twig_NodeInterface A Twig_NodeInterface instance + * @return Twig_Node A Twig_Node instance */ public function parse(Twig_Token $token) { @@ -83,7 +83,7 @@ public function decideForEnd(Twig_Token $token) } // the loop variable cannot be used in the condition - protected function checkLoopUsageCondition(Twig_TokenStream $stream, Twig_NodeInterface $node) + private function checkLoopUsageCondition(Twig_TokenStream $stream, Twig_Node $node) { if ($node instanceof Twig_Node_Expression_GetAttr && $node->getNode('node') instanceof Twig_Node_Expression_Name && 'loop' == $node->getNode('node')->getAttribute('name')) { throw new Twig_Error_Syntax('The "loop" variable cannot be used in a looping condition', $node->getLine(), $stream->getFilename()); @@ -100,7 +100,7 @@ protected function checkLoopUsageCondition(Twig_TokenStream $stream, Twig_NodeIn // check usage of non-defined loop-items // it does not catch all problems (for instance when a for is included into another or when the variable is used in an include) - protected function checkLoopUsageBody(Twig_TokenStream $stream, Twig_NodeInterface $node) + private function checkLoopUsageBody(Twig_TokenStream $stream, Twig_Node $node) { if ($node instanceof Twig_Node_Expression_GetAttr && $node->getNode('node') instanceof Twig_Node_Expression_Name && 'loop' == $node->getNode('node')->getAttribute('name')) { $attribute = $node->getNode('attribute'); diff --git a/core/vendor/twig/twig/lib/Twig/TokenParser/From.php b/core/vendor/twig/twig/lib/Twig/TokenParser/From.php index 5540efa..21d1fef 100644 --- a/core/vendor/twig/twig/lib/Twig/TokenParser/From.php +++ b/core/vendor/twig/twig/lib/Twig/TokenParser/From.php @@ -23,7 +23,7 @@ class Twig_TokenParser_From extends Twig_TokenParser * * @param Twig_Token $token A Twig_Token instance * - * @return Twig_NodeInterface A Twig_NodeInterface instance + * @return Twig_Node A Twig_Node instance */ public function parse(Twig_Token $token) { @@ -52,11 +52,7 @@ public function parse(Twig_Token $token) $node = new Twig_Node_Import($macro, new Twig_Node_Expression_AssignName($this->parser->getVarName(), $token->getLine()), $token->getLine(), $this->getTag()); foreach ($targets as $name => $alias) { - if ($this->parser->isReservedMacroName($name)) { - throw new Twig_Error_Syntax(sprintf('"%s" cannot be an imported macro as it is a reserved keyword', $name), $token->getLine(), $stream->getFilename()); - } - - $this->parser->addImportedSymbol('function', $alias, 'get'.$name, $node->getNode('var')); + $this->parser->addImportedSymbol('function', $alias, 'macro_'.$name, $node->getNode('var')); } return $node; diff --git a/core/vendor/twig/twig/lib/Twig/TokenParser/If.php b/core/vendor/twig/twig/lib/Twig/TokenParser/If.php index 3d7d1f5..eb4332d 100644 --- a/core/vendor/twig/twig/lib/Twig/TokenParser/If.php +++ b/core/vendor/twig/twig/lib/Twig/TokenParser/If.php @@ -30,7 +30,7 @@ class Twig_TokenParser_If extends Twig_TokenParser * * @param Twig_Token $token A Twig_Token instance * - * @return Twig_NodeInterface A Twig_NodeInterface instance + * @return Twig_Node A Twig_Node instance */ public function parse(Twig_Token $token) { diff --git a/core/vendor/twig/twig/lib/Twig/TokenParser/Import.php b/core/vendor/twig/twig/lib/Twig/TokenParser/Import.php index e7050c7..6a9de61 100644 --- a/core/vendor/twig/twig/lib/Twig/TokenParser/Import.php +++ b/core/vendor/twig/twig/lib/Twig/TokenParser/Import.php @@ -23,7 +23,7 @@ class Twig_TokenParser_Import extends Twig_TokenParser * * @param Twig_Token $token A Twig_Token instance * - * @return Twig_NodeInterface A Twig_NodeInterface instance + * @return Twig_Node A Twig_Node instance */ public function parse(Twig_Token $token) { diff --git a/core/vendor/twig/twig/lib/Twig/TokenParser/Include.php b/core/vendor/twig/twig/lib/Twig/TokenParser/Include.php index 9c3099a..8736fd6 100644 --- a/core/vendor/twig/twig/lib/Twig/TokenParser/Include.php +++ b/core/vendor/twig/twig/lib/Twig/TokenParser/Include.php @@ -26,7 +26,7 @@ class Twig_TokenParser_Include extends Twig_TokenParser * * @param Twig_Token $token A Twig_Token instance * - * @return Twig_NodeInterface A Twig_NodeInterface instance + * @return Twig_Node A Twig_Node instance */ public function parse(Twig_Token $token) { diff --git a/core/vendor/twig/twig/lib/Twig/TokenParser/Macro.php b/core/vendor/twig/twig/lib/Twig/TokenParser/Macro.php index ad910b5..7e9f82e 100644 --- a/core/vendor/twig/twig/lib/Twig/TokenParser/Macro.php +++ b/core/vendor/twig/twig/lib/Twig/TokenParser/Macro.php @@ -25,7 +25,7 @@ class Twig_TokenParser_Macro extends Twig_TokenParser * * @param Twig_Token $token A Twig_Token instance * - * @return Twig_NodeInterface A Twig_NodeInterface instance + * @return Twig_Node A Twig_Node instance */ public function parse(Twig_Token $token) { diff --git a/core/vendor/twig/twig/lib/Twig/TokenParser/Sandbox.php b/core/vendor/twig/twig/lib/Twig/TokenParser/Sandbox.php index 9457325..9ce518e 100644 --- a/core/vendor/twig/twig/lib/Twig/TokenParser/Sandbox.php +++ b/core/vendor/twig/twig/lib/Twig/TokenParser/Sandbox.php @@ -27,7 +27,7 @@ class Twig_TokenParser_Sandbox extends Twig_TokenParser * * @param Twig_Token $token A Twig_Token instance * - * @return Twig_NodeInterface A Twig_NodeInterface instance + * @return Twig_Node A Twig_Node instance */ public function parse(Twig_Token $token) { diff --git a/core/vendor/twig/twig/lib/Twig/TokenParser/Set.php b/core/vendor/twig/twig/lib/Twig/TokenParser/Set.php index 0b41909..8c2d66b 100644 --- a/core/vendor/twig/twig/lib/Twig/TokenParser/Set.php +++ b/core/vendor/twig/twig/lib/Twig/TokenParser/Set.php @@ -33,7 +33,7 @@ class Twig_TokenParser_Set extends Twig_TokenParser * * @param Twig_Token $token A Twig_Token instance * - * @return Twig_NodeInterface A Twig_NodeInterface instance + * @return Twig_Node A Twig_Node instance */ public function parse(Twig_Token $token) { diff --git a/core/vendor/twig/twig/lib/Twig/TokenParser/Spaceless.php b/core/vendor/twig/twig/lib/Twig/TokenParser/Spaceless.php index 1e3fa8f..b5aaac6 100644 --- a/core/vendor/twig/twig/lib/Twig/TokenParser/Spaceless.php +++ b/core/vendor/twig/twig/lib/Twig/TokenParser/Spaceless.php @@ -29,7 +29,7 @@ class Twig_TokenParser_Spaceless extends Twig_TokenParser * * @param Twig_Token $token A Twig_Token instance * - * @return Twig_NodeInterface A Twig_NodeInterface instance + * @return Twig_Node A Twig_Node instance */ public function parse(Twig_Token $token) { diff --git a/core/vendor/twig/twig/lib/Twig/TokenParser/Use.php b/core/vendor/twig/twig/lib/Twig/TokenParser/Use.php index 3ea68b1..5092e31 100644 --- a/core/vendor/twig/twig/lib/Twig/TokenParser/Use.php +++ b/core/vendor/twig/twig/lib/Twig/TokenParser/Use.php @@ -30,7 +30,7 @@ class Twig_TokenParser_Use extends Twig_TokenParser * * @param Twig_Token $token A Twig_Token instance * - * @return Twig_NodeInterface A Twig_NodeInterface instance + * @return Twig_Node A Twig_Node instance */ public function parse(Twig_Token $token) { diff --git a/core/vendor/twig/twig/lib/Twig/TokenParserBroker.php b/core/vendor/twig/twig/lib/Twig/TokenParserBroker.php deleted file mode 100644 index 6ca73fb..0000000 --- a/core/vendor/twig/twig/lib/Twig/TokenParserBroker.php +++ /dev/null @@ -1,141 +0,0 @@ - - * - * @deprecated since 1.12 (to be removed in 2.0) - */ -class Twig_TokenParserBroker implements Twig_TokenParserBrokerInterface -{ - protected $parser; - protected $parsers = array(); - protected $brokers = array(); - - /** - * Constructor. - * - * @param array|Traversable $parsers A Traversable of Twig_TokenParserInterface instances - * @param array|Traversable $brokers A Traversable of Twig_TokenParserBrokerInterface instances - */ - public function __construct($parsers = array(), $brokers = array(), $triggerDeprecationError = true) - { - if ($triggerDeprecationError) { - @trigger_error('The '.__CLASS__.' class is deprecated since version 1.12 and will be removed in 2.0.', E_USER_DEPRECATED); - } - - foreach ($parsers as $parser) { - if (!$parser instanceof Twig_TokenParserInterface) { - throw new LogicException('$parsers must a an array of Twig_TokenParserInterface'); - } - $this->parsers[$parser->getTag()] = $parser; - } - foreach ($brokers as $broker) { - if (!$broker instanceof Twig_TokenParserBrokerInterface) { - throw new LogicException('$brokers must a an array of Twig_TokenParserBrokerInterface'); - } - $this->brokers[] = $broker; - } - } - - /** - * Adds a TokenParser. - * - * @param Twig_TokenParserInterface $parser A Twig_TokenParserInterface instance - */ - public function addTokenParser(Twig_TokenParserInterface $parser) - { - $this->parsers[$parser->getTag()] = $parser; - } - - /** - * Removes a TokenParser. - * - * @param Twig_TokenParserInterface $parser A Twig_TokenParserInterface instance - */ - public function removeTokenParser(Twig_TokenParserInterface $parser) - { - $name = $parser->getTag(); - if (isset($this->parsers[$name]) && $parser === $this->parsers[$name]) { - unset($this->parsers[$name]); - } - } - - /** - * Adds a TokenParserBroker. - * - * @param Twig_TokenParserBroker $broker A Twig_TokenParserBroker instance - */ - public function addTokenParserBroker(Twig_TokenParserBroker $broker) - { - $this->brokers[] = $broker; - } - - /** - * Removes a TokenParserBroker. - * - * @param Twig_TokenParserBroker $broker A Twig_TokenParserBroker instance - */ - public function removeTokenParserBroker(Twig_TokenParserBroker $broker) - { - if (false !== $pos = array_search($broker, $this->brokers)) { - unset($this->brokers[$pos]); - } - } - - /** - * Gets a suitable TokenParser for a tag. - * - * First looks in parsers, then in brokers. - * - * @param string $tag A tag name - * - * @return null|Twig_TokenParserInterface A Twig_TokenParserInterface or null if no suitable TokenParser was found - */ - public function getTokenParser($tag) - { - if (isset($this->parsers[$tag])) { - return $this->parsers[$tag]; - } - $broker = end($this->brokers); - while (false !== $broker) { - $parser = $broker->getTokenParser($tag); - if (null !== $parser) { - return $parser; - } - $broker = prev($this->brokers); - } - } - - public function getParsers() - { - return $this->parsers; - } - - public function getParser() - { - return $this->parser; - } - - public function setParser(Twig_ParserInterface $parser) - { - $this->parser = $parser; - foreach ($this->parsers as $tokenParser) { - $tokenParser->setParser($parser); - } - foreach ($this->brokers as $broker) { - $broker->setParser($parser); - } - } -} diff --git a/core/vendor/twig/twig/lib/Twig/TokenParserBrokerInterface.php b/core/vendor/twig/twig/lib/Twig/TokenParserBrokerInterface.php deleted file mode 100644 index 3ec2a88..0000000 --- a/core/vendor/twig/twig/lib/Twig/TokenParserBrokerInterface.php +++ /dev/null @@ -1,46 +0,0 @@ - - * - * @deprecated since 1.12 (to be removed in 2.0) - */ -interface Twig_TokenParserBrokerInterface -{ - /** - * Gets a TokenParser suitable for a tag. - * - * @param string $tag A tag name - * - * @return null|Twig_TokenParserInterface A Twig_TokenParserInterface or null if no suitable TokenParser was found - */ - public function getTokenParser($tag); - - /** - * Calls Twig_TokenParserInterface::setParser on all parsers the implementation knows of. - * - * @param Twig_ParserInterface $parser A Twig_ParserInterface interface - */ - public function setParser(Twig_ParserInterface $parser); - - /** - * Gets the Twig_ParserInterface. - * - * @return null|Twig_ParserInterface A Twig_ParserInterface instance or null - */ - public function getParser(); -} diff --git a/core/vendor/twig/twig/lib/Twig/TokenParserInterface.php b/core/vendor/twig/twig/lib/Twig/TokenParserInterface.php index 12ec396..2a47e4a 100644 --- a/core/vendor/twig/twig/lib/Twig/TokenParserInterface.php +++ b/core/vendor/twig/twig/lib/Twig/TokenParserInterface.php @@ -28,7 +28,7 @@ public function setParser(Twig_Parser $parser); * * @param Twig_Token $token A Twig_Token instance * - * @return Twig_NodeInterface A Twig_NodeInterface instance + * @return Twig_Node A Twig_Node instance * * @throws Twig_Error_Syntax */ diff --git a/core/vendor/twig/twig/lib/Twig/TokenStream.php b/core/vendor/twig/twig/lib/Twig/TokenStream.php index 8d2e220..249d109 100644 --- a/core/vendor/twig/twig/lib/Twig/TokenStream.php +++ b/core/vendor/twig/twig/lib/Twig/TokenStream.php @@ -17,9 +17,9 @@ */ class Twig_TokenStream { - protected $tokens; - protected $current = 0; - protected $filename; + private $tokens; + private $current = 0; + private $filename; /** * Constructor. diff --git a/core/vendor/twig/twig/lib/Twig/Util/DeprecationCollector.php b/core/vendor/twig/twig/lib/Twig/Util/DeprecationCollector.php index e406f0a..d21c2d2 100644 --- a/core/vendor/twig/twig/lib/Twig/Util/DeprecationCollector.php +++ b/core/vendor/twig/twig/lib/Twig/Util/DeprecationCollector.php @@ -15,7 +15,6 @@ class Twig_Util_DeprecationCollector { private $twig; - private $deprecations; public function __construct(Twig_Environment $twig) { @@ -50,9 +49,12 @@ public function collectDir($dir, $ext = '.twig') */ public function collect(Iterator $iterator) { - $this->deprecations = array(); - - set_error_handler(array($this, 'errorHandler')); + $deprecations = array(); + set_error_handler(function($type, $msg) use (&$deprecations) { + if (E_USER_DEPRECATED === $type) { + $deprecations[] = $msg; + } + }); foreach ($iterator as $name => $contents) { try { @@ -64,19 +66,6 @@ public function collect(Iterator $iterator) restore_error_handler(); - $deprecations = $this->deprecations; - $this->deprecations = array(); - return $deprecations; } - - /** - * @internal - */ - public function errorHandler($type, $msg) - { - if (E_USER_DEPRECATED === $type) { - $this->deprecations[] = $msg; - } - } } diff --git a/core/vendor/twig/twig/test/Twig/Tests/AutoloaderTest.php b/core/vendor/twig/twig/test/Twig/Tests/AutoloaderTest.php deleted file mode 100644 index 52107c0..0000000 --- a/core/vendor/twig/twig/test/Twig/Tests/AutoloaderTest.php +++ /dev/null @@ -1,24 +0,0 @@ -assertFalse(class_exists('FooBarFoo'), '->autoload() does not try to load classes that does not begin with Twig'); - - $autoloader = new Twig_Autoloader(); - $this->assertNull($autoloader->autoload('Foo'), '->autoload() returns false if it is not able to load a class'); - } -} diff --git a/core/vendor/twig/twig/test/Twig/Tests/EnvironmentTest.php b/core/vendor/twig/twig/test/Twig/Tests/EnvironmentTest.php index e4bef74..df7426c 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/EnvironmentTest.php +++ b/core/vendor/twig/twig/test/Twig/Tests/EnvironmentTest.php @@ -11,17 +11,6 @@ class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase { - /** - * @expectedException LogicException - * @expectedExceptionMessage You must set a loader first. - * @group legacy - */ - public function testRenderNoLoader() - { - $env = new Twig_Environment(); - $env->render('test'); - } - public function testAutoescapeOption() { $loader = new Twig_Loader_Array(array( @@ -88,7 +77,6 @@ public function testGlobals() $template = $twig->loadTemplate('index'); $this->assertEquals('bar', $template->render(array())); - /* to be uncomment in Twig 2.0 // globals cannot be added after runtime init $twig = new Twig_Environment($this->getMock('Twig_LoaderInterface')); $twig->addGlobal('foo', 'foo'); @@ -135,7 +123,6 @@ public function testGlobals() } catch (LogicException $e) { $this->assertFalse(array_key_exists('bar', $twig->getGlobals())); } - */ } public function testExtensionsAreNotInitializedWhenRenderingACompiledTemplate() @@ -182,25 +169,6 @@ public function testAddExtension() $visitors = $twig->getNodeVisitors(); $this->assertEquals('Twig_Tests_EnvironmentTest_NodeVisitor', get_class($visitors[2])); } - - /** - * @group legacy - */ - public function testRemoveExtension() - { - $twig = new Twig_Environment($this->getMock('Twig_LoaderInterface')); - $twig->addExtension(new Twig_Tests_EnvironmentTest_Extension()); - $twig->removeExtension('environment_test'); - - $this->assertFalse(array_key_exists('test', $twig->getTags())); - $this->assertFalse(array_key_exists('foo_filter', $twig->getFilters())); - $this->assertFalse(array_key_exists('foo_function', $twig->getFunctions())); - $this->assertFalse(array_key_exists('foo_test', $twig->getTests())); - $this->assertFalse(array_key_exists('foo_unary', $twig->getUnaryOperators())); - $this->assertFalse(array_key_exists('foo_binary', $twig->getBinaryOperators())); - $this->assertFalse(array_key_exists('foo_global', $twig->getGlobals())); - $this->assertCount(2, $twig->getNodeVisitors()); - } } class Twig_Tests_EnvironmentTest_Extension extends Twig_Extension @@ -222,21 +190,21 @@ public function getNodeVisitors() public function getFilters() { return array( - new Twig_SimpleFilter('foo_filter', 'foo_filter'), + new Twig_Filter('foo_filter'), ); } public function getTests() { return array( - new Twig_SimpleTest('foo_test', 'foo_test'), + new Twig_Test('foo_test'), ); } public function getFunctions() { return array( - new Twig_SimpleFunction('foo_function', 'foo_function'), + new Twig_Function('foo_function'), ); } @@ -275,12 +243,12 @@ public function getTag() class Twig_Tests_EnvironmentTest_NodeVisitor implements Twig_NodeVisitorInterface { - public function enterNode(Twig_NodeInterface $node, Twig_Environment $env) + public function enterNode(Twig_Node $node, Twig_Environment $env) { return $node; } - public function leaveNode(Twig_NodeInterface $node, Twig_Environment $env) + public function leaveNode(Twig_Node $node, Twig_Environment $env) { return $node; } diff --git a/core/vendor/twig/twig/test/Twig/Tests/ErrorTest.php b/core/vendor/twig/twig/test/Twig/Tests/ErrorTest.php index d58c40b..d8527a5 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/ErrorTest.php +++ b/core/vendor/twig/twig/test/Twig/Tests/ErrorTest.php @@ -29,7 +29,7 @@ public function testErrorWithArrayFilename() public function testTwigExceptionAddsFileAndLineWhenMissingWithInheritanceOnDisk() { - $loader = new Twig_Loader_Filesystem(dirname(__FILE__).'/Fixtures/errors'); + $loader = new Twig_Loader_Filesystem(__DIR__.'/Fixtures/errors'); $twig = new Twig_Environment($loader, array('strict_variables' => true, 'debug' => true, 'cache' => false)); $template = $twig->loadTemplate('index.html'); diff --git a/core/vendor/twig/twig/test/Twig/Tests/FileExtensionEscapingStrategyTest.php b/core/vendor/twig/twig/test/Twig/Tests/FileExtensionEscapingStrategyTest.php index d2f55eb..b310a5b 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/FileExtensionEscapingStrategyTest.php +++ b/core/vendor/twig/twig/test/Twig/Tests/FileExtensionEscapingStrategyTest.php @@ -16,7 +16,7 @@ class Twig_Tests_FileExtensionEscapingStrategyTest extends PHPUnit_Framework_Tes */ public function testGuess($strategy, $filename) { - $this->assertEquals($strategy, Twig_FileExtensionEscapingStrategy::guess($filename)); + $this->assertSame($strategy, Twig_FileExtensionEscapingStrategy::guess($filename)); } public function getGuessData() @@ -34,6 +34,8 @@ public function getGuessData() array('css', 'foo.css'), array('css', 'foo.css.twig'), array('css', 'foo.twig.css'), + array('css', 'foo.js.css'), + array('css', 'foo.js.css.twig'), // js array('js', 'foo.js'), diff --git a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/extensions/anonymous_functions.test b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/extensions/anonymous_functions.test new file mode 100644 index 0000000..842ecf7 --- /dev/null +++ b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/extensions/anonymous_functions.test @@ -0,0 +1,10 @@ +--TEST-- +use an anonymous function as a function +--TEMPLATE-- +{{ anon_foo('bar') }} +{{ 'bar'|anon_foo }} +--DATA-- +return array() +--EXPECT-- +*bar* +*bar* diff --git a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/date_default_format_interval.test b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/date_default_format_interval.test index e6d3707..41a8115 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/date_default_format_interval.test +++ b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/date_default_format_interval.test @@ -1,7 +1,5 @@ --TEST-- -"date" filter (interval support as of PHP 5.3) ---CONDITION-- -version_compare(phpversion(), '5.3.0', '>=') +"date" filter (interval support) --TEMPLATE-- {{ date2|date }} {{ date2|date('%d days') }} diff --git a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/date_interval.test b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/date_interval.test index 0c8c6f1..a5a89f4 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/date_interval.test +++ b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/date_interval.test @@ -1,7 +1,5 @@ --TEST-- -"date" filter (interval support as of PHP 5.3) ---CONDITION-- -version_compare(phpversion(), '5.3.0', '>=') +"date" filter (interval support) --TEMPLATE-- {{ date1|date }} {{ date1|date('%d days %h hours') }} diff --git a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/merge.test b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/merge.test index 2bd3d4c..81371a4 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/merge.test +++ b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/merge.test @@ -6,11 +6,13 @@ {{ {'bar': 'foo'}|merge(items)|join }} {{ {'bar': 'foo'}|merge(items)|keys|join }} {{ numerics|merge([4, 5, 6])|join }} +{{ traversable.a|merge(traversable.b)|join }} --DATA-- -return array('items' => array('foo' => 'bar'), 'numerics' => array(1, 2, 3)) +return array('items' => array('foo' => 'bar'), 'numerics' => array(1, 2, 3), 'traversable' => array('a' => new ArrayObject(array(0 => 1, 1 => 2, 2 => 3)), 'b' => new ArrayObject(array('a' => 'b')))) --EXPECT-- barfoo foobar foobar barfoo 123456 +123b diff --git a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/replace.test b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/replace.test index 4021660..06be7e2 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/replace.test +++ b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/replace.test @@ -1,8 +1,12 @@ --TEST-- "replace" filter --TEMPLATE-- -{{ "I like %this% and %that%."|replace({'%this%': "foo", '%that%': "bar"}) }} +{{ "I liké %this% and %that%."|replace({'%this%': "foo", '%that%': "bar"}) }} +{{ 'I like single replace operation only %that%'|replace({'%that%' : '%that%1'}) }} +{{ 'I like %this% and %that%.'|replace(traversable) }} --DATA-- -return array() +return array('traversable' => new ArrayObject(array('%this%' => 'foo', '%that%' => 'bar'))) --EXPECT-- +I liké foo and bar. +I like single replace operation only %that%1 I like foo and bar. diff --git a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/replace_invalid_arg.test b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/replace_invalid_arg.test new file mode 100644 index 0000000..08ecfd4 --- /dev/null +++ b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/replace_invalid_arg.test @@ -0,0 +1,8 @@ +--TEST-- +Exception for invalid argument type in replace call +--TEMPLATE-- +{{ 'test %foo%'|replace(stdClass) }} +--DATA-- +return array('stdClass' => new \stdClass()) +--EXCEPTION-- +Twig_Error_Runtime: The "replace" filter expects an array or "Traversable" as replace values, got "stdClass" in "index.twig" at line 2. diff --git a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/sort.test b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/sort.test index 21d575f..c67c18e 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/sort.test +++ b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/sort.test @@ -3,8 +3,10 @@ --TEMPLATE-- {{ array1|sort|join }} {{ array2|sort|join }} +{{ traversable|sort|join }} --DATA-- -return array('array1' => array(4, 1), 'array2' => array('foo', 'bar')) +return array('array1' => array(4, 1), 'array2' => array('foo', 'bar'), 'traversable' => new ArrayObject(array(0 => 3, 1 => 2, 2 => 1))) --EXPECT-- 14 barfoo +123 diff --git a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/regression/simple_xml_element.test b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/regression/simple_xml_element.test index 60c3c51..2a80c1e 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/regression/simple_xml_element.test +++ b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/regression/simple_xml_element.test @@ -1,7 +1,5 @@ --TEST-- Twig is able to deal with SimpleXMLElement instances as variables ---CONDITION-- -version_compare(phpversion(), '5.3.0', '>=') --TEMPLATE-- Hello '{{ images.image.0.group }}'! {{ images.image.0.group.attributes.myattr }} diff --git a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/basic.test b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/basic.test index 2f6a3e1..703d935 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/basic.test +++ b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/basic.test @@ -10,9 +10,6 @@ {% autoescape false %} {{ var }}
{% endautoescape %} -{% autoescape true %} -{{ var }}
-{% endautoescape %} {% autoescape false %} {{ var }}
{% endautoescape %} @@ -22,5 +19,4 @@ <br />
<br />


-<br />


diff --git a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/strategy.legacy.test b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/strategy.legacy.test deleted file mode 100644 index bbf1356..0000000 --- a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/strategy.legacy.test +++ /dev/null @@ -1,11 +0,0 @@ ---TEST-- -"autoescape" tag accepts an escaping strategy ---TEMPLATE-- -{% autoescape true js %}{{ var }}{% endautoescape %} - -{% autoescape true html %}{{ var }}{% endautoescape %} ---DATA-- -return array('var' => '
"') ---EXPECT-- -\x3Cbr\x20\x2F\x3E\x22 -<br />" diff --git a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/from_with_reserved_name.test b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/from_with_reserved_name.test deleted file mode 100644 index 6df4f5d..0000000 --- a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/from_with_reserved_name.test +++ /dev/null @@ -1,9 +0,0 @@ ---TEST-- -"from" tag with reserved name ---TEMPLATE-- -{% from 'forms.twig' import templateName %} ---TEMPLATE(forms.twig)-- ---DATA-- -return array() ---EXCEPTION-- -Twig_Error_Syntax: "templateName" cannot be an imported macro as it is a reserved keyword in "index.twig" at line 2 diff --git a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/import_with_reserved_nam.test b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/import_with_reserved_nam.test deleted file mode 100644 index e5aa749..0000000 --- a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/import_with_reserved_nam.test +++ /dev/null @@ -1,11 +0,0 @@ ---TEST-- -"from" tag with reserved name ---TEMPLATE-- -{% import 'forms.twig' as macros %} - -{{ macros.parent() }} ---TEMPLATE(forms.twig)-- ---DATA-- -return array() ---EXCEPTION-- -Twig_Error_Syntax: "parent" cannot be called as macro as it is a reserved keyword in "index.twig" at line 4 diff --git a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/reserved_name.test b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/reserved_name.test deleted file mode 100644 index a2dde5a..0000000 --- a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/reserved_name.test +++ /dev/null @@ -1,10 +0,0 @@ ---TEST-- -"macro" tag with reserved name ---TEMPLATE-- -{% macro parent(arg1, arg2) %} - parent -{% endmacro %} ---DATA-- -return array() ---EXCEPTION-- -Twig_Error_Syntax: "parent" cannot be used as a macro name as it is a reserved keyword in "index.twig" at line 2 diff --git a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/raw/basic.legacy.test b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/raw/basic.legacy.test deleted file mode 100644 index 0445e85..0000000 --- a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/raw/basic.legacy.test +++ /dev/null @@ -1,10 +0,0 @@ ---TEST-- -"raw" tag ---TEMPLATE-- -{% raw %} -{{ foo }} -{% endraw %} ---DATA-- -return array() ---EXPECT-- -{{ foo }} diff --git a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/raw/mixed_usage_with_raw.legacy.test b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/raw/mixed_usage_with_raw.legacy.test deleted file mode 100644 index 2fd9fb2..0000000 --- a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/raw/mixed_usage_with_raw.legacy.test +++ /dev/null @@ -1,10 +0,0 @@ ---TEST-- -"raw" tag ---TEMPLATE-- -{% raw %} -{{ foo }} -{% endverbatim %} ---DATA-- -return array() ---EXCEPTION-- -Twig_Error_Syntax: Unexpected end of file: Unclosed "raw" block in "index.twig" at line 2 diff --git a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/raw/whitespace_control.legacy.test b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/raw/whitespace_control.legacy.test deleted file mode 100644 index 352bb18..0000000 --- a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/raw/whitespace_control.legacy.test +++ /dev/null @@ -1,56 +0,0 @@ ---TEST-- -"raw" tag ---TEMPLATE-- -1*** - -{%- raw %} - {{ 'bla' }} -{% endraw %} - -1*** -2*** - -{%- raw -%} - {{ 'bla' }} -{% endraw %} - -2*** -3*** - -{%- raw -%} - {{ 'bla' }} -{% endraw -%} - -3*** -4*** - -{%- raw -%} - {{ 'bla' }} -{%- endraw %} - -4*** -5*** - -{%- raw -%} - {{ 'bla' }} -{%- endraw -%} - -5*** ---DATA-- -return array() ---EXPECT-- -1*** - {{ 'bla' }} - - -1*** -2***{{ 'bla' }} - - -2*** -3***{{ 'bla' }} -3*** -4***{{ 'bla' }} - -4*** -5***{{ 'bla' }}5*** diff --git a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/verbatim/mixed_usage_with_raw.test b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/verbatim/mixed_usage_with_raw.test deleted file mode 100644 index 941dddc..0000000 --- a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/verbatim/mixed_usage_with_raw.test +++ /dev/null @@ -1,10 +0,0 @@ ---TEST-- -"verbatim" tag ---TEMPLATE-- -{% verbatim %} -{{ foo }} -{% endraw %} ---DATA-- -return array() ---EXCEPTION-- -Twig_Error_Syntax: Unexpected end of file: Unclosed "verbatim" block in "index.twig" at line 2 diff --git a/core/vendor/twig/twig/test/Twig/Tests/IntegrationTest.php b/core/vendor/twig/twig/test/Twig/Tests/IntegrationTest.php index 1908bcd..3085a75 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/IntegrationTest.php +++ b/core/vendor/twig/twig/test/Twig/Tests/IntegrationTest.php @@ -32,7 +32,7 @@ public function getExtensions() public function getFixturesDir() { - return dirname(__FILE__).'/Fixtures/'; + return __DIR__.'/Fixtures/'; } } @@ -136,31 +136,33 @@ public function getTokenParsers() public function getFilters() { return array( - new Twig_SimpleFilter('§', array($this, '§Filter')), - new Twig_SimpleFilter('escape_and_nl2br', array($this, 'escape_and_nl2br'), array('needs_environment' => true, 'is_safe' => array('html'))), - new Twig_SimpleFilter('nl2br', array($this, 'nl2br'), array('pre_escape' => 'html', 'is_safe' => array('html'))), - new Twig_SimpleFilter('escape_something', array($this, 'escape_something'), array('is_safe' => array('something'))), - new Twig_SimpleFilter('preserves_safety', array($this, 'preserves_safety'), array('preserves_safety' => array('html'))), - new Twig_SimpleFilter('*_path', array($this, 'dynamic_path')), - new Twig_SimpleFilter('*_foo_*_bar', array($this, 'dynamic_foo')), + new Twig_Filter('§', array($this, '§Filter')), + new Twig_Filter('escape_and_nl2br', array($this, 'escape_and_nl2br'), array('needs_environment' => true, 'is_safe' => array('html'))), + new Twig_Filter('nl2br', array($this, 'nl2br'), array('pre_escape' => 'html', 'is_safe' => array('html'))), + new Twig_Filter('escape_something', array($this, 'escape_something'), array('is_safe' => array('something'))), + new Twig_Filter('preserves_safety', array($this, 'preserves_safety'), array('preserves_safety' => array('html'))), + new Twig_Filter('*_path', array($this, 'dynamic_path')), + new Twig_Filter('*_foo_*_bar', array($this, 'dynamic_foo')), + new Twig_Filter('anon_foo', function ($name) { return '*'.$name.'*'; }), ); } public function getFunctions() { return array( - new Twig_SimpleFunction('§', array($this, '§Function')), - new Twig_SimpleFunction('safe_br', array($this, 'br'), array('is_safe' => array('html'))), - new Twig_SimpleFunction('unsafe_br', array($this, 'br')), - new Twig_SimpleFunction('*_path', array($this, 'dynamic_path')), - new Twig_SimpleFunction('*_foo_*_bar', array($this, 'dynamic_foo')), + new Twig_Function('§', array($this, '§Function')), + new Twig_Function('safe_br', array($this, 'br'), array('is_safe' => array('html'))), + new Twig_Function('unsafe_br', array($this, 'br')), + new Twig_Function('*_path', array($this, 'dynamic_path')), + new Twig_Function('*_foo_*_bar', array($this, 'dynamic_foo')), + new Twig_Function('anon_foo', function ($name) { return '*'.$name.'*'; }), ); } public function getTests() { return array( - new Twig_SimpleTest('multi word', array($this, 'is_multi_word')), + new Twig_Test('multi word', array($this, 'is_multi_word')), ); } diff --git a/core/vendor/twig/twig/test/Twig/Tests/LegacyFixtures/test.legacy.test b/core/vendor/twig/twig/test/Twig/Tests/LegacyFixtures/test.legacy.test deleted file mode 100644 index d9c1d50..0000000 --- a/core/vendor/twig/twig/test/Twig/Tests/LegacyFixtures/test.legacy.test +++ /dev/null @@ -1,8 +0,0 @@ ---TEST-- -Old test classes usage ---TEMPLATE-- -{{ 'foo' is multi word ? 'yes' : 'no' }} ---DATA-- -return array() ---EXPECT-- -no diff --git a/core/vendor/twig/twig/test/Twig/Tests/LegacyIntegrationTest.php b/core/vendor/twig/twig/test/Twig/Tests/LegacyIntegrationTest.php deleted file mode 100644 index 02ec3cb..0000000 --- a/core/vendor/twig/twig/test/Twig/Tests/LegacyIntegrationTest.php +++ /dev/null @@ -1,45 +0,0 @@ - new Twig_Test_Method($this, 'is_multi_word'), - ); - } - - public function is_multi_word($value) - { - return false !== strpos($value, ' '); - } - - public function getName() - { - return 'legacy_integration_test'; - } -} diff --git a/core/vendor/twig/twig/test/Twig/Tests/LexerTest.php b/core/vendor/twig/twig/test/Twig/Tests/LexerTest.php index 4945d22..1bb7c6b 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/LexerTest.php +++ b/core/vendor/twig/twig/test/Twig/Tests/LexerTest.php @@ -155,6 +155,7 @@ public function testStringWithEscapedDelimiter() "{{ 'foo \' bar' }}" => 'foo \' bar', '{{ "foo \" bar" }}' => 'foo " bar', ); + $lexer = new Twig_Lexer(new Twig_Environment($this->getMock('Twig_LoaderInterface'))); foreach ($tests as $template => $expected) { $stream = $lexer->tokenize($template); diff --git a/core/vendor/twig/twig/test/Twig/Tests/Loader/ArrayTest.php b/core/vendor/twig/twig/test/Twig/Tests/Loader/ArrayTest.php index 1369a6b..ae7648f 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/Loader/ArrayTest.php +++ b/core/vendor/twig/twig/test/Twig/Tests/Loader/ArrayTest.php @@ -68,30 +68,4 @@ public function testIsFreshWhenTemplateDoesNotExist() $loader->isFresh('foo', time()); } - - public function testTemplateReference() - { - $name = new Twig_Test_Loader_TemplateReference('foo'); - $loader = new Twig_Loader_Array(array('foo' => 'bar')); - - $loader->getCacheKey($name); - $loader->getSource($name); - $loader->isFresh($name, time()); - $loader->setTemplate($name, 'foobar'); - } -} - -class Twig_Test_Loader_TemplateReference -{ - private $name; - - public function __construct($name) - { - $this->name = $name; - } - - public function __toString() - { - return $this->name; - } } diff --git a/core/vendor/twig/twig/test/Twig/Tests/Loader/ChainTest.php b/core/vendor/twig/twig/test/Twig/Tests/Loader/ChainTest.php index 4fe0db9..4a4674d 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/Loader/ChainTest.php +++ b/core/vendor/twig/twig/test/Twig/Tests/Loader/ChainTest.php @@ -68,7 +68,8 @@ public function testExists() $loader1->expects($this->never())->method('getSource'); $loader2 = $this->getMock('Twig_LoaderInterface'); - $loader2->expects($this->once())->method('getSource')->will($this->returnValue('content')); + $loader2->expects($this->once())->method('exists')->will($this->returnValue(true)); + $loader2->expects($this->never())->method('getSource'); $loader = new Twig_Loader_Chain(); $loader->addLoader($loader1); diff --git a/core/vendor/twig/twig/test/Twig/Tests/Loader/FilesystemTest.php b/core/vendor/twig/twig/test/Twig/Tests/Loader/FilesystemTest.php index e07f374..75fd821 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/Loader/FilesystemTest.php +++ b/core/vendor/twig/twig/test/Twig/Tests/Loader/FilesystemTest.php @@ -16,7 +16,7 @@ class Twig_Tests_Loader_FilesystemTest extends PHPUnit_Framework_TestCase */ public function testSecurity($template) { - $loader = new Twig_Loader_Filesystem(array(dirname(__FILE__).'/../Fixtures')); + $loader = new Twig_Loader_Filesystem(array(__DIR__.'/../Fixtures')); try { $loader->getCacheKey($template); @@ -53,7 +53,7 @@ public function getSecurityTests() public function testPaths() { - $basePath = dirname(__FILE__).'/Fixtures'; + $basePath = __DIR__.'/Fixtures'; $loader = new Twig_Loader_Filesystem(array($basePath.'/normal', $basePath.'/normal_bis')); $loader->setPaths(array($basePath.'/named', $basePath.'/named_bis'), 'named'); @@ -103,7 +103,7 @@ public function testGetNamespaces() public function testFindTemplateExceptionNamespace() { - $basePath = dirname(__FILE__).'/Fixtures'; + $basePath = __DIR__.'/Fixtures'; $loader = new Twig_Loader_Filesystem(array($basePath.'/normal')); $loader->addPath($basePath.'/named', 'named'); @@ -118,7 +118,7 @@ public function testFindTemplateExceptionNamespace() public function testFindTemplateWithCache() { - $basePath = dirname(__FILE__).'/Fixtures'; + $basePath = __DIR__.'/Fixtures'; $loader = new Twig_Loader_Filesystem(array($basePath.'/normal')); $loader->addPath($basePath.'/named', 'named'); @@ -134,9 +134,9 @@ public function testFindTemplateWithCache() public function testLoadTemplateAndRenderBlockWithCache() { $loader = new Twig_Loader_Filesystem(array()); - $loader->addPath(dirname(__FILE__).'/Fixtures/themes/theme2'); - $loader->addPath(dirname(__FILE__).'/Fixtures/themes/theme1'); - $loader->addPath(dirname(__FILE__).'/Fixtures/themes/theme1', 'default_theme'); + $loader->addPath(__DIR__.'/Fixtures/themes/theme2'); + $loader->addPath(__DIR__.'/Fixtures/themes/theme1'); + $loader->addPath(__DIR__.'/Fixtures/themes/theme1', 'default_theme'); $twig = new Twig_Environment($loader); diff --git a/core/vendor/twig/twig/test/Twig/Tests/Node/Expression/CallTest.php b/core/vendor/twig/twig/test/Twig/Tests/Node/Expression/CallTest.php index 43afcd2..342b4ed 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/Node/Expression/CallTest.php +++ b/core/vendor/twig/twig/test/Twig/Tests/Node/Expression/CallTest.php @@ -14,7 +14,7 @@ class Twig_Tests_Node_Expression_CallTest extends PHPUnit_Framework_TestCase public function testGetArguments() { $node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'date')); - $this->assertEquals(array('U', null), $node->getArguments('date', array('format' => 'U', 'timestamp' => null))); + $this->assertEquals(array('U', null), $this->getArguments($node, array('date', array('format' => 'U', 'timestamp' => null)))); } /** @@ -24,7 +24,7 @@ public function testGetArguments() public function testGetArgumentsWhenPositionalArgumentsAfterNamedArguments() { $node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'date')); - $node->getArguments('date', array('timestamp' => 123456, 'Y-m-d')); + $this->getArguments($node, array('date', array('timestamp' => 123456, 'Y-m-d'))); } /** @@ -34,7 +34,7 @@ public function testGetArgumentsWhenPositionalArgumentsAfterNamedArguments() public function testGetArgumentsWhenArgumentIsDefinedTwice() { $node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'date')); - $node->getArguments('date', array('Y-m-d', 'format' => 'U')); + $this->getArguments($node, array('date', array('Y-m-d', 'format' => 'U'))); } /** @@ -44,7 +44,7 @@ public function testGetArgumentsWhenArgumentIsDefinedTwice() public function testGetArgumentsWithWrongNamedArgumentName() { $node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'date')); - $node->getArguments('date', array('Y-m-d', 'timestamp' => null, 'unknown' => '')); + $this->getArguments($node, array('date', array('Y-m-d', 'timestamp' => null, 'unknown' => ''))); } /** @@ -54,7 +54,7 @@ public function testGetArgumentsWithWrongNamedArgumentName() public function testGetArgumentsWithWrongNamedArgumentNames() { $node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'date')); - $node->getArguments('date', array('Y-m-d', 'timestamp' => null, 'unknown1' => '', 'unknown2' => '')); + $this->getArguments($node, array('date', array('Y-m-d', 'timestamp' => null, 'unknown1' => '', 'unknown2' => ''))); } /** @@ -68,20 +68,20 @@ public function testResolveArgumentsWithMissingValueForOptionalArgument() } $node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'substr_compare')); - $node->getArguments('substr_compare', array('abcd', 'bc', 'offset' => 1, 'case_sensitivity' => true)); + $this->getArguments($node, array('substr_compare', array('abcd', 'bc', 'offset' => 1, 'case_sensitivity' => true))); } public function testResolveArgumentsOnlyNecessaryArgumentsForCustomFunction() { $node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'custom_function')); - $this->assertEquals(array('arg1'), $node->getArguments(array($this, 'customFunction'), array('arg1' => 'arg1'))); + $this->assertEquals(array('arg1'), $this->getArguments($node, array(array($this, 'customFunction'), array('arg1' => 'arg1')))); } public function testGetArgumentsForStaticMethod() { $node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'custom_static_function')); - $this->assertEquals(array('arg1'), $node->getArguments(__CLASS__.'::customStaticFunction', array('arg1' => 'arg1'))); + $this->assertEquals(array('arg1'), $this->getArguments($node, array(__CLASS__.'::customStaticFunction', array('arg1' => 'arg1')))); } /** @@ -91,7 +91,7 @@ public function testGetArgumentsForStaticMethod() public function testResolveArgumentsWithMissingParameterForArbitraryArguments() { $node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'foo', 'is_variadic' => true)); - $node->getArguments(array($this, 'customFunctionWithArbitraryArguments'), array()); + $this->getArguments($node, array(array($this, 'customFunctionWithArbitraryArguments'), array())); } public static function customStaticFunction($arg1, $arg2 = 'default', $arg3 = array()) @@ -102,6 +102,14 @@ public function customFunction($arg1, $arg2 = 'default', $arg3 = array()) { } + private function getArguments($call, $args) + { + $m = new ReflectionMethod($call, 'getArguments'); + $m->setAccessible(true); + + return $m->invokeArgs($call, $args); + } + public function customFunctionWithArbitraryArguments() { } @@ -109,8 +117,4 @@ public function customFunctionWithArbitraryArguments() class Twig_Tests_Node_Expression_Call extends Twig_Node_Expression_Call { - public function getArguments($callable, $arguments) - { - return parent::getArguments($callable, $arguments); - } } diff --git a/core/vendor/twig/twig/test/Twig/Tests/Node/Expression/FilterTest.php b/core/vendor/twig/twig/test/Twig/Tests/Node/Expression/FilterTest.php index d5ffb24..0482dac 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/Node/Expression/FilterTest.php +++ b/core/vendor/twig/twig/test/Twig/Tests/Node/Expression/FilterTest.php @@ -26,7 +26,7 @@ public function testConstructor() public function getTests() { $environment = new Twig_Environment($this->getMock('Twig_LoaderInterface')); - $environment->addFilter(new Twig_SimpleFilter('bar', 'bar', array('needs_environment' => true))); + $environment->addFilter(new Twig_SimpleFilter('bar', 'twig_tests_filter_dummy', array('needs_environment' => true))); $environment->addFilter(new Twig_SimpleFilter('barbar', 'twig_tests_filter_barbar', array('needs_context' => true, 'is_variadic' => true))); $tests = array(); @@ -68,17 +68,15 @@ public function getTests() $tests[] = array($node, 'twig_reverse_filter($this->env, "abc", true)'); // filter as an anonymous function - if (PHP_VERSION_ID >= 50300) { - $node = $this->createFilter(new Twig_Node_Expression_Constant('foo', 1), 'anonymous'); - $tests[] = array($node, 'call_user_func_array($this->env->getFilter(\'anonymous\')->getCallable(), array("foo"))'); - } + $node = $this->createFilter(new Twig_Node_Expression_Constant('foo', 1), 'anonymous'); + $tests[] = array($node, 'call_user_func_array($this->env->getFilter(\'anonymous\')->getCallable(), array("foo"))'); // needs environment $node = $this->createFilter($string, 'bar'); - $tests[] = array($node, 'bar($this->env, "abc")', $environment); + $tests[] = array($node, 'twig_tests_filter_dummy($this->env, "abc")', $environment); $node = $this->createFilter($string, 'bar', array(new Twig_Node_Expression_Constant('bar', 1))); - $tests[] = array($node, 'bar($this->env, "abc", "bar")', $environment); + $tests[] = array($node, 'twig_tests_filter_dummy($this->env, "abc", "bar")', $environment); // arbitrary named arguments $node = $this->createFilter($string, 'barbar'); @@ -141,14 +139,17 @@ protected function createFilter($node, $name, array $arguments = array()) protected function getEnvironment() { - if (PHP_VERSION_ID >= 50300) { - return include 'PHP53/FilterInclude.php'; - } + $env = new Twig_Environment(new Twig_Loader_Array(array())); + $env->addFilter(new Twig_Filter('anonymous', function () {})); - return parent::getEnvironment(); + return $env; } } +function twig_tests_filter_dummy() +{ +} + function twig_tests_filter_barbar($context, $string, $arg1 = null, $arg2 = null, array $args = array()) { } diff --git a/core/vendor/twig/twig/test/Twig/Tests/Node/Expression/FunctionTest.php b/core/vendor/twig/twig/test/Twig/Tests/Node/Expression/FunctionTest.php index de2e0f8..b0c259d 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/Node/Expression/FunctionTest.php +++ b/core/vendor/twig/twig/test/Twig/Tests/Node/Expression/FunctionTest.php @@ -24,37 +24,37 @@ public function testConstructor() public function getTests() { $environment = new Twig_Environment($this->getMock('Twig_LoaderInterface')); - $environment->addFunction(new Twig_SimpleFunction('foo', 'foo', array())); - $environment->addFunction(new Twig_SimpleFunction('bar', 'bar', array('needs_environment' => true))); - $environment->addFunction(new Twig_SimpleFunction('foofoo', 'foofoo', array('needs_context' => true))); - $environment->addFunction(new Twig_SimpleFunction('foobar', 'foobar', array('needs_environment' => true, 'needs_context' => true))); - $environment->addFunction(new Twig_SimpleFunction('barbar', 'twig_tests_function_barbar', array('is_variadic' => true))); + $environment->addFunction(new Twig_Function('foo', 'twig_tests_function_dummy', array())); + $environment->addFunction(new Twig_Function('bar', 'twig_tests_function_dummy', array('needs_environment' => true))); + $environment->addFunction(new Twig_Function('foofoo', 'twig_tests_function_dummy', array('needs_context' => true))); + $environment->addFunction(new Twig_Function('foobar', 'twig_tests_function_dummy', array('needs_environment' => true, 'needs_context' => true))); + $environment->addFunction(new Twig_Function('barbar', 'twig_tests_function_barbar', array('is_variadic' => true))); $tests = array(); $node = $this->createFunction('foo'); - $tests[] = array($node, 'foo()', $environment); + $tests[] = array($node, 'twig_tests_function_dummy()', $environment); $node = $this->createFunction('foo', array(new Twig_Node_Expression_Constant('bar', 1), new Twig_Node_Expression_Constant('foobar', 1))); - $tests[] = array($node, 'foo("bar", "foobar")', $environment); + $tests[] = array($node, 'twig_tests_function_dummy("bar", "foobar")', $environment); $node = $this->createFunction('bar'); - $tests[] = array($node, 'bar($this->env)', $environment); + $tests[] = array($node, 'twig_tests_function_dummy($this->env)', $environment); $node = $this->createFunction('bar', array(new Twig_Node_Expression_Constant('bar', 1))); - $tests[] = array($node, 'bar($this->env, "bar")', $environment); + $tests[] = array($node, 'twig_tests_function_dummy($this->env, "bar")', $environment); $node = $this->createFunction('foofoo'); - $tests[] = array($node, 'foofoo($context)', $environment); + $tests[] = array($node, 'twig_tests_function_dummy($context)', $environment); $node = $this->createFunction('foofoo', array(new Twig_Node_Expression_Constant('bar', 1))); - $tests[] = array($node, 'foofoo($context, "bar")', $environment); + $tests[] = array($node, 'twig_tests_function_dummy($context, "bar")', $environment); $node = $this->createFunction('foobar'); - $tests[] = array($node, 'foobar($this->env, $context)', $environment); + $tests[] = array($node, 'twig_tests_function_dummy($this->env, $context)', $environment); $node = $this->createFunction('foobar', array(new Twig_Node_Expression_Constant('bar', 1))); - $tests[] = array($node, 'foobar($this->env, $context, "bar")', $environment); + $tests[] = array($node, 'twig_tests_function_dummy($this->env, $context, "bar")', $environment); // named arguments $node = $this->createFunction('date', array( @@ -82,10 +82,8 @@ public function getTests() $tests[] = array($node, 'twig_tests_function_barbar("1", "2", array(0 => "3", "foo" => "bar"))', $environment); // function as an anonymous function - if (PHP_VERSION_ID >= 50300) { - $node = $this->createFunction('anonymous', array(new Twig_Node_Expression_Constant('foo', 1))); - $tests[] = array($node, 'call_user_func_array($this->env->getFunction(\'anonymous\')->getCallable(), array("foo"))'); - } + $node = $this->createFunction('anonymous', array(new Twig_Node_Expression_Constant('foo', 1))); + $tests[] = array($node, 'call_user_func_array($this->env->getFunction(\'anonymous\')->getCallable(), array("foo"))'); return $tests; } @@ -97,14 +95,17 @@ protected function createFunction($name, array $arguments = array()) protected function getEnvironment() { - if (PHP_VERSION_ID >= 50300) { - return include 'PHP53/FunctionInclude.php'; - } + $env = new Twig_Environment(new Twig_Loader_Array(array())); + $env->addFunction(new Twig_Function('anonymous', function () {})); - return parent::getEnvironment(); + return $env; } } +function twig_tests_function_dummy() +{ +} + function twig_tests_function_barbar($arg1 = null, $arg2 = null, array $args = array()) { } diff --git a/core/vendor/twig/twig/test/Twig/Tests/Node/Expression/NameTest.php b/core/vendor/twig/twig/test/Twig/Tests/Node/Expression/NameTest.php index 8cbb2f7..10f51a1 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/Node/Expression/NameTest.php +++ b/core/vendor/twig/twig/test/Twig/Tests/Node/Expression/NameTest.php @@ -27,7 +27,7 @@ public function getTests() $env1 = new Twig_Environment($this->getMock('Twig_LoaderInterface'), array('strict_variables' => false)); return array( - array($node, "// line 1\n".(PHP_VERSION_ID >= 50400 ? '(isset($context["foo"]) ? $context["foo"] : $this->getContext($context, "foo"))' : '$this->getContext($context, "foo")'), $env), + array($node, "// line 1\n".'(isset($context["foo"]) || array_key_exists("foo", $context) ? $context["foo"] : $this->notFound("foo", 1))', $env), array($node, $this->getVariableGetter('foo', 1), $env1), array($context, "// line 1\n\$context"), ); diff --git a/core/vendor/twig/twig/test/Twig/Tests/Node/Expression/PHP53/FilterInclude.php b/core/vendor/twig/twig/test/Twig/Tests/Node/Expression/PHP53/FilterInclude.php deleted file mode 100644 index b5394bc..0000000 --- a/core/vendor/twig/twig/test/Twig/Tests/Node/Expression/PHP53/FilterInclude.php +++ /dev/null @@ -1,6 +0,0 @@ -addFilter(new Twig_SimpleFilter('anonymous', function () {})); - -return $env; diff --git a/core/vendor/twig/twig/test/Twig/Tests/Node/Expression/PHP53/FunctionInclude.php b/core/vendor/twig/twig/test/Twig/Tests/Node/Expression/PHP53/FunctionInclude.php deleted file mode 100644 index e8f68c7..0000000 --- a/core/vendor/twig/twig/test/Twig/Tests/Node/Expression/PHP53/FunctionInclude.php +++ /dev/null @@ -1,6 +0,0 @@ -addFunction(new Twig_SimpleFunction('anonymous', function () {})); - -return $env; diff --git a/core/vendor/twig/twig/test/Twig/Tests/Node/Expression/PHP53/TestInclude.php b/core/vendor/twig/twig/test/Twig/Tests/Node/Expression/PHP53/TestInclude.php deleted file mode 100644 index 9f818bc..0000000 --- a/core/vendor/twig/twig/test/Twig/Tests/Node/Expression/PHP53/TestInclude.php +++ /dev/null @@ -1,6 +0,0 @@ -addTest(new Twig_SimpleTest('anonymous', function () {})); - -return $env; diff --git a/core/vendor/twig/twig/test/Twig/Tests/Node/Expression/TestTest.php b/core/vendor/twig/twig/test/Twig/Tests/Node/Expression/TestTest.php index 55d3fcb..2b90a10 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/Node/Expression/TestTest.php +++ b/core/vendor/twig/twig/test/Twig/Tests/Node/Expression/TestTest.php @@ -35,10 +35,8 @@ public function getTests() $tests[] = array($node, '(null === "foo")'); // test as an anonymous function - if (PHP_VERSION_ID >= 50300) { - $node = $this->createTest(new Twig_Node_Expression_Constant('foo', 1), 'anonymous', array(new Twig_Node_Expression_Constant('foo', 1))); - $tests[] = array($node, 'call_user_func_array($this->env->getTest(\'anonymous\')->getCallable(), array("foo", "foo"))'); - } + $node = $this->createTest(new Twig_Node_Expression_Constant('foo', 1), 'anonymous', array(new Twig_Node_Expression_Constant('foo', 1))); + $tests[] = array($node, 'call_user_func_array($this->env->getTest(\'anonymous\')->getCallable(), array("foo", "foo"))'); // arbitrary named arguments $string = new Twig_Node_Expression_Constant('abc', 1); @@ -69,11 +67,10 @@ protected function createTest($node, $name, array $arguments = array()) protected function getEnvironment() { - if (PHP_VERSION_ID >= 50300) { - return include 'PHP53/TestInclude.php'; - } + $env = new Twig_Environment(new Twig_Loader_Array(array())); + $env->addTest(new Twig_Test('anonymous', function () {})); - return parent::getEnvironment(); + return $env; } } diff --git a/core/vendor/twig/twig/test/Twig/Tests/Node/ForTest.php b/core/vendor/twig/twig/test/Twig/Tests/Node/ForTest.php index b289592..b2c6fa4 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/Node/ForTest.php +++ b/core/vendor/twig/twig/test/Twig/Tests/Node/ForTest.php @@ -51,7 +51,7 @@ public function getTests() $tests[] = array($node, <<getVariableGetter('items')}); foreach (\$context['_seq'] as \$context["key"] => \$context["item"]) { echo {$this->getVariableGetter('foo')}; @@ -73,7 +73,7 @@ public function getTests() $tests[] = array($node, <<getVariableGetter('values')}); \$context['loop'] = array( 'parent' => \$context['_parent'], @@ -116,7 +116,7 @@ public function getTests() $tests[] = array($node, <<getVariableGetter('values')}); \$context['loop'] = array( 'parent' => \$context['_parent'], @@ -149,7 +149,7 @@ public function getTests() $tests[] = array($node, <<getVariableGetter('values')}); \$context['_iterated'] = false; \$context['loop'] = array( diff --git a/core/vendor/twig/twig/test/Twig/Tests/Node/MacroTest.php b/core/vendor/twig/twig/test/Twig/Tests/Node/MacroTest.php index 901e57b..ec27977 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/Node/MacroTest.php +++ b/core/vendor/twig/twig/test/Twig/Tests/Node/MacroTest.php @@ -42,7 +42,7 @@ public function getTests() return array( array($node, <<env->mergeGlobals(array( "foo" => \$__foo__, diff --git a/core/vendor/twig/twig/test/Twig/Tests/NodeVisitor/OptimizerTest.php b/core/vendor/twig/twig/test/Twig/Tests/NodeVisitor/OptimizerTest.php index b5ea7aa..aca8970 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/NodeVisitor/OptimizerTest.php +++ b/core/vendor/twig/twig/test/Twig/Tests/NodeVisitor/OptimizerTest.php @@ -34,21 +34,6 @@ public function testRenderParentBlockOptimizer() $this->assertTrue($node->getAttribute('output')); } - public function testRenderVariableBlockOptimizer() - { - if (PHP_VERSION_ID >= 50400) { - return; - } - - $env = new Twig_Environment($this->getMock('Twig_LoaderInterface'), array('cache' => false, 'autoescape' => false)); - $stream = $env->parse($env->tokenize('{{ block(name|lower) }}', 'index')); - - $node = $stream->getNode('body')->getNode(0)->getNode(1); - - $this->assertEquals('Twig_Node_Expression_BlockReference', get_class($node)); - $this->assertTrue($node->getAttribute('output')); - } - /** * @dataProvider getTestsForForOptimizer */ @@ -102,7 +87,7 @@ public function getTestsForForOptimizer() ); } - public function checkForConfiguration(Twig_NodeInterface $node = null, $target, $withLoop) + public function checkForConfiguration(Twig_Node $node = null, $target, $withLoop) { if (null === $node) { return; diff --git a/core/vendor/twig/twig/test/Twig/Tests/ParserTest.php b/core/vendor/twig/twig/test/Twig/Tests/ParserTest.php index b29dac3..398173b 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/ParserTest.php +++ b/core/vendor/twig/twig/test/Twig/Tests/ParserTest.php @@ -11,15 +11,6 @@ class Twig_Tests_ParserTest extends PHPUnit_Framework_TestCase { /** - * @expectedException Twig_Error_Syntax - */ - public function testSetMacroThrowsExceptionOnReservedMethods() - { - $parser = $this->getParser(); - $parser->setMacro('parent', $this->getMock('Twig_Node_Macro', array(), array(), '', null)); - } - - /** * @expectedException Twig_Error_Syntax * @expectedExceptionMessage Unknown tag name "foo". Did you mean "for" at line 1 */ @@ -41,8 +32,10 @@ public function testUnknownTag() public function testFilterBodyNodes($input, $expected) { $parser = $this->getParser(); + $m = new ReflectionMethod($parser, 'filterBodyNodes'); + $m->setAccessible(true); - $this->assertEquals($expected, $parser->filterBodyNodes($input)); + $this->assertEquals($expected, $m->invoke($parser, $input)); } public function getFilterBodyNodesData() @@ -71,7 +64,10 @@ public function testFilterBodyNodesThrowsException($input) { $parser = $this->getParser(); - $parser->filterBodyNodes($input); + $m = new ReflectionMethod($parser, 'filterBodyNodes'); + $m->setAccessible(true); + + $m->invoke($parser, $input); } public function getFilterBodyNodesDataThrowsException() @@ -89,7 +85,10 @@ public function getFilterBodyNodesDataThrowsException() public function testFilterBodyNodesWithBOM() { $parser = $this->getParser(); - $parser->filterBodyNodes(new Twig_Node_Text(chr(0xEF).chr(0xBB).chr(0xBF), 1)); + + $m = new ReflectionMethod($parser, 'filterBodyNodes'); + $m->setAccessible(true); + $m->invoke($parser, new Twig_Node_Text(chr(0xEF).chr(0xBB).chr(0xBF), 1)); } public function testParseIsReentrant() @@ -137,24 +136,16 @@ public function testGetVarName() protected function getParser() { - $parser = new TestParser(new Twig_Environment($this->getMock('Twig_LoaderInterface'))); + $parser = new Twig_Parser(new Twig_Environment($this->getMock('Twig_LoaderInterface'))); $parser->setParent(new Twig_Node()); - $parser->stream = $this->getMockBuilder('Twig_TokenStream')->disableOriginalConstructor()->getMock(); + $p = new ReflectionProperty($parser, 'stream'); + $p->setAccessible(true); + $p->setValue($parser, $this->getMockBuilder('Twig_TokenStream')->disableOriginalConstructor()->getMock()); return $parser; } } -class TestParser extends Twig_Parser -{ - public $stream; - - public function filterBodyNodes(Twig_NodeInterface $node) - { - return parent::filterBodyNodes($node); - } -} - class TestTokenParser extends Twig_TokenParser { public function parse(Twig_Token $token) diff --git a/core/vendor/twig/twig/test/Twig/Tests/TemplateTest.php b/core/vendor/twig/twig/test/Twig/Tests/TemplateTest.php index 31a844b..c028b00 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/TemplateTest.php +++ b/core/vendor/twig/twig/test/Twig/Tests/TemplateTest.php @@ -663,7 +663,7 @@ public function __call($method, $arguments) class CExtDisablingNodeVisitor implements Twig_NodeVisitorInterface { - public function enterNode(Twig_NodeInterface $node, Twig_Environment $env) + public function enterNode(Twig_Node $node, Twig_Environment $env) { if ($node instanceof Twig_Node_Expression_GetAttr) { $node->setAttribute('disable_c_ext', true); @@ -672,7 +672,7 @@ public function enterNode(Twig_NodeInterface $node, Twig_Environment $env) return $node; } - public function leaveNode(Twig_NodeInterface $node, Twig_Environment $env) + public function leaveNode(Twig_Node $node, Twig_Environment $env) { return $node; } diff --git a/core/vendor/twig/twig/test/bootstrap.php b/core/vendor/twig/twig/test/bootstrap.php deleted file mode 100644 index aecb976..0000000 --- a/core/vendor/twig/twig/test/bootstrap.php +++ /dev/null @@ -1,13 +0,0 @@ -