From e6ae0d0caa5925c5ced5430165469b2b4bdb0b79 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Thu, 13 Aug 2015 10:32:03 +0200 Subject: [PATCH 1/3] Remove broken code Trait templates can only be constant expression nodes, so fixing the broken is not actually needed and it can be removed. --- lib/Twig/Node/Module.php | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/lib/Twig/Node/Module.php b/lib/Twig/Node/Module.php index 327b5e6d6..1bc4fea6d 100644 --- a/lib/Twig/Node/Module.php +++ b/lib/Twig/Node/Module.php @@ -402,22 +402,7 @@ class Twig_Node_Module extends Twig_Node ->raw(");\n") ; } else { - $compiler - ->write(sprintf('%s = ', $var)) - ->subcompile($node) - ->raw(";\n") - ->write(sprintf('if (!%s', $var)) - ->raw(" instanceof Twig_Template) {\n") - ->indent() - ->write(sprintf('%s = $this->loadTemplate(%s') - ->raw(', ') - ->repr($compiler->getFilename()) - ->raw(', ') - ->repr($node->getLine()) - ->raw(");\n", $var, $var)) - ->outdent() - ->write("}\n") - ; + throw new LogicException('Trait templates can only be constant nodes'); } } } From 1f3fb9a1785ff07227c0328bd635409ea6fb058b Mon Sep 17 00:00:00 2001 From: Alexander Vasilyev Date: Thu, 13 Aug 2015 11:01:08 +0300 Subject: [PATCH 2/3] [doc/recipes] Added OPcache support --- doc/recipes.rst | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/doc/recipes.rst b/doc/recipes.rst index 86cede630..7a8af89a8 100644 --- a/doc/recipes.rst +++ b/doc/recipes.rst @@ -274,12 +274,13 @@ If you iterate over a set of files, you can pass the filename to the is enforced during template rendering (as Twig needs the context for some checks like allowed methods on objects). -Refreshing modified Templates when APC is enabled and apc.stat = 0 ------------------------------------------------------------------- +Refreshing modified Templates when OPcache or APC is enabled +------------------------------------------------------------ -When using APC with ``apc.stat`` set to ``0`` and Twig cache enabled, clearing -the template cache won't update the APC cache. To get around this, one can -extend ``Twig_Environment`` and force the update of the APC cache when Twig +When using OPcache with ``opcache.validate_timestamps`` set to ``0`` or +APC with ``apc.stat`` set to ``0`` and Twig cache enabled, clearing +the template cache won't update the cache. To get around this, one can +extend ``Twig_Environment`` and force the update of the cache when Twig rewrites the cache:: class Twig_Environment_APC extends Twig_Environment @@ -288,8 +289,17 @@ rewrites the cache:: { parent::writeCacheFile($file, $content); - // Compile cached file into bytecode cache - apc_compile_file($file); + // OPcache enabled by default sinse PHP 5.5 + if (extension_loaded('Zend OPcache') && ini_get('opcache.enable')) { + // Compile cached file into OPcache bytecode cache + opcache_compile_file($file); + + // For PHP 5.4 or less + } else if (extension_loaded('apc') && ini_get('apc.enabled')) { + // Compile cached file into APC bytecode cache + apc_compile_file($file); + } + } } From af129b2f75fbb7b9c23f4dcb6f6c77a90769bd47 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 13 Aug 2015 14:50:40 +0200 Subject: [PATCH 3/3] fixed typos and CS --- doc/recipes.rst | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/doc/recipes.rst b/doc/recipes.rst index 7a8af89a8..22d44f912 100644 --- a/doc/recipes.rst +++ b/doc/recipes.rst @@ -277,11 +277,11 @@ If you iterate over a set of files, you can pass the filename to the Refreshing modified Templates when OPcache or APC is enabled ------------------------------------------------------------ -When using OPcache with ``opcache.validate_timestamps`` set to ``0`` or -APC with ``apc.stat`` set to ``0`` and Twig cache enabled, clearing -the template cache won't update the cache. To get around this, one can -extend ``Twig_Environment`` and force the update of the cache when Twig -rewrites the cache:: +When using OPcache with ``opcache.validate_timestamps`` set to ``0`` or APC +with ``apc.stat`` set to ``0`` and Twig cache enabled, clearing the template +cache won't update the cache. To get around this, one can extend +``Twig_Environment`` and force the update of the cache when Twig rewrites the +cache:: class Twig_Environment_APC extends Twig_Environment { @@ -289,17 +289,12 @@ rewrites the cache:: { parent::writeCacheFile($file, $content); - // OPcache enabled by default sinse PHP 5.5 + // Compile cached file into bytecode cache if (extension_loaded('Zend OPcache') && ini_get('opcache.enable')) { - // Compile cached file into OPcache bytecode cache opcache_compile_file($file); - - // For PHP 5.4 or less - } else if (extension_loaded('apc') && ini_get('apc.enabled')) { - // Compile cached file into APC bytecode cache + } elseif (extension_loaded('apc') && ini_get('apc.enabled')) { apc_compile_file($file); } - } }