* allow `|length` of `null`
* allow `|length` of objects not implementing `\Countable`
* To get no errors when running with PHP 7.2 You need to use phpunit
^6.1, otherwise the `each` function, used by phpunit, triggers errors.
You can do so by running phpunit like:
`SYMFONY_PHPUNIT_VERSION=6.1 phpnightly vendor/bin/simple-phpunit` *
* 1.x:
Wrong stdClass class name generates warning
added more is_object() safegaruds
Autoescape test addition; collision fix in Array Loader.
test if is_object before calling method_exists, fixes#2431
bumped version to 1.33.1-DEV
prepared the 1.33.0 release
* 1.x:
updated CHANGELOG
Call clearstatcache() before calling is_dir().
bumped version to 1.33
fixed CHANGELOG
Make "length" filter and "empty" test consider __toString [Twig 1.x]
This PR was squashed before being merged into the 1.x branch (closes#2420).
Discussion
----------
Make "length" filter and "empty" test consider __toString [Twig 1.x]
Use case: When you have variables in your views that are actually objects but implement `__toString`, they feel like strings: For example, `{{ something }}` will make use of that to-string-conversion.
What does *not* work is
**a)** `{{ something | length }}`, because that will only have a meaningful return value for objects implementing `\Countable`. This interface, however, may have a totally different semantic/purpose for the object in question.
**b)** `{% if something is empty %}`, because
> empty checks if a variable is an empty string, an empty array, an empty hash, exactly false, or exactly null `[http://twig.sensiolabs.org/doc/2.x/tests/empty.html]`
... and obviously `something !== null` in this case.
For template designers, this may be surprising if they don't actually care about the object-or-string difference, they just "use" the variable.
This change tries to address this as it changes the behavior for such objects that have a `__toString` method and are *not* `\Countable`.
*Yes*, it's a BC break in edge cases:
For a), objects that implement a `__toString` but not `\Countable` would previously yield `1` for `{{ object | length }}`, and now would return the length of the string returned by `__toString`.
For b), testing (defined) variables that are objects implementing `__toString` and that return `''`, the test now is `false`.
Commits
-------
f5193e92 Make "length" filter and "empty" test consider __toString [Twig 1.x]
This PR was merged into the 2.x branch.
Discussion
----------
Fix undef. source in exception.
closes https://github.com/twigphp/Twig/issues/2383
Two things:
- the tests fails without a corrupt cache, so maybe the message is of or the cache generation is off (i.e. not respecting the `$index`)
- passing the `$source` seems superfluous (but maybe that is only the case in the exception message)
Commits
-------
772373cf Fix undef. source in exception.
* 1.x:
fixed tests for PHP 5.2
fixed tests for PHP 5.2
fixed tests for PHP 5.2
Fix typo in test filename
added a note in the docs about the PSR-11 runtime loader
fixed typo
updated CHANGELOG
bumped version to 1.32
Add ContainerRuntimeLoader
tweaked docs
Update striptags.rst
fixed CS
Mention autoescape=true deprecation (issue #2386)
Fix typo.
bumped version to 1.31.1-DEV
prepared the 1.31.0 release
added a note about macros usage in the deprecated docs
This PR was squashed before being merged into the 1.x branch (closes#2265).
Discussion
----------
Optimize usage of Traversable/Iterator
Commits
-------
2bdcfb6 Optimize usage of Traversable/Iterator
This PR was merged into the 2.x branch.
Discussion
----------
moved Twig_Template::getAttribute() to a function
Commits
-------
6405684 moved Twig_Template::getAttribute() to a function
This PR was merged into the 1.x branch.
Discussion
----------
Add a simple Twig_RuntimeLoaderInterface implementation
Next to https://github.com/symfony/symfony/pull/21023
This is related to the BC break reported in symfony/symfony#21008 which has been introduced in symfony/symfony#20093 when decoupling extensions from definitions.
What I propose here is to ease the upgrade to symfony 3.2+ by adding a simple `Twig_RuntimeLoaderInterface` implementation here, useful only when using the twig-bridge outside of the symfony fullstack framework (with the Form component for instance).
Upgrading would be as simple as:
```diff
$twig = new Twig_Environment(...);
$rendererEngine = new TwigRendererEngine(array('form_div_layout.html.twig'), $twig);
- $twig->addExtension(new FormExtension(new TwigRenderer($rendererEngine, $csrfTokenManager)));
+ $twig->addExtension(new FormExtension());
+ $twig->addRuntimeLoader(new Twig_RuntimeLoader(array(TwigRenderer::class => new TwigRenderer($rendererEngine, $csrfTokenManager)));
```
Instead of having to write this runtime loader yourself.
Please see symfony/symfony#21008 for details and a concrete example of how this could help.
Commits
-------
91c8d59 Add a Twig_FactoryRuntimeLoader