1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | <?php /** * GitPHP ProjectListDirectory * * Lists all projects in a given directory * * @author Christopher Han <xiphux@gmail.com> * @copyright Copyright (c) 2010 Christopher Han * @package GitPHP * @subpackage Git */ require_once(GITPHP_INCLUDEDIR . 'Config.class.php'); require_once(GITPHP_GITOBJECTDIR . 'ProjectListBase.class.php'); require_once(GITPHP_GITOBJECTDIR . 'Project.class.php'); /** * ProjectListDirectory class * * @package GitPHP * @subpackage Git */ class GitPHP_ProjectListDirectory extends GitPHP_ProjectListBase { /** * projectDir * * Stores projectlist directory internally * * @access protected */ protected $projectDir; /** * __construct * * constructor * * @param string $projectDir directory to search * @throws Exception if parameter is not a directory * @access public */ public function __construct($projectDir) { if (!is_dir($projectDir)) { throw new Exception(sprintf(__('%1$s is not a directory'), $projectDir)); } $this->projectDir = GitPHP_Util::AddSlash($projectDir); parent::__construct(); } /** * PopulateProjects * * Populates the internal list of projects * * @access protected */ protected function PopulateProjects() { $this->RecurseDir($this->projectDir); } /** * RecurseDir * * Recursively searches for projects * * @param string $dir directory to recurse into */ private function RecurseDir($dir) { if (!is_dir($dir)) return; GitPHP_Log::GetInstance()->Log(sprintf('Searching directory %1$s', $dir)); if ($dh = opendir($dir)) { $trimlen = strlen($this->projectDir) + 1; while (($file = readdir($dh)) !== false) { $fullPath = $dir . '/' . $file; if ((strpos($file, '.') !== 0) && is_dir($fullPath)) { if (is_file($fullPath . '/HEAD')) { GitPHP_Log::GetInstance()->Log(sprintf('Found project %1$s', $fullPath)); $projectPath = substr($fullPath, $trimlen); try { $proj = new GitPHP_Project($this->projectDir, $projectPath); $proj->SetCategory(trim(substr($dir, strlen($this->projectDir)), '/')); if ((!GitPHP_Config::GetInstance()->GetValue('exportedonly', false)) || $proj->GetDaemonEnabled()) { $this->projects[$projectPath] = $proj; } } catch (Exception $e) { GitPHP_Log::GetInstance()->Log($e->message); } } else { $this->RecurseDir($fullPath); } } else { GitPHP_Log::GetInstance()->Log(sprintf('Skipping %1$s', $fullPath)); } } closedir($dh); } } } |