Forgot that the exception message property was protected
Forgot that the exception message property was protected

<?php <?php
/** /**
* GitPHP ProjectListArray * GitPHP ProjectListArray
* *
* Lists all projects in a multidimensional array * Lists all projects in a multidimensional array
* *
* @author Christopher Han <xiphux@gmail.com> * @author Christopher Han <xiphux@gmail.com>
* @copyright Copyright (c) 2010 Christopher Han * @copyright Copyright (c) 2010 Christopher Han
* @package GitPHP * @package GitPHP
* @subpackage Git * @subpackage Git
*/ */
   
require_once(GITPHP_GITOBJECTDIR . 'ProjectListBase.class.php'); require_once(GITPHP_GITOBJECTDIR . 'ProjectListBase.class.php');
require_once(GITPHP_GITOBJECTDIR . 'Project.class.php'); require_once(GITPHP_GITOBJECTDIR . 'Project.class.php');
   
/** /**
* ProjectListArray class * ProjectListArray class
* *
* @package GitPHP * @package GitPHP
* @subpackage Git * @subpackage Git
*/ */
class GitPHP_ProjectListArray extends GitPHP_ProjectListBase class GitPHP_ProjectListArray extends GitPHP_ProjectListBase
{ {
   
/** /**
* __construct * __construct
* *
* constructor * constructor
* *
* @param mixed $projectArray array to read * @param mixed $projectArray array to read
* @throws Exception if parameter is not an array * @throws Exception if parameter is not an array
* @access public * @access public
*/ */
public function __construct($projectArray) public function __construct($projectArray)
{ {
if (!is_array($projectArray)) { if (!is_array($projectArray)) {
throw new Exception('An array of projects is required'); throw new Exception('An array of projects is required');
} }
   
$this->projectConfig = $projectArray; $this->projectConfig = $projectArray;
   
parent::__construct(); parent::__construct();
} }
   
/** /**
* PopulateProjects * PopulateProjects
* *
* Populates the internal list of projects * Populates the internal list of projects
* *
* @access protected * @access protected
* @throws Exception if file cannot be read * @throws Exception if file cannot be read
*/ */
protected function PopulateProjects() protected function PopulateProjects()
{ {
$projectRoot = GitPHP_Util::AddSlash(GitPHP_Config::GetInstance()->GetValue('projectroot')); $projectRoot = GitPHP_Util::AddSlash(GitPHP_Config::GetInstance()->GetValue('projectroot'));
   
foreach ($this->projectConfig as $proj => $projData) { foreach ($this->projectConfig as $proj => $projData) {
try { try {
if (is_string($projData)) { if (is_string($projData)) {
// Just flat array of project paths // Just flat array of project paths
$projObj = new GitPHP_Project($projectRoot, $projData); $projObj = new GitPHP_Project($projectRoot, $projData);
$this->projects[$projData] = $projObj; $this->projects[$projData] = $projObj;
} else if (is_array($projData)) { } else if (is_array($projData)) {
if (is_string($proj) && !empty($proj)) { if (is_string($proj) && !empty($proj)) {
// Project key pointing to data array // Project key pointing to data array
$projObj = new GitPHP_Project($projectRoot, $proj); $projObj = new GitPHP_Project($projectRoot, $proj);
$this->projects[$proj] = $projObj; $this->projects[$proj] = $projObj;
$this->ApplyProjectSettings($proj, $projData); $this->ApplyProjectSettings($proj, $projData);
} else if (isset($projData['project'])) { } else if (isset($projData['project'])) {
// List of data arrays with projects inside // List of data arrays with projects inside
$projObj = new GitPHP_Project($projectRoot, $projData['project']); $projObj = new GitPHP_Project($projectRoot, $projData['project']);
$this->projects[$projData['project']] = $projObj; $this->projects[$projData['project']] = $projObj;
$this->ApplyProjectSettings(null, $projData); $this->ApplyProjectSettings(null, $projData);
} }
} }
} catch (Exception $e) { } catch (Exception $e) {
GitPHP_Log::GetInstance()->Log($e->message); GitPHP_Log::GetInstance()->Log($e->getMessage());
} }
} }
} }
   
} }
   
