This PR was merged into the 1.x branch.
Discussion
----------
deprecated the possibility to override an extension by registering an other one with the same name
Commits
-------
72485c2 deprecated the possibility to override an extension by registering another one with the same name
This PR was merged into the 1.x branch.
Discussion
----------
deprecated Twig_ExtensionInterface::initRuntime()
I'm working on splitting Twig extensions into 2 different phases: compilation and runtime. The goal is to avoid having to load the runtime environment of an extension when compiling templates. That also opens the way to be able to lazy-load Twig extensions.
While working on the split, I realized that the `initRuntime()` method on `Twig_ExtensionInterface` is not needed anymore. It was added at a time `needs_environment` did not exist and was a way to keep the environment around for custom filters/tests/functions. But nowadays, that's not needed anymore. I did a quick search on Github, and most of the implementation I found just store the environment in a local property, which is not needed anymore. So, I propose to deprecate it in 1.x and remove it in 2.0.
Commits
-------
9774f4f deprecated Twig_ExtensionInterface::initRuntime()
This PR was merged into the 1.x branch.
Discussion
----------
deprecated Twig_Environment::computeAlternatives()
Commits
-------
d0a5ef8 deprecated Twig_Environment::computeAlternatives()
This PR was merged into the 1.x branch.
Discussion
----------
made the tests semantically more correct
Calling `initRuntime()` is just a side-effect of loading a template.
Commits
-------
f839ad3 made the tests semantically more correct
This PR was merged into the 1.x branch.
Discussion
----------
Fix adding mock extension to Twig environment
When the extension class is not defined in a file but in eval'd code we cannot assume `ReflectionObject::getFileName()` will return a valid file path.
https://bugs.php.net/bug.php?id=63901
This PR adds a test case that produce the following error without the fix:
```
1) Twig_Tests_EnvironmentTest::testAddMockExtension
filemtime(): stat failed for phar:///usr/local/php5-5.5.14-20140628-105310/bin/phpunit/phpunit-mock-objects/Framework/MockObject/Generator.php(335) : eval()'d code
/xxx/Twig/vendor/symfony/phpunit-bridge/DeprecationErrorHandler.php:40
/xxx/Twig/lib/Twig/Environment.php:769
/xxx/Twig/test/Twig/Tests/EnvironmentTest.php:304
```
I encountered this issue with mocked twig extensions in SonataAdminBundle test suite:
https://github.com/sonata-project/SonataAdminBundle/blob/master/Tests/Controller/HelperControllerTest.php#L254
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #1870
| License | MIT
| Doc PR | n/a
Commits
-------
a57b1cc Fix adding mock extension to Twig environment
When the extension class is not defined in a file but in eval'd code
we cannot assume ReflectionObject::getFileName will return
a valid file path.
https://bugs.php.net/bug.php?id=63901
This PR was merged into the 1.x branch.
Discussion
----------
removed obsolete documentation about requiring classes
Commits
-------
eac8c0c removed obsolete documentation about requiring classes
This PR was merged into the 1.x branch.
Discussion
----------
fixed BC break by allowing null as the cache strategy
fixes#1851
Commits
-------
d6316d6 fixed BC break by allowing null as the cache strategy
This PR was merged into the 1.x branch.
Discussion
----------
added a note about using .. and | together
fixes#1860
Commits
-------
3802920 added a note about using .. and | together
This PR was merged into the 1.x branch.
Discussion
----------
Improved performance of template freshness checks
Same as #1864 but with with even less perf impact.
Commits
-------
7030fdd simplified logic and improve perf slightly
77c94ea Added a cache for extension freshness test
Freshness of each extension was been checked everytime a template was loaded.
Projects with many templates and extension benefit noticeably with this cache.
Only environments with debug or autoload set are affected.
This PR was squashed before being merged into the 1.x branch (closes#1866).
Discussion
----------
Check if cached file exists
Without this modification:
```
Array
(
[code] => 2
[message] => filemtime(): stat failed for /Users/torzech/code/[---cut---]/app/cache/6/9/69b8b36648330d23ccfb6e8b7542e0dbdd518a910ab986d602639e1b855de522.php
[file] => /Users/torzech/code/[---cut---]/libs/twig/twig/lib/Twig/Cache/Filesystem.php
[line] => 91
)
```
Commits
-------
154bc9d Check if cached file exists
This PR was squashed before being merged into the 1.x branch (closes#1846).
Discussion
----------
Add test coverage for auto_reload
Fixes#1841
Commits
-------
1769f84 Add test coverage for auto_reload
This PR was merged into the 1.x branch.
Discussion
----------
Add unit tests for filesystem cache
Fixes#1842
Commits
-------
40555fc Add test coverage for Twig_Cache_Filesystem
This PR was merged into the 1.x branch.
Discussion
----------
fix template class name generation to prevent possible collisions
- fix template class name generation to prevent possible collisions
- save one inode per file
- fix tests as they are broken with the cext since #1844
Commits
-------
f379e81 fix template class name generation to prevent possible collisions and one inode per file
This PR was squashed before being merged into the 1.x branch (closes#1855).
Discussion
----------
Fix custom escaper null values
First, a bit of context:
About 10 years ago, when I was doing some Java, I used to use a SQL mapper called iBatis (now moved to myBatis here: http://mybatis.github.io/mybatis-3/dynamic-sql.html)
The whole concept is to put SQL requests in XML files and use XML as a templating engine. Here is a code sample:
```xml
SELECT * FROM BLOG
WHERE state = ‘ACTIVE’
<if test="title != null">
AND title like #{title}
</if>
```
Fast forward today. I just realized Twig could be a great tool to do exactly the same. Just imagine:
```SQL
SELECT * FROM BLOG
WHERE state = ‘ACTIVE’
{% if title %}
AND title like {{ title }}
{% endif %}
```
All I need to do is write a custom escaper. Like this one:
```php
$twig->getExtension('core')->setEscaper('sql', function(\Twig_Environment $env, $string, $charset) use ($connection) {
// $connection is a DBAL connection
return $connection->quote($string);
});
```
Now, here is my problem:
For an SQL escaper to work, I would need *null* to translate into the 'NULL' string.
But in Twig, escapers are not triggered for null or numeric values. This is due to these lines of code: https://github.com/twigphp/Twig/blob/1.x/lib/Twig/Extension/Core.php#L1021-L1027
```php
if (!is_string($string)) {
if (is_object($string) && method_exists($string, '__toString')) {
$string = (string) $string;
} else {
return $string;
}
}
```
Everything that is not a string (i.e. a numeric value, null, an array...) is directly returned and completely bypasses the escaper.
I understand that this behaviour is ok in most cases (html, js, css, url, etc...), and that it allows some degree of optimisation, but it prevents from working on more specific escapers like a SQL escaper. It is also an undocumented behaviour of custom escapers.
This pull request tries to fix this without impacting performance.
In most Twig installations, no custom escapers are used. In this cases, returning early is a good idea since all default escapers share the same behaviour.
If there is a custom escaper configured however, I'm going the "long" route to be sure that the custom escaper is fed with all values (and not only non empty strings)
Commits
-------
6f84981 Fix custom escaper null values
This PR was merged into the 1.x branch.
Discussion
----------
Remove deprecated return types from the PHPDocs.
There are deprecation warnings added to the environment (for example https://github.com/twigphp/Twig/blob/1.x/lib/Twig/Environment.php#L1287).
This PR aims to remove the deprecated return types from the PHPDocs as well. It will be useful for developers, but for for IDE's/SCA as well.
Commits
-------
831fd60 Remove deprecated return types from the PHPDocs.
This PR was merged into the 1.x branch.
Discussion
----------
changed template cache names to take into account the Twig C extension
Commits
-------
76ecd43 changed template cache names to take into account the Twig C extension