소스 검색

simplified some code

Fabien Potencier 15 년 전
부모
커밋
b514d767ef
3개의 변경된 파일12개의 추가작업 그리고 37개의 파일을 삭제
  1. 4 13
      src/Symfony/Components/Routing/Router.php
  2. 4 12
      src/Symfony/Framework/ClassCollectionLoader.php
  3. 4 12
      src/Symfony/Framework/Kernel.php

+ 4 - 13
src/Symfony/Components/Routing/Router.php

@@ -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));
-        }
-
-        @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 (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $file)) {
+            chmod($file, 0644);
 
-        if (!@rename($tmpFile, $file)) {
-            throw new \RuntimeException(sprintf('Failed to write cache file "%s".', $file));
+            return;
         }
 
-        chmod($file, 0644);
+        throw new \RuntimeException(sprintf('Failed to write cache file "%s".', $file));
     }
 }

+ 4 - 12
src/Symfony/Framework/ClassCollectionLoader.php

@@ -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 ($content != file_get_contents($tmpFile)) {
-            die(sprintf('Failed to write cache file "%s" (cache corrupted).', $tmpFile));
-        }
+        if (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $file)) {
+            chmod($file, 0644);
 
-        if (!@rename($tmpFile, $file)) {
-            throw new \RuntimeException(sprintf('Failed to write cache file "%s".', $file));
+            return;
         }
 
-        chmod($file, 0644);
+        throw new \RuntimeException(sprintf('Failed to write cache file "%s".', $file));
     }
 }

+ 4 - 12
src/Symfony/Framework/Kernel.php

@@ -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 ($content != file_get_contents($tmpFile)) {
-            die(sprintf('Failed to write cache file "%s" (cache corrupted).', $tmpFile));
-        }
+        if (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $file)) {
+            chmod($file, 0644);
 
-        if (!@rename($tmpFile, $file)) {
-            throw new \RuntimeException(sprintf('Failed to write cache file "%s".', $file));
+            return;
         }
 
-        chmod($file, 0644);
+        throw new \RuntimeException(sprintf('Failed to write cache file "%s".', $file));
     }
 
     public function serialize()