<?php <?php
/** /**
* GitPHP ProjectListArrayLegacy * GitPHP ProjectListArrayLegacy
* *
* Lists all projects in a multidimensional array * Lists all projects in a multidimensional array
* Legacy array format * Legacy array format
* *
* @author Christopher Han <xiphux@gmail.com> * @author Christopher Han <xiphux@gmail.com>
* @copyright Copyright (c) 2010 Christopher Han * @copyright Copyright (c) 2010 Christopher Han
* @package GitPHP * @package GitPHP
* @subpackage Git * @subpackage Git
*/ */
   
require_once(GITPHP_GITOBJECTDIR . 'ProjectListBase.class.php'); require_once(GITPHP_GITOBJECTDIR . 'ProjectListBase.class.php');
require_once(GITPHP_GITOBJECTDIR . 'Project.class.php'); require_once(GITPHP_GITOBJECTDIR . 'Project.class.php');
   
define('GITPHP_NO_CATEGORY', 'none'); define('GITPHP_NO_CATEGORY', 'none');
   
/** /**
* ProjectListArrayLegacy class * ProjectListArrayLegacy class
* *
* @package GitPHP * @package GitPHP
* @subpackage Git * @subpackage Git
*/ */
class GitPHP_ProjectListArrayLegacy extends GitPHP_ProjectListBase class GitPHP_ProjectListArrayLegacy extends GitPHP_ProjectListBase
{ {
   
/** /**
* __construct * __construct
* *
* constructor * constructor
* *
* @param mixed $projectArray array to read * @param mixed $projectArray array to read
* @throws Exception if parameter is not an array * @throws Exception if parameter is not an array
* @access public * @access public
*/ */
public function __construct($projectArray) public function __construct($projectArray)
{ {
if (!is_array($projectArray)) { if (!is_array($projectArray)) {
throw new Exception('An array of projects is required.'); throw new Exception('An array of projects is required.');
} }
   
$this->projectConfig = $projectArray; $this->projectConfig = $projectArray;
   
parent::__construct(); parent::__construct();
} }
   
/** /**
* PopulateProjects * PopulateProjects
* *
* Populates the internal list of projects * Populates the internal list of projects
* *
* @access protected * @access protected
* @throws Exception if file cannot be read * @throws Exception if file cannot be read
*/ */
protected function PopulateProjects() protected function PopulateProjects()
{ {
$projectRoot = GitPHP_Util::AddSlash(GitPHP_Config::GetInstance()->GetValue('projectroot')); $projectRoot = GitPHP_Util::AddSlash(GitPHP_Config::GetInstance()->GetValue('projectroot'));
   
foreach ($this->projectConfig as $cat => $plist) { foreach ($this->projectConfig as $cat => $plist) {
if (is_array($plist)) { if (is_array($plist)) {
foreach ($plist as $pname => $ppath) { foreach ($plist as $pname => $ppath) {
try { try {
$projObj = new GitPHP_Project($projectRoot, $ppath); $projObj = new GitPHP_Project($projectRoot, $ppath);
if ($cat != GITPHP_NO_CATEGORY) if ($cat != GITPHP_NO_CATEGORY)
$projObj->SetCategory($cat); $projObj->SetCategory($cat);
$this->projects[$ppath] = $projObj; $this->projects[$ppath] = $projObj;
} catch (Exception $e) { } catch (Exception $e) {
GitPHP_Log::GetInstance()->Log($e->message); GitPHP_Log::GetInstance()->Log($e->getMessage());
} }
} }
} }
} }
} }
   
} }
   
<?php <?php
/** /**
* GitPHP ProjectListDirectory * GitPHP ProjectListDirectory
* *
* Lists all projects in a given directory * Lists all projects in a given directory
* *
* @author Christopher Han <xiphux@gmail.com> * @author Christopher Han <xiphux@gmail.com>
* @copyright Copyright (c) 2010 Christopher Han * @copyright Copyright (c) 2010 Christopher Han
* @package GitPHP * @package GitPHP
* @subpackage Git * @subpackage Git
*/ */
   
