From a834dbb22457ffad95977670fe78fe2973919eb3 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 4 Aug 2013 15:09:59 +0200 Subject: [PATCH] fixed template_from_string() cache side-effects --- lib/Twig/Extension/StringLoader.php | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/Twig/Extension/StringLoader.php b/lib/Twig/Extension/StringLoader.php index a1cef87..5e1a60d 100644 --- a/lib/Twig/Extension/StringLoader.php +++ b/lib/Twig/Extension/StringLoader.php @@ -43,14 +43,16 @@ class Twig_Extension_StringLoader extends Twig_Extension */ function twig_template_from_string(Twig_Environment $env, $template) { + $name = sprintf('__string_template__%s', hash('sha256', uniqid(mt_rand(), true), false)); + $loader = new Twig_Loader_Chain(array( - new Twig_Loader_Array(array('__string_template__' => $template)), + new Twig_Loader_Array(array($name => $template)), $current = $env->getLoader(), )); $env->setLoader($loader); try { - $template = $env->loadTemplate('__string_template__'); + $template = $env->loadTemplate($name); } catch (Exception $e) { $env->setLoader($current); -- 1.7.2.5