Apply description from repo config value "gitweb.description" in absence of "gitphp.description".
[gitphp.git] / include / git / projectlist / ProjectListBase.class.php
blob:a/include/git/projectlist/ProjectListBase.class.php -> blob:b/include/git/projectlist/ProjectListBase.class.php
<?php <?php
/** /**
* Base class that all projectlist classes extend * Base class that all projectlist classes extend
* *
* @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\ProjectList * @subpackage Git\ProjectList
*/ */
abstract class GitPHP_ProjectListBase implements Iterator, GitPHP_Observable_Interface abstract class GitPHP_ProjectListBase implements Iterator, GitPHP_Observable_Interface
{ {
/** /**
* Project name sort * Project name sort
* *
* @var string * @var string
*/ */
const ProjectSort = 'project'; const ProjectSort = 'project';
   
/** /**
* Project description sort * Project description sort
* *
* @var string * @var string
*/ */
const DescriptionSort = 'descr'; const DescriptionSort = 'descr';
   
/** /**
* Project owner sort * Project owner sort
* *
* @var string * @var string
*/ */
const OwnerSort = 'owner'; const OwnerSort = 'owner';
   
/** /**
* Project age sort * Project age sort
* *
* @var string * @var string
*/ */
const AgeSort = 'age'; const AgeSort = 'age';
   
/** /**
* Project list * Project list
* *
* @var GitPHP_Project[] * @var GitPHP_Project[]
*/ */
protected $projects; protected $projects;
   
/** /**
* Whether the list of projects has been loaded * Whether the list of projects has been loaded
* *
* @var boolean * @var boolean
*/ */
protected $projectsLoaded = false; protected $projectsLoaded = false;
   
/** /**
* The projectlist configuration * The projectlist configuration
* *
* @var string * @var string
*/ */
protected $projectConfig = null; protected $projectConfig = null;
   
/** /**
* Project settings * Project settings
* *
* @var array * @var array
*/ */
protected $projectSettings = null; protected $projectSettings = null;
   
/** /**
* The project root * The project root
* *
* @var string * @var string
*/ */
protected $projectRoot = null; protected $projectRoot = null;
   
/** /**
* Object cache instance for all projects * Object cache instance for all projects
* *
* @var GitPHP_Cache * @var GitPHP_Cache
*/ */
protected $cache = null; protected $cache = null;
   
/** /**
* Memory cache instance for all projects * Memory cache instance for all projects
* *
* @var GitPHP_MemoryCache * @var GitPHP_MemoryCache
*/ */
protected $memoryCache = null; protected $memoryCache = null;
   
/** /**
* Executable for all projects * Executable for all projects
* *
* @var GitPHP_GitExe * @var GitPHP_GitExe
*/ */
protected $exe = null; protected $exe = null;
   
/** /**
* Config provider * Config provider
* *
* @var GitPHP_Config * @var GitPHP_Config
*/ */
protected $config = null; protected $config = null;
   
/** /**
* Observers * Observers
* *
* @var GitPHP_Observer_Interface[] * @var GitPHP_Observer_Interface[]
*/ */
protected $observers = array(); protected $observers = array();
   
/** /**
* Constructor * Constructor
* *
* @param string $projectRoot project root * @param string $projectRoot project root
*/ */
public function __construct($projectRoot) public function __construct($projectRoot)
{ {
$this->projects = array(); $this->projects = array();
$this->projectRoot = GitPHP_Util::AddSlash($projectRoot); $this->projectRoot = GitPHP_Util::AddSlash($projectRoot);
if (empty($this->projectRoot)) { if (empty($this->projectRoot)) {
throw new GitPHP_MissingProjectrootException(); throw new GitPHP_MissingProjectrootException();
} }
if (!is_dir($this->projectRoot)) { if (!is_dir($this->projectRoot)) {
throw new GitPHP_InvalidDirectoryConfigurationException($this->projectRoot); throw new GitPHP_InvalidDirectoryConfigurationException($this->projectRoot);
} }
} }
   
/** /**
* Get config provider * Get config provider
* *
* @return GitPHP_Config * @return GitPHP_Config
*/ */
public function GetConfig() public function GetConfig()
{ {
return $this->config; return $this->config;
} }
   
/** /**
* Set config provider * Set config provider
* *
* @param GitPHP_Config $config config provider * @param GitPHP_Config $config config provider
*/ */
public function SetConfig($config) public function SetConfig($config)
{ {
$this->config = $config; $this->config = $config;
} }
   
/** /**
* Get memory cache instance * Get memory cache instance
* *
* @return GitPHP_MemoryCache|null * @return GitPHP_MemoryCache|null
*/ */
public function GetMemoryCache() public function GetMemoryCache()
{ {
return $this->memoryCache; return $this->memoryCache;
} }
   
/** /**
* Set memory cache instance * Set memory cache instance
* *
* @param GitPHP_MemoryCache|null $memoryCache memory cache instance * @param GitPHP_MemoryCache|null $memoryCache memory cache instance
*/ */
public function SetMemoryCache($memoryCache) public function SetMemoryCache($memoryCache)
{ {
$this->memoryCache = $memoryCache; $this->memoryCache = $memoryCache;
} }
   
/** /**
* Get object cache instance * Get object cache instance
* *
* @return GitPHP_Cache|null object cache * @return GitPHP_Cache|null object cache
*/ */
public function GetCache() public function GetCache()
{ {
return $this->cache; return $this->cache;
} }
   
/** /**
* Set object cache instance * Set object cache instance
* *
* @param GitPHP_Cache|null $cache object cache instance * @param GitPHP_Cache|null $cache object cache instance
*/ */
public function SetCache($cache) public function SetCache($cache)
{ {
$this->cache = $cache; $this->cache = $cache;
} }
   
/** /**
* Get executable * Get executable
* *
* @return GitPHP_GitExe executable * @return GitPHP_GitExe executable
*/ */
public function GetExe() public function GetExe()
{ {
return $this->exe; return $this->exe;
} }
   
/** /**
* Set executable * Set executable
* *
* @param GitPHP_GitExe $exe executable * @param GitPHP_GitExe $exe executable
*/ */
public function SetExe($exe) public function SetExe($exe)
{ {
$this->exe = $exe; $this->exe = $exe;
} }
   
/** /**
* Test if the projectlist contains the given project * Test if the projectlist contains the given project
* *
* @return boolean true if project exists in list * @return boolean true if project exists in list
* @param string $project the project to find * @param string $project the project to find
*/ */
public function HasProject($project) public function HasProject($project)
{ {
if (empty($project)) if (empty($project))
return false; return false;
   
return isset($this->projects[$project]); return isset($this->projects[$project]);
} }
   
/** /**
* Gets a particular project * Gets a particular project
* *
* @return GitPHP_Project|null project object or null * @return GitPHP_Project|null project object or null
* @param string $project the project to find * @param string $project the project to find
*/ */
public function GetProject($project) public function GetProject($project)
{ {
if (empty($project)) if (empty($project))
return null; return null;
   
if (isset($this->projects[$project])) if (isset($this->projects[$project]))
return $this->projects[$project]; return $this->projects[$project];
   
if (!$this->projectsLoaded) { if (!$this->projectsLoaded) {
$projObj = $this->LoadProject($project); $projObj = $this->LoadProject($project);
$this->projects[$project] = $projObj; $this->projects[$project] = $projObj;
return $projObj; return $projObj;
} }
   
return null; return null;
} }
   
/** /**
* Loads a project * Loads a project
* *
* @param string $proj project * @param string $proj project
* @return return GitPHP_Project project object * @return return GitPHP_Project project object
*/ */
protected function LoadProject($proj) protected function LoadProject($proj)
{ {
$project = new GitPHP_Project(GitPHP_Util::AddSlash($this->projectRoot), $proj); $project = new GitPHP_Project(GitPHP_Util::AddSlash($this->projectRoot), $proj);
   
$this->ApplyGlobalConfig($project); $this->ApplyGlobalConfig($project);
   
$this->ApplyGitConfig($project); $this->ApplyGitConfig($project);
   
if ($this->projectSettings && isset($this->projectSettings[$proj])) { if ($this->projectSettings && isset($this->projectSettings[$proj])) {
$this->ApplyProjectSettings($project, $this->projectSettings[$proj]); $this->ApplyProjectSettings($project, $this->projectSettings[$proj]);
} }
   
$this->InjectProjectDependencies($project); $this->InjectProjectDependencies($project);
   
return $project; return $project;
} }
   
/** /**
* Inject project dependency objects * Inject project dependency objects
* *
* @param GitPHP_Project $project project object * @param GitPHP_Project $project project object
*/ */
protected function InjectProjectDependencies($project) protected function InjectProjectDependencies($project)
{ {
if (!$project) if (!$project)
return; return;
   
$compat = $project->GetCompat(); $compat = $project->GetCompat();
   
$loader = null; $loader = null;
if ($compat) { if ($compat) {
$project->SetStrategy(new GitPHP_ProjectLoad_Git($this->exe)); $project->SetStrategy(new GitPHP_ProjectLoad_Git($this->exe));
} else { } else {
$loader = new GitPHP_GitObjectLoader($project); $loader = new GitPHP_GitObjectLoader($project);
$project->SetStrategy(new GitPHP_ProjectLoad_Raw($loader)); $project->SetStrategy(new GitPHP_ProjectLoad_Raw($loader));
} }
   
$headListStrategy = null; $headListStrategy = null;
if ($compat) { if ($compat) {
$headListStrategy = new GitPHP_HeadListLoad_Git($this->exe); $headListStrategy = new GitPHP_HeadListLoad_Git($this->exe);
} else { } else {
$headListStrategy = new GitPHP_HeadListLoad_Raw(); $headListStrategy = new GitPHP_HeadListLoad_Raw();
} }
$headList = new GitPHP_HeadList($project, $headListStrategy); $headList = new GitPHP_HeadList($project, $headListStrategy);
$project->SetHeadList($headList); $project->SetHeadList($headList);
   
$tagListStrategy = null; $tagListStrategy = null;
if ($compat) { if ($compat) {
$tagListStrategy = new GitPHP_TagListLoad_Git($this->exe); $tagListStrategy = new GitPHP_TagListLoad_Git($this->exe);
} else { } else {
$tagListStrategy = new GitPHP_TagListLoad_Raw(); $tagListStrategy = new GitPHP_TagListLoad_Raw();
} }
$tagList = new GitPHP_TagList($project, $tagListStrategy); $tagList = new GitPHP_TagList($project, $tagListStrategy);
$project->SetTagList($tagList); $project->SetTagList($tagList);
   
$manager = new GitPHP_GitObjectManager($project); $manager = new GitPHP_GitObjectManager($project);
$manager->SetCompat($compat); $manager->SetCompat($compat);
if (!$compat) { if (!$compat) {
$manager->SetObjectLoader($loader); $manager->SetObjectLoader($loader);
} }
$manager->SetExe($this->exe); $manager->SetExe($this->exe);
if ($this->memoryCache) { if ($this->memoryCache) {
$manager->SetMemoryCache($this->memoryCache); $manager->SetMemoryCache($this->memoryCache);
} }
if ($this->cache) { if ($this->cache) {
$manager->SetCache($this->cache); $manager->SetCache($this->cache);
} }
$project->SetObjectManager($manager); $project->SetObjectManager($manager);
} }
   
/** /**
* Gets the config defined for this ProjectList * Gets the config defined for this ProjectList
* *
* @return mixed project config * @return mixed project config
*/ */
public function GetProjectListConfig() public function GetProjectListConfig()
{ {
return $this->projectConfig; return $this->projectConfig;
} }
   
/** /**
* Gets the settings applied to this projectlist * Gets the settings applied to this projectlist
* *
* @return array * @return array
*/ */
public function GetProjectSettings() public function GetProjectSettings()
{ {
return $this->projectSettings; return $this->projectSettings;
} }
   
/** /**
* Reads the project's git config settings and applies them to the project * Reads the project's git config settings and applies them to the project
* *
* @param GitPHP_Project $project project * @param GitPHP_Project $project project
*/ */
protected function ApplyGitConfig($project) protected function ApplyGitConfig($project)
{ {
if (!$project) if (!$project)
return; return;
   
$config = null; $config = null;
try { try {
$config = new GitPHP_GitConfig($project->GetPath() . '/config'); $config = new GitPHP_GitConfig($project->GetPath() . '/config');
} catch (Exception $e) { } catch (Exception $e) {
return; return;
} }
   
if ($config->HasValue('gitphp.owner')) { if ($config->HasValue('gitphp.owner')) {
$project->SetOwner($config->GetValue('gitphp.owner')); $project->SetOwner($config->GetValue('gitphp.owner'));
} else if ($config->HasValue('gitweb.owner')) { } else if ($config->HasValue('gitweb.owner')) {
$project->SetOwner($config->GetValue('gitweb.owner')); $project->SetOwner($config->GetValue('gitweb.owner'));
} }
   
if ($config->HasValue('gitphp.description')) { if ($config->HasValue('gitphp.description')) {
$project->SetDescription($config->GetValue('gitphp.description')); $project->SetDescription($config->GetValue('gitphp.description'));
  } else if ($config->HasValue('gitweb.description')) {
  $project->SetDescription($config->GetValue('gitweb.description'));
} }
   
if ($config->HasValue('gitphp.category')) { if ($config->HasValue('gitphp.category')) {
$project->SetCategory($config->GetValue('gitphp.category')); $project->SetCategory($config->GetValue('gitphp.category'));
} }
   
if ($config->HasValue('gitphp.cloneurl')) { if ($config->HasValue('gitphp.cloneurl')) {
$project->SetCloneUrl($config->GetValue('gitphp.cloneurl')); $project->SetCloneUrl($config->GetValue('gitphp.cloneurl'));
} }
   
if ($config->HasValue('gitphp.pushurl')) { if ($config->HasValue('gitphp.pushurl')) {
$project->SetPushUrl($config->GetValue('gitphp.pushurl')); $project->SetPushUrl($config->GetValue('gitphp.pushurl'));
} }
   
if ($config->HasValue('gitphp.bugurl')) { if ($config->HasValue('gitphp.bugurl')) {
$project->SetBugUrl($config->GetValue('gitphp.bugurl')); $project->SetBugUrl($config->GetValue('gitphp.bugurl'));
} }
   
if ($config->HasValue('gitphp.bugpattern')) { if ($config->HasValue('gitphp.bugpattern')) {
$project->SetBugPattern($config->GetValue('gitphp.bugpattern')); $project->SetBugPattern($config->GetValue('gitphp.bugpattern'));
} }
   
if ($config->HasValue('gitphp.website')) { if ($config->HasValue('gitphp.website')) {
$project->SetWebsite($config->GetValue('gitphp.website')); $project->SetWebsite($config->GetValue('gitphp.website'));
} }
   
if ($config->HasValue('gitphp.compat')) { if ($config->HasValue('gitphp.compat')) {
$project->SetCompat($config->GetValue('gitphp.compat')); $project->SetCompat($config->GetValue('gitphp.compat'));
} }
   
if ($config->HasValue('core.abbrev')) { if ($config->HasValue('core.abbrev')) {
$project->SetAbbreviateLength($config->GetValue('core.abbrev')); $project->SetAbbreviateLength($config->GetValue('core.abbrev'));
} }
   
if ($config->HasValue('gitphp.allowedusers')) { if ($config->HasValue('gitphp.allowedusers')) {
$project->SetAllowedUsers($config->GetValue('gitphp.allowedusers', true)); $project->SetAllowedUsers($config->GetValue('gitphp.allowedusers', true));
} }
   
} }
   
/** /**
* Applies global config settings to a project * Applies global config settings to a project
* *
* @param GitPHP_Project $project project * @param GitPHP_Project $project project
*/ */
protected function ApplyGlobalConfig($project) protected function ApplyGlobalConfig($project)
{ {
if (!$project) if (!$project)
return; return;
   
if (!$this->config) if (!$this->config)
return; return;
   
if ($this->config->GetValue('cloneurl')) { if ($this->config->GetValue('cloneurl')) {
$project->SetCloneUrl(GitPHP_Util::AddSlash($this->config->GetValue('cloneurl'), false) . $project->GetProject()); $project->SetCloneUrl(GitPHP_Util::AddSlash($this->config->GetValue('cloneurl'), false) . $project->GetProject());
} }
   
if ($this->config->GetValue('pushurl')) { if ($this->config->GetValue('pushurl')) {
$project->SetPushUrl(GitPHP_Util::AddSlash($this->config->GetValue('pushurl'), false) . $project->GetProject()); $project->SetPushUrl(GitPHP_Util::AddSlash($this->config->GetValue('pushurl'), false) . $project->GetProject());
} }
   
if ($this->config->GetValue('bugpattern')) { if ($this->config->GetValue('bugpattern')) {
$project->SetBugPattern($this->config->GetValue('bugpattern')); $project->SetBugPattern($this->config->GetValue('bugpattern'));
} }
   
if ($this->config->GetValue('bugurl')) { if ($this->config->GetValue('bugurl')) {
$project->SetBugUrl($this->config->GetValue('bugurl')); $project->SetBugUrl($this->config->GetValue('bugurl'));
} }
   
if ($this->config->HasKey('compat')) { if ($this->config->HasKey('compat')) {
$project->SetCompat($this->config->GetValue('compat')); $project->SetCompat($this->config->GetValue('compat'));
} }
   
if ($this->config->HasKey('uniqueabbrev')) { if ($this->config->HasKey('uniqueabbrev')) {
$project->SetUniqueAbbreviation($this->config->GetValue('uniqueabbrev')); $project->SetUniqueAbbreviation($this->config->GetValue('uniqueabbrev'));
} }
   
if ($this->config->GetValue('abbreviateurl')) { if ($this->config->GetValue('abbreviateurl')) {
$project->SetUniqueAbbreviation(true); $project->SetUniqueAbbreviation(true);
} }
} }
   
/** /**
* Loads all projects in the list * Loads all projects in the list
*/ */
public function LoadProjects() public function LoadProjects()
{ {
$this->PopulateProjects(); $this->PopulateProjects();
   
$this->projectsLoaded = true; $this->projectsLoaded = true;
   
$this->Sort(); $this->Sort();
   
$this->ApplySettings(); $this->ApplySettings();
} }
   
/** /**
* Filter projects by user access * Filter projects by user access
* *
* @param string $username username * @param string $username username
*/ */
public function FilterByUser($username) public function FilterByUser($username)
{ {
foreach ($this->projects as $path => $project) { foreach ($this->projects as $path => $project) {
if (!$project->UserCanAccess($username)) if (!$project->UserCanAccess($username))
unset($this->projects[$path]); unset($this->projects[$path]);
} }
} }
   
/** /**
* Populates the internal list of projects * Populates the internal list of projects
*/ */
abstract protected function PopulateProjects(); abstract protected function PopulateProjects();
   
/** /**
* Rewinds the iterator * Rewinds the iterator
* *
* @return GitPHP_Project * @return GitPHP_Project
*/ */
function rewind() function rewind()
{ {
return reset($this->projects); return reset($this->projects);
} }
   
/** /**
* Returns the current element in the array * Returns the current element in the array
* *
* @return GitPHP_Project * @return GitPHP_Project
*/ */
function current() function current()
{ {
return current($this->projects); return current($this->projects);
} }
   
/** /**
* Returns the current key * Returns the current key
* *
* @return string * @return string
*/ */
function key() function key()
{ {
return key($this->projects); return key($this->projects);
} }
   
/** /**
* Advance the pointer * Advance the pointer
* *
* @return GitPHP_Project * @return GitPHP_Project
*/ */
function next() function next()
{ {
return next($this->projects); return next($this->projects);
} }
   
/** /**
* Test for a valid pointer * Test for a valid pointer
* *
* @return boolean * @return boolean
*/ */
function valid() function valid()
{ {
return key($this->projects) !== null; return key($this->projects) !== null;
} }
   
/** /**
* Sorts the project list * Sorts the project list
* *
* @param string $sortBy sort method * @param string $sortBy sort method
*/ */
public function Sort($sortBy = GitPHP_ProjectListBase::ProjectSort) public function Sort($sortBy = GitPHP_ProjectListBase::ProjectSort)
{ {
switch ($sortBy) { switch ($sortBy) {
case GitPHP_ProjectListBase::DescriptionSort: case GitPHP_ProjectListBase::DescriptionSort:
uasort($this->projects, array('GitPHP_Project', 'CompareDescription')); uasort($this->projects, array('GitPHP_Project', 'CompareDescription'));
break; break;
case GitPHP_ProjectListBase::OwnerSort: case GitPHP_ProjectListBase::OwnerSort:
uasort($this->projects, array('GitPHP_Project', 'CompareOwner')); uasort($this->projects, array('GitPHP_Project', 'CompareOwner'));
break; break;
case GitPHP_ProjectListBase::AgeSort: case GitPHP_ProjectListBase::AgeSort:
uasort($this->projects, array('GitPHP_Project', 'CompareAge')); uasort($this->projects, array('GitPHP_Project', 'CompareAge'));
break; break;
case GitPHP_ProjectListBase::ProjectSort: case GitPHP_ProjectListBase::ProjectSort:
default: default:
uasort($this->projects, array('GitPHP_Project', 'CompareProject')); uasort($this->projects, array('GitPHP_Project', 'CompareProject'));
break; break;
} }
} }
   
/** /**
* Gets the count of projects * Gets the count of projects
* *
* @return integer number of projects * @return integer number of projects
*/ */
public function Count() public function Count()
{ {
return count($this->projects); return count($this->projects);
} }
   
/** /**
* Returns a filtered list of projects * Returns a filtered list of projects
* *
* @param string $pattern filter pattern * @param string $pattern filter pattern
* @return GitPHP_Project[] array of filtered projects * @return GitPHP_Project[] array of filtered projects
*/ */
public function Filter($pattern = null) public function Filter($pattern = null)
{ {
if (empty($pattern)) if (empty($pattern))
return $this->projects; return $this->projects;
   
$matches = array(); $matches = array();
   
foreach ($this->projects as $proj) { foreach ($this->projects as $proj) {
if ((stripos($proj->GetProject(), $pattern) !== false) || if ((stripos($proj->GetProject(), $pattern) !== false) ||
(stripos($proj->GetDescription(), $pattern) !== false) || (stripos($proj->GetDescription(), $pattern) !== false) ||
(stripos($proj->GetOwner(), $pattern) !== false)) { (stripos($proj->GetOwner(), $pattern) !== false)) {
$matches[] = $proj; $matches[] = $proj;
} }
} }
   
return $matches; return $matches;
} }
   
/** /**
* Applies override settings for a project * Applies override settings for a project
* *
* @param GitPHP_Project $project the project object * @param GitPHP_Project $project the project object
* @param array $projData project data array * @param array $projData project data array
*/ */
protected function ApplyProjectSettings($project, $projData) protected function ApplyProjectSettings($project, $projData)
{ {
if (!$project) if (!$project)
return; return;
   
if (isset($projData['category']) && is_string($projData['category'])) { if (isset($projData['category']) && is_string($projData['category'])) {
$project->SetCategory($projData['category']); $project->SetCategory($projData['category']);
} }
if (isset($projData['owner']) && is_string($projData['owner'])) { if (isset($projData['owner']) && is_string($projData['owner'])) {
$project->SetOwner($projData['owner']); $project->SetOwner($projData['owner']);
} }
if (isset($projData['description']) && is_string($projData['description'])) { if (isset($projData['description']) && is_string($projData['description'])) {
$project->SetDescription($projData['description']); $project->SetDescription($projData['description']);
} }
if (isset($projData['cloneurl']) && is_string($projData['cloneurl'])) { if (isset($projData['cloneurl']) && is_string($projData['cloneurl'])) {
$project->SetCloneUrl($projData['cloneurl']); $project->SetCloneUrl($projData['cloneurl']);
} }
if (isset($projData['pushurl']) && is_string($projData['pushurl'])) { if (isset($projData['pushurl']) && is_string($projData['pushurl'])) {
$project->SetPushUrl($projData['pushurl']); $project->SetPushUrl($projData['pushurl']);
} }
if (isset($projData['bugpattern']) && is_string($projData['bugpattern'])) { if (isset($projData['bugpattern']) && is_string($projData['bugpattern'])) {
$project->SetBugPattern($projData['bugpattern']); $project->SetBugPattern($projData['bugpattern']);
} }
if (isset($projData['bugurl']) && is_string($projData['bugurl'])) { if (isset($projData['bugurl']) && is_string($projData['bugurl'])) {
$project->SetBugUrl($projData['bugurl']); $project->SetBugUrl($projData['bugurl']);
} }
if (isset($projData['compat'])) { if (isset($projData['compat'])) {
$project->SetCompat($projData['compat']); $project->SetCompat($projData['compat']);
} }
if (isset($projData['website']) && is_string($projData['website'])) { if (isset($projData['website']) && is_string($projData['website'])) {
$project->SetWebsite($projData['website']); $project->SetWebsite($projData['website']);
} }
if (!empty($projData['allowedusers'])) { if (!empty($projData['allowedusers'])) {
$project->SetAllowedUsers($projData['allowedusers']); $project->SetAllowedUsers($projData['allowedusers']);
} }
} }
   
/** /**
* Sets a list of settings for the project list * Sets a list of settings for the project list
* *
* @param array $settings the array of settings * @param array $settings the array of settings
*/ */
public function SetProjectSettings($settings) public function SetProjectSettings($settings)
{ {
if ((!$settings) || (count($settings) < 1)) if ((!$settings) || (count($settings) < 1))
return; return;
   
$this->projectSettings = $settings; $this->projectSettings = $settings;
   
$this->ApplySettings(); $this->ApplySettings();
} }
   
/** /**
* Applies project settings to project list * Applies project settings to project list
*/ */
protected function ApplySettings() protected function ApplySettings()
{ {
if (!$this->projectSettings) if (!$this->projectSettings)
return; return;
   
if (count($this->projects) > 0) { if (count($this->projects) > 0) {
foreach ($this->projectSettings as $proj => $setting) { foreach ($this->projectSettings as $proj => $setting) {
   
if (empty($proj)) { if (empty($proj)) {
if (isset($setting['project']) && !empty($setting['project'])) { if (isset($setting['project']) && !empty($setting['project'])) {
$proj = $setting['project']; $proj = $setting['project'];
} }
} }
   
if (!isset($this->projects[$proj])) if (!isset($this->projects[$proj]))
break; break;
   
$this->ApplyProjectSettings($this->projects[$proj], $setting); $this->ApplyProjectSettings($this->projects[$proj], $setting);
} }
} }
} }
   
/** /**
* Add a new observer * Add a new observer
* *
* @param GitPHP_Observer_Interface $observer observer * @param GitPHP_Observer_Interface $observer observer
*/ */
public function AddObserver($observer) public function AddObserver($observer)
{ {
if (!$observer) if (!$observer)
return; return;
   
if (array_search($observer, $this->observers) !== false) if (array_search($observer, $this->observers) !== false)
return; return;
   
$this->observers[] = $observer; $this->observers[] = $observer;
} }
   
/** /**
* Remove an observer * Remove an observer
* *
* @param GitPHP_Observer_Interface $observer observer * @param GitPHP_Observer_Interface $observer observer
*/ */
public function RemoveObserver($observer) public function RemoveObserver($observer)
{ {
if (!$observer) if (!$observer)
return; return;
   
$key = array_search($observer, $this->observers); $key = array_search($observer, $this->observers);
   
if ($key === false) if ($key === false)
return; return;
   
unset($this->observers[$key]); unset($this->observers[$key]);
} }
   
/** /**
* Log a message to observers * Log a message to observers
* *
* @param string $message message * @param string $message message
*/ */
protected function Log($message) protected function Log($message)
{ {
if (empty($message)) if (empty($message))
return; return;
   
foreach ($this->observers as $observer) { foreach ($this->observers as $observer) {
$observer->ObjectChanged($this, GitPHP_Observer_Interface::LoggableChange, array($message)); $observer->ObjectChanged($this, GitPHP_Observer_Interface::LoggableChange, array($message));
} }
} }
   
} }
   
comments