Move listdir to utility class
Move listdir to utility class

--- a/include/Util.class.php
+++ b/include/Util.class.php
@@ -148,5 +148,37 @@
 		return null;
 	}
 
+	/**
+	 * ListDir
+	 *
+	 * Recurses into a directory and lists files inside
+	 *
+	 * @access public
+	 * @static
+	 * @param string $dir directory
+	 * @return array array of filenames
+	 */
+	public static function ListDir($dir)
+	{
+		$files = array();
+		if ($dh = opendir($dir)) {
+			while (($file = readdir($dh)) !== false) {
+				if (($file == '.') || ($file == '..')) {
+					continue;
+				}
+				$fullFile = $dir . '/' . $file;
+				if (is_dir($fullFile)) {
+					$subFiles = GitPHP_Util::ListDir($fullFile);
+					if (count($subFiles) > 0) {
+						$files = array_merge($files, $subFiles);
+					}
+				} else {
+					$files[] = $fullFile;
+				}
+			}
+		}
+		return $files;
+	}
+
 }
 

--- a/include/git/Project.class.php
+++ b/include/git/Project.class.php
@@ -1113,7 +1113,7 @@
 		$pathlen = strlen($this->GetPath()) + 1;
 
 		// read loose heads
-		$heads = $this->ListDir($this->GetPath() . '/refs/heads');
+		$heads = GitPHP_Util::ListDir($this->GetPath() . '/refs/heads');
 		for ($i = 0; $i < count($heads); $i++) {
 			$key = trim(substr($heads[$i], $pathlen), "/\\");
 			$head = substr($key, strlen('refs/heads/'));
@@ -1129,7 +1129,7 @@
 		}
 
 		// read loose tags
-		$tags = $this->ListDir($this->GetPath() . '/refs/tags');
+		$tags = GitPHP_Util::ListDir($this->GetPath() . '/refs/tags');
 		for ($i = 0; $i < count($tags); $i++) {
 			$key = trim(substr($tags[$i], $pathlen), "/\\");
 			$tag = substr($key, strlen('refs/tags/'));
@@ -1179,37 +1179,6 @@
 				}
 			}
 		}
-	}
-
-	/**
-	 * ListDir
-	 *
-	 * Recurses into a directory and lists files inside
-	 *
-	 * @access private
-	 * @param string $dir directory
-	 * @return array array of filenames
-	 */
-	private function ListDir($dir)
-	{
-		$files = array();
-		if ($dh = opendir($dir)) {
-			while (($file = readdir($dh)) !== false) {
-				if (($file == '.') || ($file == '..')) {
-					continue;
-				}
-				$fullFile = $dir . '/' . $file;
-				if (is_dir($fullFile)) {
-					$subFiles = $this->ListDir($fullFile);
-					if (count($subFiles) > 0) {
-						$files = array_merge($files, $subFiles);
-					}
-				} else {
-					$files[] = $fullFile;
-				}
-			}
-		}
-		return $files;
 	}
 
 /*}}}2*/

comments