require_once(GITPHP_INCLUDEDIR . 'Config.class.php'); require_once(GITPHP_INCLUDEDIR . 'Config.class.php');
require_once(GITPHP_GITOBJECTDIR . 'ProjectListBase.class.php'); require_once(GITPHP_GITOBJECTDIR . 'ProjectListBase.class.php');
require_once(GITPHP_GITOBJECTDIR . 'Project.class.php'); require_once(GITPHP_GITOBJECTDIR . 'Project.class.php');
   
/** /**
* ProjectListDirectory class * ProjectListDirectory class
* *
* @package GitPHP * @package GitPHP
* @subpackage Git * @subpackage Git
*/ */
class GitPHP_ProjectListDirectory extends GitPHP_ProjectListBase class GitPHP_ProjectListDirectory extends GitPHP_ProjectListBase
{ {
/** /**
* projectDir * projectDir
* *
* Stores projectlist directory internally * Stores projectlist directory internally
* *
* @access protected * @access protected
*/ */
protected $projectDir; protected $projectDir;
   
/** /**
* __construct * __construct
* *
* constructor * constructor
* *
* @param string $projectDir directory to search * @param string $projectDir directory to search
* @throws Exception if parameter is not a directory * @throws Exception if parameter is not a directory
* @access public * @access public
*/ */
public function __construct($projectDir) public function __construct($projectDir)
{ {
if (!is_dir($projectDir)) { if (!is_dir($projectDir)) {
throw new Exception(sprintf(__('%1$s is not a directory'), $projectDir)); throw new Exception(sprintf(__('%1$s is not a directory'), $projectDir));
} }
   
$this->projectDir = GitPHP_Util::AddSlash($projectDir); $this->projectDir = GitPHP_Util::AddSlash($projectDir);
   
parent::__construct(); parent::__construct();
} }
   
/** /**
* PopulateProjects * PopulateProjects
* *
* Populates the internal list of projects * Populates the internal list of projects
* *
* @access protected * @access protected
*/ */
protected function PopulateProjects() protected function PopulateProjects()
{ {
$this->RecurseDir($this->projectDir); $this->RecurseDir($this->projectDir);
} }
   
/** /**
* RecurseDir * RecurseDir
* *
* Recursively searches for projects * Recursively searches for projects
* *
* @param string $dir directory to recurse into * @param string $dir directory to recurse into
*/ */
private function RecurseDir($dir) private function RecurseDir($dir)
{ {
if (!is_dir($dir)) if (!is_dir($dir))
return; return;
   
GitPHP_Log::GetInstance()->Log(sprintf('Searching directory %1$s', $dir)); GitPHP_Log::GetInstance()->Log(sprintf('Searching directory %1$s', $dir));
   
if ($dh = opendir($dir)) { if ($dh = opendir($dir)) {
$trimlen = strlen($this->projectDir) + 1; $trimlen = strlen($this->projectDir) + 1;
while (($file = readdir($dh)) !== false) { while (($file = readdir($dh)) !== false) {
$fullPath = $dir . '/' . $file; $fullPath = $dir . '/' . $file;
if ((strpos($file, '.') !== 0) && is_dir($fullPath)) { if ((strpos($file, '.') !== 0) && is_dir($fullPath)) {
if (is_file($fullPath . '/HEAD')) { if (is_file($fullPath . '/HEAD')) {
GitPHP_Log::GetInstance()->Log(sprintf('Found project %1$s', $fullPath)); GitPHP_Log::GetInstance()->Log(sprintf('Found project %1$s', $fullPath));
$projectPath = substr($fullPath, $trimlen); $projectPath = substr($fullPath, $trimlen);
try { try {
$proj = new GitPHP_Project($this->projectDir, $projectPath); $proj = new GitPHP_Project($this->projectDir, $projectPath);
$proj->SetCategory(trim(substr($dir, strlen($this->projectDir)), '/')); $proj->SetCategory(trim(substr($dir, strlen($this->projectDir)), '/'));
if ((!GitPHP_Config::GetInstance()->GetValue('exportedonly', false)) || $proj->GetDaemonEnabled()) { if ((!GitPHP_Config::GetInstance()->GetValue('exportedonly', false)) || $proj->GetDaemonEnabled()) {
$this->projects[$projectPath] = $proj; $this->projects[$projectPath] = $proj;
} }
} catch (Exception $e) { } catch (Exception $e) {
GitPHP_Log::GetInstance()->Log($e->message); GitPHP_Log::GetInstance()->Log($e->getMessage());
} }
} else { } else {
$this->RecurseDir($fullPath); $this->RecurseDir($fullPath);
} }
} else { } else {
GitPHP_Log::GetInstance()->Log(sprintf('Skipping %1$s', $fullPath)); GitPHP_Log::GetInstance()->Log(sprintf('Skipping %1$s', $fullPath));
} }
} }
closedir($dh); closedir($dh);
} }
} }
   
} }
   
