Skip to content

Commit

Permalink
avoid writing template file if an error occurs
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.twig-project.org/trunk@56 93ef8e89-cb99-4229-a87c-7fa0fa45744b
  • Loading branch information
fabien committed Oct 15, 2009
1 parent d11a330 commit 6f535bc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions 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
Expand Down
10 changes: 5 additions & 5 deletions lib/Twig/Loader.php
Expand Up @@ -78,19 +78,19 @@ public function load($name)
$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;
Expand Down

0 comments on commit 6f535bc

Please sign in to comment.