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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | <?php /** * GitPHP ProjectListScmManager * * Lists all projects in an scm-manager config file * * @author Christopher Han <xiphux@gmail.com> * @copyright Copyright (c) 2011 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'); /** * ProjectListScmManager class * * @package GitPHP * @subpackage Git */ class GitPHP_ProjectListScmManager extends GitPHP_ProjectListBase { /** * __construct * * constructor * * @param string $projectFile file to read * @throws Exception if parameter is not a readable file * @access public */ public function __construct($projectFile) { if (!(is_string($projectFile) && is_file($projectFile))) { throw new Exception(sprintf(__('%1$s is not a file'), $projectFile)); } $this->projectConfig = $projectFile; parent::__construct(); } /** * PopulateProjects * * Populates the internal list of projects * * @access protected * @throws Exception if file cannot be read */ protected function PopulateProjects() { $projectRoot = GitPHP_Util::AddSlash(GitPHP_Config::GetInstance()->GetValue('projectroot')); $use_errors = libxml_use_internal_errors(true); $xml = simplexml_load_file($this->projectConfig); libxml_clear_errors(); libxml_use_internal_errors($use_errors); if (!$xml) { throw new Exception(sprintf('Could not load SCM manager config %1$s', $this->projectConfig)); } foreach ($xml->repositories->repository as $repository) { if ($repository->type != 'git') { GitPHP_Log::GetInstance()->Log(sprintf('%1$s is not a git project', $repository->name)); continue; } if ($repository->public != 'true') { GitPHP_Log::GetInstance()->Log(sprintf('%1$s is not public', $repository->name)); continue; } $projName = trim($repository->name); if (empty($projName)) continue; if (is_file($projectRoot . $projName . '/HEAD')) { try { $projObj = new GitPHP_Project($projectRoot, $projName); $projOwner = trim($repository->contact); if (!empty($projOwner)) { $projObj->SetOwner($projOwner); } $projDesc = trim($repository->description); if (!empty($projDesc)) { $projObj->SetDescription($projDesc); } $this->projects[$projName] = $projObj; } catch (Exception $e) { GitPHP_Log::GetInstance()->Log($e->message); } } else { GitPHP_Log::GetInstance()->Log(sprintf('%1$s is not a git project', $projName)); } } } /** * IsSCMManager * * Tests if this file is an SCM manager config file * * @access protected * @returns true if file is an SCM manager config */ public static function IsSCMManager($file) { if (empty($file)) return false; if (!(is_string($file) && is_file($file))) return false; $use_errors = libxml_use_internal_errors(true); $xml = simplexml_load_file($file); libxml_clear_errors(); libxml_use_internal_errors($use_errors); if (!$xml) return false; if ($xml->getName() !== 'repository-db') return false; return true; } } |