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
This PR was merged into the 1.x branch.
Discussion
----------
Profiler root duration fix
When using the Twig profiler, the root node is a bit special and the duration should really be the sum of the children duration. That should fix#1792
Commits
-------
f1e963c fixed the profiler duration for the root node
This PR was merged into the 1.x branch.
Discussion
----------
changed the arguments of generateKey
We now pass the template name and the template class, which seems much better from a UX standpoint.
Passing the prefix was really just a hack and an implementation leak to be able to determine the variable part of the class name and generate sub-directories for templates. Now, we generate the cache key by taking the last characters instead of the first ones, to avoid the need for the class prefix.
That should also make Drupal happy :)
Commits
-------
c2e75ff changed the arguments of generateKey
0157315 deprecated Twig_Environment::getTemplateClassPrefix
This PR was merged into the 1.x branch.
Discussion
----------
added enabled extension names in the generated template class names
The generated template class names now take into account enabled extensions.
fixes#1742
Commits
-------
550a384 added enabled extension names in the generated template class names
This PR was merged into the 1.x branch.
Discussion
----------
no need to call setTimezone on a current date
Avoiding unnecessary method calls.
- When retrieving the current time, there is no point changing the timezone from default to the specified timezone, e.g. if you just use twigs `date()` function.
- When dealing with timestamps, the initial timezone is irrelevant as well since unix timstamps are always in GMT.
Commits
-------
163f42e no need to call setTimezone on a current date
This PR was merged into the 1.x branch.
Discussion
----------
Fix inlining of sources with CRLF
Commits
-------
7e666cb Fix inlining of sources with CRLF
This PR was merged into the 1.x branch.
Discussion
----------
Extracted the filesystem cache to its own class
Twig caches the compiled PHP classes on the filesystem. This is **always** the best strategy as it allows Twig to automatically benefit from PHP opcache/APC. But overriding how the classes are stored on the filesystem is difficult with the current way, so this PR proposes to extract this logic to its own class (that should allow Drupal to stop copy/pasting some Twig code and accessing private code - see #1811).
This PR also unifies the no-cache feature by extracting it to its own class as well.
BC is kept and the `false` and `$dir` caching strategies are still supported.
The `Twig_Cache_Interface` can be used to create other cache classes, but that's not documented and should only be used with extreme care (performance-wise). It means that Twig itself will **never** ship with other implementations like Memcache, Redis, whatever storage is hype nowadays. This should fix#1421 (this PR builds on top of it), #1573, #1415, #741, #728.
Commits
-------
cacfb06 added a cache interface for templates
04cc7e4 Implemented filesystem cache, one and only (see #1415)
This PR was merged into the 1.x branch.
Discussion
----------
Add $template->getSource()
Now that we have the source inlined, we should provide a way to get it. This also make it possible to feature-test if the source is available for backward/forward compat.
Commits
-------
de86850 Add $template->getSource()
This PR was merged into the 1.x branch.
Discussion
----------
removed code that supports obsolete versions of PHP
Commits
-------
33917e8 removed code that supports obsolete versions of PHP
This PR was submitted for the master branch but it was merged into the 1.x branch instead (closes#1807).
Discussion
----------
Inline original source code in compiled templates
For introspection purposes (e.g. instead of https://github.com/symfony/symfony/pull/15653) it is sometimes useful to be able to retrieve the original template source code.
I propose to inline it commented after the compiled class declaration.
This creates no memory nor cpu overhead while still allowing to get the source with very simple parsing logic.
Commits
-------
c9fb373 Inline original source code in compiled templates
This PR was merged into the 1.x branch.
Discussion
----------
Traversable support for 'replace', 'merge' and 'sort'
Add traversable support to:
* replace
* merge
* sort
Other changes:
* Removes some not need checks
* ~~Make unit test skip if it cannot write to cache because of the user running the test~~
* Tests added for traversable support
* Doc updates
Deprecating:
I think the undocumented (and multibyte not supported) use of `replace(string, string)` can be removed in Twig 2.0.
Adding MB support and documentation of the feature was turned down (https://github.com/twigphp/Twig/pull/1618)
However removing it is a BC break (https://github.com/twigphp/Twig/pull/1445#issuecomment-48746926)
Commits
-------
2a17303 Mark test skipped if cannot write to cache directory.
This PR was merged into the 1.x branch.
Discussion
----------
Fix variable names for the deprecation triggering code
Closes https://github.com/twigphp/Twig/issues/1800
Commits
-------
dd446c0 Fix variable names for the deprecation triggering code
This PR was merged into the 1.x branch.
Discussion
----------
fix escaping strategy detection based on filename
Fixessymfony/symfony#15095
It previously excluded any fileextension (not just `.twig`) which is pretty wrong.
Commits
-------
e403363 fix escaping strategy detection based on filename
This PR was squashed before being merged into the 1.x branch (closes#1796).
Discussion
----------
OPcache support fix
According this recipe http://twig.sensiolabs.org/doc/recipes.html#refreshing-modified-templates-when-opcache-or-apc-is-enabled when using OPcache:
```
class Twig_Environment_APC extends Twig_Environment
{
protected function writeCacheFile($file, $content)
{
parent::writeCacheFile($file, $content);
// Compile cached file into bytecode cache
if (extension_loaded('Zend OPcache') && ini_get('opcache.enable')) {
opcache_compile_file($file);
} elseif (extension_loaded('apc') && ini_get('apc.enabled')) {
apc_compile_file($file);
}
}
}
```
it takes an error:
```
Cannot redeclare class __TwigTemplate_12e7606b10ee267fa4174f660f86451aed936cc5680300a6442092f337c910cf
```
This is due to fact that the function ```opcache_compile_file($file)``` executes the file. But it should not do so in accordance with the documentation: http://php.net/manual/en/function.opcache-compile-file.php
There is a bug report: https://bugs.php.net/bug.php?id=66066 (since 2013 👎).
This patch prevents reexecution of the compiled template.
Commits
-------
2c4af24 OPcache support fix