simplified some code

This commit is contained in:
Fabien Potencier 2010-08-12 21:58:19 +02:00
parent 84446fe0ec
commit b514d767ef
3 changed files with 13 additions and 38 deletions

View File

@ -246,21 +246,12 @@ class Router implements RouterInterface
protected function writeCacheFile($file, $content)
{
$tmpFile = tempnam(dirname($file), basename($file));
if (!$fp = @fopen($tmpFile, 'wb')) {
throw new \RuntimeException(sprintf('Failed to write cache file "%s".', $tmpFile));
if (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $file)) {
chmod($file, 0644);
return;
}
@fwrite($fp, $content);
@fclose($fp);
if ($content != file_get_contents($tmpFile)) {
throw new \RuntimeException(sprintf('Failed to write cache file "%s" (cache corrupted).', $tmpFile));
}
if (!@rename($tmpFile, $file)) {
throw new \RuntimeException(sprintf('Failed to write cache file "%s".', $file));
}
chmod($file, 0644);
throw new \RuntimeException(sprintf('Failed to write cache file "%s".', $file));
}
}

View File

@ -94,20 +94,12 @@ class ClassCollectionLoader
static protected function writeCacheFile($file, $content)
{
$tmpFile = tempnam(dirname($file), basename($file));
if (!$fp = @fopen($tmpFile, 'wb')) {
die(sprintf('Failed to write cache file "%s".', $tmpFile));
}
@fwrite($fp, $content);
@fclose($fp);
if (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $file)) {
chmod($file, 0644);
if ($content != file_get_contents($tmpFile)) {
die(sprintf('Failed to write cache file "%s" (cache corrupted).', $tmpFile));
return;
}
if (!@rename($tmpFile, $file)) {
throw new \RuntimeException(sprintf('Failed to write cache file "%s".', $file));
}
chmod($file, 0644);
throw new \RuntimeException(sprintf('Failed to write cache file "%s".', $file));
}
}

View File

@ -462,21 +462,13 @@ abstract class Kernel implements HttpKernelInterface, \Serializable
protected function writeCacheFile($file, $content)
{
$tmpFile = tempnam(dirname($file), basename($file));
if (!$fp = @fopen($tmpFile, 'wb')) {
die(sprintf('Failed to write cache file "%s".', $tmpFile));
}
@fwrite($fp, $content);
@fclose($fp);
if (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $file)) {
chmod($file, 0644);
if ($content != file_get_contents($tmpFile)) {
die(sprintf('Failed to write cache file "%s" (cache corrupted).', $tmpFile));
return;
}
if (!@rename($tmpFile, $file)) {
throw new \RuntimeException(sprintf('Failed to write cache file "%s".', $file));
}
chmod($file, 0644);
throw new \RuntimeException(sprintf('Failed to write cache file "%s".', $file));
}
public function serialize()