Przeglądaj źródła

Avoid using GlobIterator since it seems to trip up open_basedir restrictions, fixes #204

Jordi Boggiano 12 lat temu
rodzic
commit
875ada786b
1 zmienionych plików z 7 dodań i 9 usunięć
  1. 7 9
      src/Monolog/Handler/RotatingFileHandler.php

+ 7 - 9
src/Monolog/Handler/RotatingFileHandler.php

@@ -93,22 +93,20 @@ class RotatingFileHandler extends StreamHandler
         if (!empty($fileInfo['extension'])) {
             $glob .= '.'.$fileInfo['extension'];
         }
-        $iterator = new \GlobIterator($glob);
-        $count = $iterator->count();
-        if ($this->maxFiles >= $count) {
+        $logFiles = glob($glob);
+        if ($this->maxFiles >= count($logFiles)) {
             // no files to remove
             return;
         }
 
         // Sorting the files by name to remove the older ones
-        $array = iterator_to_array($iterator);
-        usort($array, function($a, $b) {
-            return strcmp($b->getFilename(), $a->getFilename());
+        usort($logFiles, function($a, $b) {
+            return strcmp($b, $a);
         });
 
-        foreach (array_slice($array, $this->maxFiles) as $file) {
-            if ($file->isWritable()) {
-                unlink($file->getRealPath());
+        foreach (array_slice($logFiles, $this->maxFiles) as $file) {
+            if (is_writable($file)) {
+                unlink($file);
             }
         }
     }