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
This PR was merged into the 1.x branch.
Discussion
----------
Fix race condition in `Environment::loadTemplate` (1.x)
Fixes#1836 (1.x branch)
Commits
-------
1bb7000 Fix race condition in `Environment::loadTemplate`
This PR was merged into the 1.x branch.
Discussion
----------
Fix instance variable declaration in Filesystem cache
Commits
-------
d88c8a9 Fix instance variable declaration in Filesystem cache
This PR was merged into the 1.x branch.
Discussion
----------
Non-existing files are not cached by statcache
Reverts #1583
Based on the docs this cannot happen because the stat cache is only active for existing files.
> You should also note that PHP doesn't cache information about non-existent files. So, if you call file_exists() on a file that doesn't exist, it will return FALSE until you create the file. If you create the file, it will return TRUE even if you then delete the file. However unlink() clears the cache automatically.
http://php.net/manual/en/function.clearstatcache.php
Also the arugments you pass to clearstatcache(false, $filename) make no sense according the documentation and are not effective.
> filename
Clear the realpath and the stat cache for a specific filename only; only used if clear_realpath_cache is TRUE.
Also doctrine cachee does't use this approach either: https://github.com/doctrine/cache/blob/master/lib/Doctrine/Common/Cache/FileCache.php#L185 And nobody reported problems with this as far as I can see.
Commits
-------
4edf3fd Non-existing files are not cached by statcache
Reverts #1583
Based on the docs this cannot happen because the stat cache is only active for existing files.
> You should also note that PHP doesn't cache information about non-existent files. So, if you call file_exists() on a file that doesn't exist, it will return FALSE until you create the file. If you create the file, it will return TRUE even if you then delete the file. However unlink() clears the cache automatically.
http://php.net/manual/en/function.clearstatcache.php
Also the arugments you pass to clearstatcache(false, $filename) make no sense according the documentation and are not effective.
> filename
Clear the realpath and the stat cache for a specific filename only; only used if clear_realpath_cache is TRUE.
Also doctrine cachee does't use this approach either: https://github.com/doctrine/cache/blob/master/lib/Doctrine/Common/Cache/FileCache.php#L185 And nobody reported problems with this as far as I can see.
This PR was merged into the 1.x branch.
Discussion
----------
added @internal when appropriate
Commits
-------
2c0839c added @internal when appropriate
This PR was merged into the 1.x branch.
Discussion
----------
fixed implementation of Null cache
fixes#1832
Commits
-------
b43e298 fixed implementation of Null cache
This PR was merged into the 1.x branch.
Discussion
----------
String-cast in template_from_string
Fixes#1829 caused by https://github.com/twigphp/Twig/pull/1807/files#diff-5e190f538c5c328c7473a5cfd3b7cd95R578
As twig allows many types in twig templates, e.g. array or traversable, we can do the same for string.
But we only take this approach for twig exposed function/filters etc, i.e. template code, but not core code.
Commits
-------
e1e3655 String-case in template_from_string
This PR was merged into the 1.x branch.
Discussion
----------
Prevent potential doc comments in escaped inlined source
Hopefully the last patch of this multi-patches feature...
Commits
-------
f35a540 Prevent potential doc comments in escaped inlined source
This PR was squashed before being merged into the 1.x branch (closes#1806).
Discussion
----------
More flexible integration test
replaces https://github.com/twigphp/Twig/pull/1805 as a 1.x version
Commits
-------
3f779f6 More flexible integration test
This PR was merged into the 1.x branch.
Discussion
----------
No need to check modification time when opcache_invalidate
- We know the file is new
- No need to check if opcache/apc is enabled as these methods will just return false in this case
Commits
-------
f63099e No need to check modification time when opcache_invalidate
This PR was merged into the 1.x branch.
Discussion
----------
rewrote the recipes about APC and opcache to avoid deprecation notices
Commits
-------
96a54b3 added an option to force PHP bytecode invalidation when writing a compiled template into the cache
e9b0802 rewrote the recipes about APC and opcache to avoid deprecation notices
This PR was merged into the 1.x branch.
Discussion
----------
added a recipe about how to render a template stored as a string
Commits
-------
77fed4e added a recipe about how to render a template stored as a string