<?php <?php
/** /**
* GitPHP ProjectListFile * GitPHP ProjectListFile
* *
* Lists all projects in a given file * Lists all projects in a given file
* *
* @author Christopher Han <xiphux@gmail.com> * @author Christopher Han <xiphux@gmail.com>
* @copyright Copyright (c) 2010 Christopher Han * @copyright Copyright (c) 2010 Christopher Han
* @package GitPHP * @package GitPHP
* @subpackage Git * @subpackage Git
*/ */
   
require_once(GITPHP_INCLUDEDIR . 'Config.class.php'); require_once(GITPHP_INCLUDEDIR . 'Config.class.php');
require_once(GITPHP_GITOBJECTDIR . 'ProjectListBase.class.php'); require_once(GITPHP_GITOBJECTDIR . 'ProjectListBase.class.php');
require_once(GITPHP_GITOBJECTDIR . 'Project.class.php'); require_once(GITPHP_GITOBJECTDIR . 'Project.class.php');
   
/** /**
* ProjectListFile class * ProjectListFile class
* *
* @package GitPHP * @package GitPHP
* @subpackage Git * @subpackage Git
*/ */
class GitPHP_ProjectListFile extends GitPHP_ProjectListBase class GitPHP_ProjectListFile extends GitPHP_ProjectListBase
{ {
/** /**
* __construct * __construct
* *
* constructor * constructor
* *
* @param string $projectFile file to read * @param string $projectFile file to read
* @throws Exception if parameter is not a readable file * @throws Exception if parameter is not a readable file
* @access public * @access public
*/ */
public function __construct($projectFile) public function __construct($projectFile)
{ {
if (!(is_string($projectFile) && is_file($projectFile))) { if (!(is_string($projectFile) && is_file($projectFile))) {
throw new Exception(sprintf(__('%1$s is not a file'), $projectFile)); throw new Exception(sprintf(__('%1$s is not a file'), $projectFile));
} }
   
$this->projectConfig = $projectFile; $this->projectConfig = $projectFile;
   
parent::__construct(); parent::__construct();
} }
   
/** /**
* PopulateProjects * PopulateProjects
* *
* Populates the internal list of projects * Populates the internal list of projects
* *
* @access protected * @access protected
* @throws Exception if file cannot be read * @throws Exception if file cannot be read
*/ */
protected function PopulateProjects() protected function PopulateProjects()
{ {
if (!($fp = fopen($this->projectConfig, 'r'))) { if (!($fp = fopen($this->projectConfig, 'r'))) {
throw new Exception(sprintf(__('Failed to open project list file %1$s'), $this->projectConfig)); throw new Exception(sprintf(__('Failed to open project list file %1$s'), $this->projectConfig));
} }
   
$projectRoot = GitPHP_Util::AddSlash(GitPHP_Config::GetInstance()->GetValue('projectroot')); $projectRoot = GitPHP_Util::AddSlash(GitPHP_Config::GetInstance()->GetValue('projectroot'));
   
while (!feof($fp) && ($line = fgets($fp))) { while (!feof($fp) && ($line = fgets($fp))) {
if (preg_match('/^([^\s]+)(\s.+)?$/', $line, $regs)) { if (preg_match('/^([^\s]+)(\s.+)?$/', $line, $regs)) {
if (is_file($projectRoot . $regs[1] . '/HEAD')) { if (is_file($projectRoot . $regs[1] . '/HEAD')) {
try { try {
$projObj = new GitPHP_Project($projectRoot, $regs[1]); $projObj = new GitPHP_Project($projectRoot, $regs[1]);
if (isset($regs[2]) && !empty($regs[2])) { if (isset($regs[2]) && !empty($regs[2])) {
$projOwner = trim($regs[2]); $projOwner = trim($regs[2]);
if (!empty($projOwner)) { if (!empty($projOwner)) {
$projObj->SetOwner($projOwner); $projObj->SetOwner($projOwner);
} }
} }
$this->projects[$regs[1]] = $projObj; $this->projects[$regs[1]] = $projObj;
} catch (Exception $e) { } catch (Exception $e) {
GitPHP_Log::GetInstance()->Log($e->message); GitPHP_Log::GetInstance()->Log($e->getMessage());
} }
} else { } else {
GitPHP_Log::GetInstance()->Log(sprintf('%1$s is not a git project', $projectRoot . $regs[1])); GitPHP_Log::GetInstance()->Log(sprintf('%1$s is not a git project', $projectRoot . $regs[1]));
} }
} }
} }
   
fclose($fp); fclose($fp);
} }
   
} }
   
