فهرست منبع

Merge remote branch 'stealth35/use_filesystemiterator'

* stealth35/use_filesystemiterator:
  simplify folders deletion
  work with Traversable
  added FilesystemIterator namespace
  tab to spaces
  use FilesytemIterator insteed opendir
Fabien Potencier 14 سال پیش
والد
کامیت
3553ed89d4
1فایلهای تغییر یافته به همراه6 افزوده شده و 9 حذف شده
  1. 6 9
      src/Symfony/Bundle/FrameworkBundle/Util/Filesystem.php

+ 6 - 9
src/Symfony/Bundle/FrameworkBundle/Util/Filesystem.php

@@ -91,9 +91,13 @@ class Filesystem
      */
     public function remove($files)
     {
-        if (!is_array($files)) {
+        if (!is_array($files) && !$files instanceof \Traversable) {
             $files = array($files);
         }
+        
+        if($files instanceof \Traversable) {
+            $files = iterator_to_array($files);
+        }
 
         $files = array_reverse($files);
         foreach ($files as $file) {
@@ -102,14 +106,7 @@ class Filesystem
             }
 
             if (is_dir($file) && !is_link($file)) {
-                $fp = opendir($file);
-                while (false !== $item = readdir($fp)) {
-                    if (!in_array($item, array('.', '..'))) {
-                        $this->remove($file.'/'.$item);
-                    }
-                }
-                closedir($fp);
-
+                $this->remove(new \FilesystemIterator($file));
                 rmdir($file);
             } else {
                 unlink($file);