avoid writing template file if an error occurs
authorfabien <fabien@93ef8e89-cb99-4229-a87c-7fa0fa45744b>
Thu, 15 Oct 2009 06:06:17 +0000 (06:06 +0000)
committerfabien <fabien@93ef8e89-cb99-4229-a87c-7fa0fa45744b>
Thu, 15 Oct 2009 06:06:17 +0000 (06:06 +0000)
git-svn-id: http://svn.twig-project.org/trunk@56 93ef8e89-cb99-4229-a87c-7fa0fa45744b

CHANGELOG
lib/Twig/Loader.php

index cc1dd19..2142cc2 100644 (file)
--- 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
index 57ef9c4..cc75aa0 100644 (file)
@@ -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;