<?php <?php
/** /**
* GitPHP ProjectListScmManager * GitPHP ProjectListScmManager
* *
* Lists all projects in an scm-manager config file * Lists all projects in an scm-manager config file
* *
* @author Christopher Han <xiphux@gmail.com> * @author Christopher Han <xiphux@gmail.com>
* @copyright Copyright (c) 2011 Christopher Han * @copyright Copyright (c) 2011 Christopher Han
* @package GitPHP * @package GitPHP
* @subpackage Git * @subpackage Git
*/ */
   
require_once(GITPHP_INCLUDEDIR . 'Config.class.php'); require_once(GITPHP_INCLUDEDIR . 'Config.class.php');
require_once(GITPHP_GITOBJECTDIR . 'ProjectListBase.class.php'); require_once(GITPHP_GITOBJECTDIR . 'ProjectListBase.class.php');
require_once(GITPHP_GITOBJECTDIR . 'Project.class.php'); require_once(GITPHP_GITOBJECTDIR . 'Project.class.php');
   
/** /**
* ProjectListScmManager class * ProjectListScmManager class
* *
* @package GitPHP * @package GitPHP
* @subpackage Git * @subpackage Git
*/ */
class GitPHP_ProjectListScmManager extends GitPHP_ProjectListBase class GitPHP_ProjectListScmManager extends GitPHP_ProjectListBase
{ {
/** /**
* __construct * __construct
* *
* constructor * constructor
* *
* @param string $projectFile file to read * @param string $projectFile file to read
* @throws Exception if parameter is not a readable file * @throws Exception if parameter is not a readable file
* @access public * @access public
*/ */
public function __construct($projectFile) public function __construct($projectFile)
{ {
if (!(is_string($projectFile) && is_file($projectFile))) { if (!(is_string($projectFile) && is_file($projectFile))) {
throw new Exception(sprintf(__('%1$s is not a file'), $projectFile)); throw new Exception(sprintf(__('%1$s is not a file'), $projectFile));
} }
   
$this->projectConfig = $projectFile; $this->projectConfig = $projectFile;
   
parent::__construct(); parent::__construct();
} }
   
/** /**
* PopulateProjects * PopulateProjects
* *
* Populates the internal list of projects * Populates the internal list of projects
* *
* @access protected * @access protected
* @throws Exception if file cannot be read * @throws Exception if file cannot be read
*/ */
protected function PopulateProjects() protected function PopulateProjects()
{ {
$projectRoot = GitPHP_Util::AddSlash(GitPHP_Config::GetInstance()->GetValue('projectroot')); $projectRoot = GitPHP_Util::AddSlash(GitPHP_Config::GetInstance()->GetValue('projectroot'));
   
$use_errors = libxml_use_internal_errors(true); $use_errors = libxml_use_internal_errors(true);
   
$xml = simplexml_load_file($this->projectConfig); $xml = simplexml_load_file($this->projectConfig);
   
libxml_clear_errors(); libxml_clear_errors();
libxml_use_internal_errors($use_errors); libxml_use_internal_errors($use_errors);
   
if (!$xml) { if (!$xml) {
throw new Exception(sprintf('Could not load SCM manager config %1$s', $this->projectConfig)); throw new Exception(sprintf('Could not load SCM manager config %1$s', $this->projectConfig));
} }
   
foreach ($xml->repositories->repository as $repository) { foreach ($xml->repositories->repository as $repository) {
   
if ($repository->type != 'git') { if ($repository->type != 'git') {
GitPHP_Log::GetInstance()->Log(sprintf('%1$s is not a git project', $repository->name)); GitPHP_Log::GetInstance()->Log(sprintf('%1$s is not a git project', $repository->name));
continue; continue;
} }
   
if ($repository->public != 'true') { if ($repository->public != 'true') {
GitPHP_Log::GetInstance()->Log(sprintf('%1$s is not public', $repository->name)); GitPHP_Log::GetInstance()->Log(sprintf('%1$s is not public', $repository->name));
continue; continue;
} }
   
$projName = trim($repository->name); $projName = trim($repository->name);
if (empty($projName)) if (empty($projName))
continue; continue;
   
if (is_file($projectRoot . $projName . '/HEAD')) { if (is_file($projectRoot . $projName . '/HEAD')) {
try { try {
$projObj = new GitPHP_Project($projectRoot, $projName); $projObj = new GitPHP_Project($projectRoot, $projName);
$projOwner = trim($repository->contact); $projOwner = trim($repository->contact);
if (!empty($projOwner)) { if (!empty($projOwner)) {
$projObj->SetOwner($projOwner); $projObj->SetOwner($projOwner);
} }
$projDesc = trim($repository->description); $projDesc = trim($repository->description);
if (!empty($projDesc)) { if (!empty($projDesc)) {
$projObj->SetDescription($projDesc); $projObj->SetDescription($projDesc);
} }
$this->projects[$projName] = $projObj; $this->projects[$projName] = $projObj;
} catch (Exception $e) { } catch (Exception $e) {
GitPHP_Log::GetInstance()->Log($e->message); GitPHP_Log::GetInstance()->Log($e->getMessage());
} }
} else { } else {
GitPHP_Log::GetInstance()->Log(sprintf('%1$s is not a git project', $projName)); GitPHP_Log::GetInstance()->Log(sprintf('%1$s is not a git project', $projName));
} }
} }
} }
   
/** /**
* IsSCMManager * IsSCMManager
* *
* Tests if this file is an SCM manager config file * Tests if this file is an SCM manager config file
* *
* @access protected * @access protected
* @returns true if file is an SCM manager config * @returns true if file is an SCM manager config
*/ */
public static function IsSCMManager($file) public static function IsSCMManager($file)
{ {
if (empty($file)) if (empty($file))
return false; return false;
   
if (!(is_string($file) && is_file($file))) if (!(is_string($file) && is_file($file)))
return false; return false;
   
$use_errors = libxml_use_internal_errors(true); $use_errors = libxml_use_internal_errors(true);
   
$xml = simplexml_load_file($file); $xml = simplexml_load_file($file);
   
libxml_clear_errors(); libxml_clear_errors();
libxml_use_internal_errors($use_errors); libxml_use_internal_errors($use_errors);
   
if (!$xml) if (!$xml)
return false; return false;
   
if ($xml->getName() !== 'repository-db') if ($xml->getName() !== 'repository-db')
return false; return false;
   
return true; return true;
} }
   
} }
   
comments