From 6f535bc859c08972664a8f48ea31bc862e52c00e Mon Sep 17 00:00:00 2001 From: fabien Date: Thu, 15 Oct 2009 06:06:17 +0000 Subject: [PATCH] avoid writing template file if an error occurs git-svn-id: http://svn.twig-project.org/trunk@56 93ef8e89-cb99-4229-a87c-7fa0fa45744b --- CHANGELOG | 1 + lib/Twig/Loader.php | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index cc1dd19..2142cc2 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ * 0.9.2-DEV + * avoid writing template file if an error occurs * added $ escaping when outputting raw strings * enhanced some error messages to ease debugging * fixed empty cache files when the template contains an error diff --git a/lib/Twig/Loader.php b/lib/Twig/Loader.php index 57ef9c4..cc75aa0 100644 --- a/lib/Twig/Loader.php +++ b/lib/Twig/Loader.php @@ -78,19 +78,19 @@ abstract class Twig_Loader implements Twig_LoaderInterface $cache = $this->getCacheFilename($name); if (!file_exists($cache) || false === $mtime || ($this->autoReload && (filemtime($cache) < $mtime))) { + // compile first to avoid empty files when an Exception occurs + $content = $this->compile($template, $name); + $fp = @fopen($cache, 'wb'); if (!$fp) { - $this->evalString($template, $name); + eval('?>'.$content); return $cls; } - - // compile first to avoid empty files when an Exception occurs - $content = $this->compile($template, $name); + fclose($fp); file_put_contents($cache, $content); - fclose($fp); } require_once $cache; -- 1.7.2.5