浏览代码

[FrameworkBundle] removed clearDir() method in some commands (use Filesystem::remove() instead)

Fabien Potencier 14 年之前
父节点
当前提交
b00a903858

+ 2 - 4
src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php

@@ -63,13 +63,10 @@ EOF
             throw new \RuntimeException(sprintf('Unable to write %s directory', $this->realCacheDir));
         }
 
-        $this->clearDir($oldCacheDir);
-
         if (!$input->getOption('warmup')) {
             $output->writeln('Clear cache');
 
             rename($realCacheDir, $oldCacheDir);
-            $this->clearDir($oldCacheDir);
         } else {
             parent::execute($input, $output);
 
@@ -78,7 +75,8 @@ EOF
             rename($this->kernelTmp->getCacheDir(), $realCacheDir);
 
             $output->writeln('Clear the old cache');
-            $this->clearDir($oldCacheDir);
         }
+
+        $this->container->get('filesystem')->remove($oldCacheDir);
     }
 }

+ 1 - 36
src/Symfony/Bundle/FrameworkBundle/Command/CacheWarmupCommand.php

@@ -73,7 +73,7 @@ EOF
                 $this->cacheDir
             );
 
-            $this->clearDir($this->kernelTmp->getCacheDir());
+            $this->container->get('filesystem')->remove($this->kernelTmp->getCacheDir());
 
             $this->kernelTmp->boot();
             unlink($this->kernelTmp->getCacheDir().DIRECTORY_SEPARATOR.$this->kernelTmp->getContainerClass().'.php');
@@ -88,39 +88,4 @@ EOF
         $warmer->enableOptionalWarmers();
         $warmer->warmUp($container->getParameter('kernel.cache_dir'));
     }
-
-    protected function clearDir($dir)
-    {
-        if (is_dir($dir)) {
-            $finder = new Finder();
-            $files  = $finder
-                ->in($dir)
-                ->getIterator()
-            ;
-
-            $array = iterator_to_array($files);
-
-            foreach (array_reverse($array) as $file) {
-                if ($file->isFile()) {
-                    if (!is_writable($file->getPathname())) {
-                        throw new \RuntimeException(sprintf('Unable to delete %s file', $file->getPathname()));
-                    }
-
-                    unlink($file->getPathname());
-                } else {
-                    if (!is_writable($file->getPathname())) {
-                        throw new \RuntimeException(sprintf('Unable to delete %s directory', $file->getPathname()));
-                    }
-
-                    rmdir($file->getPathname());
-                }
-            }
-
-            if (!is_writable($dir)) {
-                throw new \RuntimeException(sprintf('Unable to delete %s directory', $dir));
-            }
-
-            rmdir($dir);
-        }
-    }
 }