Inject cache and memorycache into projectlist
[gitphp.git] / include / git / projectlist / ProjectListBase.class.php
blob:a/include/git/projectlist/ProjectListBase.class.php -> blob:b/include/git/projectlist/ProjectListBase.class.php
--- a/include/git/projectlist/ProjectListBase.class.php
+++ b/include/git/projectlist/ProjectListBase.class.php
@@ -52,7 +52,7 @@
 	protected $projectsLoaded = false;
 
 	/**
-	 * The project configuration
+	 * The projectlist configuration
 	 *
 	 * @var string
 	 */
@@ -92,6 +92,13 @@
 	 * @var GitPHP_GitExe
 	 */
 	protected $exe = null;
+
+	/**
+	 * Config provider
+	 *
+	 * @var GitPHP_Config
+	 */
+	protected $config = null;
 
 	/**
 	 * Observers
@@ -118,6 +125,26 @@
 	}
 
 	/**
+	 * Get config provider
+	 *
+	 * @return GitPHP_Config
+	 */
+	public function GetConfig()
+	{
+		return $this->config;
+	}
+
+	/**
+	 * Set config provider
+	 *
+	 * @param GitPHP_Config $config config provider
+	 */
+	public function SetConfig($config)
+	{
+		$this->config = $config;
+	}
+
+	/**
 	 * Get memory cache instance
 	 *
 	 * @return GitPHP_MemoryCache|null
@@ -249,10 +276,12 @@
 
 		$compat = $project->GetCompat();
 
+		$loader = null;
 		if ($compat) {
 			$project->SetStrategy(new GitPHP_ProjectLoad_Git($this->exe));
 		} else {
-			$project->SetStrategy(new GitPHP_ProjectLoad_Raw());
+			$loader = new GitPHP_GitObjectLoader($project);
+			$project->SetStrategy(new GitPHP_ProjectLoad_Raw($loader));
 		}
 
 		$headListStrategy = null;
@@ -273,13 +302,11 @@
 		$tagList = new GitPHP_TagList($project, $tagListStrategy);
 		$project->SetTagList($tagList);
 
-		if (!$compat) {
-			$loader = new GitPHP_GitObjectLoader($project);
-			$project->SetObjectLoader($loader);
-		}
-
 		$manager = new GitPHP_GitObjectManager($project);
 		$manager->SetCompat($compat);
+		if (!$compat) {
+			$manager->SetObjectLoader($loader);
+		}
 		$manager->SetExe($this->exe);
 		if ($this->memoryCache) {
 			$manager->SetMemoryCache($this->memoryCache);
@@ -295,7 +322,7 @@
 	 *
 	 * @return mixed project config
 	 */
-	public function GetConfig()
+	public function GetProjectListConfig()
 	{
 		return $this->projectConfig;
 	}
@@ -305,7 +332,7 @@
 	 *
 	 * @return array
 	 */
-	public function GetSettings()
+	public function GetProjectSettings()
 	{
 		return $this->projectSettings;
 	}
@@ -335,6 +362,8 @@
 
 		if ($config->HasValue('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')) {
@@ -369,6 +398,10 @@
 			$project->SetAbbreviateLength($config->GetValue('core.abbrev'));
 		}
 
+		if ($config->HasValue('gitphp.allowedusers')) {
+			$project->SetAllowedUsers($config->GetValue('gitphp.allowedusers', true));
+		}
+
 	}
 
 	/**
@@ -381,30 +414,35 @@
 		if (!$project)
 			return;
 
-		$config = GitPHP_Config::GetInstance();
-
-		if ($config->HasKey('cloneurl')) {
-			$project->SetCloneUrl(GitPHP_Util::AddSlash($config->GetValue('cloneurl'), false) . $project->GetProject());
-		}
-
-		if ($config->HasKey('pushurl')) {
-			$project->SetPushUrl(GitPHP_Util::AddSlash($config->GetValue('pushurl'), false) . $project->GetProject());
-		}
-
-		if ($config->HasKey('bugpattern')) {
-			$project->SetBugPattern($config->GetValue('bugpattern'));
-		}
-
-		if ($config->HasKey('bugurl')) {
-			$project->SetBugUrl($config->GetValue('bugurl'));
-		}
-
-		if ($config->HasKey('compat')) {
-			$project->SetCompat($config->GetValue('compat'));
-		}
-
-		if ($config->HasKey('uniqueabbrev')) {
-			$project->SetUniqueAbbreviation($config->GetValue('uniqueabbrev'));
+		if (!$this->config)
+			return;
+
+		if ($this->config->GetValue('cloneurl')) {
+			$project->SetCloneUrl(GitPHP_Util::AddSlash($this->config->GetValue('cloneurl'), false) . $project->GetProject());
+		}
+
+		if ($this->config->GetValue('pushurl')) {
+			$project->SetPushUrl(GitPHP_Util::AddSlash($this->config->GetValue('pushurl'), false) . $project->GetProject());
+		}
+
+		if ($this->config->GetValue('bugpattern')) {
+			$project->SetBugPattern($this->config->GetValue('bugpattern'));
+		}
+
+		if ($this->config->GetValue('bugurl')) {
+			$project->SetBugUrl($this->config->GetValue('bugurl'));
+		}
+
+		if ($this->config->HasKey('compat')) {
+			$project->SetCompat($this->config->GetValue('compat'));
+		}
+
+		if ($this->config->HasKey('uniqueabbrev')) {
+			$project->SetUniqueAbbreviation($this->config->GetValue('uniqueabbrev'));
+		}
+
+		if ($this->config->GetValue('abbreviateurl')) {
+			$project->SetUniqueAbbreviation(true);
 		}
 	}
 
@@ -420,6 +458,19 @@
 		$this->Sort();
 
 		$this->ApplySettings();
+	}
+
+	/**
+	 * Filter projects by user access
+	 *
+	 * @param string $username username
+	 */
+	public function FilterByUser($username)
+	{
+		foreach ($this->projects as $path => $project) {
+			if (!$project->UserCanAccess($username))
+				unset($this->projects[$path]);
+		}
 	}
 
 	/**
@@ -573,6 +624,9 @@
 		if (isset($projData['website']) && is_string($projData['website'])) {
 			$project->SetWebsite($projData['website']);
 		}
+		if (!empty($projData['allowedusers'])) {
+			$project->SetAllowedUsers($projData['allowedusers']);
+		}
 	}
 
 	/**
@@ -580,7 +634,7 @@
 	 *
 	 * @param array $settings the array of settings
 	 */
-	public function SetSettings($settings)
+	public function SetProjectSettings($settings)
 	{
 		if ((!$settings) || (count($settings) < 1))
 			return;

comments