From a7c8b0827018437de2a93ea9fe8211c080dc1bd1 Mon Sep 17 00:00:00 2001 From: Andrej Hudec Date: Thu, 11 May 2017 12:36:01 +0200 Subject: [PATCH] Fix generating template name in createTemplate() method Before this change the name for the template was generated randomly based on uniqid(mt_rand()). It generated new file whenever the template was loaded as string using the `template_from_string` even the template was the same. The generated file wasn't used anymore. Now the cache file is generated by the content of template so using the `template_from_string` is faster and doesn't pollute the cache folder with unneeded files. --- lib/Twig/Environment.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Twig/Environment.php b/lib/Twig/Environment.php index 51ffc53fed..d75a425685 100644 --- a/lib/Twig/Environment.php +++ b/lib/Twig/Environment.php @@ -489,7 +489,7 @@ public function loadTemplate($name, $index = null) */ public function createTemplate($template) { - $name = sprintf('__string_template__%s', hash('sha256', uniqid(mt_rand(), true), false)); + $name = sprintf('__string_template__%s', hash('sha256', $template, false)); $loader = new Twig_Loader_Chain(array( new Twig_Loader_Array(array($name => $template)),