Inject cache instance into manager instead of relying on singleton
Inject cache instance into manager instead of relying on singleton

--- a/include/git/GitObjectManager.class.php
+++ b/include/git/GitObjectManager.class.php
@@ -17,6 +17,13 @@
 	protected $project;
 
 	/**
+	 * Cache instance
+	 *
+	 * @var GitPHP_Cache
+	 */
+	protected $cache = null;
+
+	/**
 	 * Constructor
 	 *
 	 * @param GitPHP_Project $project project
@@ -30,6 +37,26 @@
 	}
 
 	/**
+	 * Gets the cache instance being used
+	 *
+	 * @return GitPHP_Cache|null cache instance
+	 */
+	public function GetCache()
+	{
+		return $this->cache;
+	}
+
+	/**
+	 * Set the cache instance to use
+	 *
+	 * @param GitPHP_Cache|null $cache cache instance
+	 */
+	public function SetCache($cache)
+	{
+		$this->cache = $cache;
+	}
+
+	/**
 	 * Get a commit
 	 *
 	 * @param string $hash commit hash
@@ -46,7 +73,9 @@
 
 		if (!$commit) {
 
-			$commit = GitPHP_Cache::GetObjectCacheInstance()->Get($key);
+			if ($this->cache) {
+				$commit = $this->cache->Get($key);
+			}
 
 			if ($commit) {
 				$commit->SetProject($this->project);
@@ -81,7 +110,10 @@
 		$tagObj = $memoryCache->Get($key);
 
 		if (!$tagObj) {
-			$tagObj = GitPHP_Cache::GetObjectCacheInstance()->Get($key);
+
+			if ($this->cache) {
+				$tagObj = $this->cache->Get($key);
+			}
 
 			if ($tagObj) {
 				$tagObj->SetProject($this->project);
@@ -139,7 +171,10 @@
 		$blob = $memoryCache->Get($key);
 
 		if (!$blob) {
-			$blob = GitPHP_Cache::GetObjectCacheInstance()->Get($key);
+
+			if ($this->cache) {
+				$blob = $this->cache->Get($key);
+			}
 
 			if ($blob) {
 				$blob->SetProject($this->project);
@@ -172,7 +207,10 @@
 		$tree = $memoryCache->Get($key);
 
 		if (!$tree) {
-			$tree = GitPHP_Cache::GetObjectCacheInstance()->Get($key);
+
+			if ($this->cache) {
+				$tree = $this->cache->Get($key);
+			}
 
 			if ($tree) {
 				$tree->SetProject($this->project);
@@ -199,7 +237,7 @@
 	public function GetFileDiff($fromHash, $toHash = '')
 	{
 		$fileDiff = new GitPHP_FileDiff($this->project, $fromHash, $toHash);
-		$fileDiff->SetCache(GitPHP_Cache::GetObjectCacheInstance());
+		$fileDiff->SetCache($this->cache);
 		return $fileDiff;
 	}
 
@@ -217,10 +255,13 @@
 		if ($changeType !== GitPHP_Observer_Interface::CacheableDataChange)
 			return;
 
+		if (!$this->cache)
+			return;
+
 		if (!(($object instanceof GitPHP_Observable_Interface) && ($object instanceof GitPHP_Cacheable_Interface)))
 			return;
 
-		GitPHP_Cache::GetObjectCacheInstance()->Set($object->GetCacheKey(), $object);
+		$this->cache->Set($object->GetCacheKey(), $object);
 	}
 
 }

--- a/include/git/projectlist/ProjectListArray.class.php
+++ b/include/git/projectlist/ProjectListArray.class.php
@@ -102,6 +102,8 @@
 
 		$projectObj = new GitPHP_Project($this->projectRoot, $proj);
 
+		$this->InjectProjectDependencies($projectObj);
+
 		$this->ApplyGlobalConfig($projectObj);
 
 		$this->ApplyGitConfig($projectObj);

--- a/include/git/projectlist/ProjectListArrayLegacy.class.php
+++ b/include/git/projectlist/ProjectListArrayLegacy.class.php
@@ -80,6 +80,8 @@
 
 		$projectObj = new GitPHP_Project($this->projectRoot, $proj);
 
+		$this->InjectProjectDependencies($projectObj);
+
 		$this->ApplyGlobalConfig($projectObj);
 
 		$this->ApplyGitConfig($projectObj);

--- a/include/git/projectlist/ProjectListBase.class.php
+++ b/include/git/projectlist/ProjectListBase.class.php
@@ -137,6 +137,8 @@
 	{
 		$project = new GitPHP_Project(GitPHP_Util::AddSlash($this->projectRoot), $proj);
 
+		$this->InjectProjectDependencies($project);
+
 		$this->ApplyGlobalConfig($project);
 
 		$this->ApplyGitConfig($project);
@@ -146,6 +148,19 @@
 		}
 
 		return $project;
+	}
+
+	/**
+	 * Inject project dependency objects
+	 *
+	 * @param GitPHP_Project $project project object
+	 */
+	protected function InjectProjectDependencies($project)
+	{
+		if (!$project)
+			return;
+
+		$project->GetObjectManager()->SetCache(GitPHP_Cache::GetObjectCacheInstance());
 	}
 
 	/**

--- a/include/git/projectlist/ProjectListDirectory.class.php
+++ b/include/git/projectlist/ProjectListDirectory.class.php
@@ -99,6 +99,8 @@
 
 			$project = new GitPHP_Project($this->projectRoot, $proj);
 
+			$this->InjectProjectDependencies($project);
+
 			$category = trim(dirname($proj));
 			if (!(empty($category) || (strpos($category, '.') === 0))) {
 				$project->SetCategory($category);

--- a/include/git/projectlist/ProjectListFile.class.php
+++ b/include/git/projectlist/ProjectListFile.class.php
@@ -94,6 +94,8 @@
 
 		$projectObj = new GitPHP_Project($this->projectRoot, $proj);
 
+		$this->InjectProjectDependencies($projectObj);
+
 		$this->ApplyGlobalConfig($projectObj);
 
 		$this->ApplyGitConfig($projectObj);

--- a/include/git/projectlist/ProjectListScmManager.class.php
+++ b/include/git/projectlist/ProjectListScmManager.class.php
@@ -99,6 +99,8 @@
 
 		$projectObj = new GitPHP_Project($this->projectRoot, $proj);
 
+		$this->InjectProjectDependencies($projectObj);
+
 		$this->ApplyGlobalConfig($projectObj);
 
 		$this->ApplyGitConfig($projectObj);

comments