Use autoloading to load class files
[gitphp.git] / include / git / projectlist / ProjectListArray.class.php
blob:a/include/git/projectlist/ProjectListArray.class.php -> blob:b/include/git/projectlist/ProjectListArray.class.php
<?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 . 'projectlist/ProjectListBase.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 string $projectRoot project root * @param string $projectRoot project root
* @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($projectRoot, $projectArray) public function __construct($projectRoot, $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($projectRoot); parent::__construct($projectRoot);
} }
   
/** /**
* 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()
{ {
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 = $this->InstantiateProject($projData); $projObj = $this->InstantiateProject($projData);
if ($projObj) { if ($projObj) {
$this->projects[$projData] = $projObj; $this->projects[$projData] = $projObj;
unset($projObj); unset($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 = $this->InstantiateProject($proj); $projObj = $this->InstantiateProject($proj);
if ($projObj) { if ($projObj) {
$this->projects[$proj] = $projObj; $this->projects[$proj] = $projObj;
unset($projObj); unset($projObj);
} }
} 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 = $this->InstantiateProject($projData['project']); $projObj = $this->InstantiateProject($projData['project']);
if ($projObj) { if ($projObj) {
$this->projects[$projData['project']] = $projObj; $this->projects[$projData['project']] = $projObj;
unset($projObj); unset($projObj);
} }
} }
} }
} catch (Exception $e) { } catch (Exception $e) {
GitPHP_DebugLog::GetInstance()->Log($e->getMessage()); GitPHP_DebugLog::GetInstance()->Log($e->getMessage());
} }
} }
} }
   
/** /**
* InstantiateProject * InstantiateProject
* *
* Instantiates project object * Instantiates project object
* *
* @access protected * @access protected
* @param string $proj project * @param string $proj project
* @return mixed project * @return mixed project
*/ */
protected function InstantiateProject($proj) protected function InstantiateProject($proj)
{ {
$found = false; $found = false;
$projectSettings = null; $projectSettings = null;
foreach ($this->projectConfig as $key => $projData) { foreach ($this->projectConfig as $key => $projData) {
if (is_string($projData) && ($projData == $proj)) { if (is_string($projData) && ($projData == $proj)) {
// Just flat array of project paths // Just flat array of project paths
$found = true; $found = true;
break; break;
} else if (is_array($projData)) { } else if (is_array($projData)) {
if (is_string($key) && !empty($key) && ($key == $proj)) { if (is_string($key) && !empty($key) && ($key == $proj)) {
// Project key pointing to data array // Project key pointing to data array
$found = true; $found = true;
$projectSettings = $projData; $projectSettings = $projData;
break; break;
} }
if (isset($projData['project']) && ($projData['project'] == $proj)) { if (isset($projData['project']) && ($projData['project'] == $proj)) {
// List of data arrays with projects inside // List of data arrays with projects inside
$found = true; $found = true;
$projectSettings = $projData; $projectSettings = $projData;
break; break;
} }
} }
} }
   
if (!$found) { if (!$found) {
return; return;
} }
   
$projectObj = new GitPHP_Project($this->projectRoot, $proj); $projectObj = new GitPHP_Project($this->projectRoot, $proj);
   
$this->ApplyGlobalConfig($projectObj); $this->ApplyGlobalConfig($projectObj);
   
$this->ApplyGitConfig($projectObj); $this->ApplyGitConfig($projectObj);
   
if ($projectSettings != null) if ($projectSettings != null)
$this->ApplyProjectSettings($projectObj, $projectSettings); $this->ApplyProjectSettings($projectObj, $projectSettings);
   
if ($this->projectSettings && isset($this->projectSettings[$proj])) { if ($this->projectSettings && isset($this->projectSettings[$proj])) {
$this->ApplyProjectSettings($projectObj, $this->projectSettings[$proj]); $this->ApplyProjectSettings($projectObj, $this->projectSettings[$proj]);
} }
   
return $projectObj; return $projectObj;
} }
   
} }
   
comments