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.
This commit is contained in:
Andrej Hudec
2017-05-11 12:36:01 +02:00
committed by GitHub
parent 324ab87d2f
commit a7c8b08270
+1 -1
View File
@@ -489,7 +489,7 @@ class Twig_Environment
*/
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)),