Skip to content

Commit

Permalink
bug #2465 Fix generating template name in createTemplate() method (pu…
Browse files Browse the repository at this point in the history
…lzarraider)

This PR was merged into the 1.x branch.

Discussion
----------

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` function 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 much faster and doesn't pollute the cache folder with unneeded files.

Commits
-------

a7c8b08 Fix generating template name in createTemplate() method
  • Loading branch information
fabpot committed May 11, 2017
2 parents 324ab87 + a7c8b08 commit cf93147
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Twig/Environment.php
Expand Up @@ -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)),
Expand Down

0 comments on commit cf93147

Please sign in to comment.