Inject dependent classes into project class
Inject dependent classes into project class

--- a/include/git/GitObjectLoader.class.php
+++ b/include/git/GitObjectLoader.class.php
@@ -44,6 +44,16 @@
 	}
 
 	/**
+	 * Gets the project
+	 *
+	 * @return GitPHP_Project project
+	 */
+	public function GetProject()
+	{
+		return $this->project;
+	}
+
+	/**
 	 * Gets the raw content of an object
 	 *
 	 * @param string $hash object hash

--- a/include/git/GitObjectManager.class.php
+++ b/include/git/GitObjectManager.class.php
@@ -44,6 +44,16 @@
 	}
 
 	/**
+	 * Get project
+	 *
+	 * @return GitPHP_Project
+	 */
+	public function GetProject()
+	{
+		return $this->project;
+	}
+
+	/**
 	 * Gets the cache instance being used
 	 *
 	 * @return GitPHP_Cache|null cache instance

--- a/include/git/Project.class.php
+++ b/include/git/Project.class.php
@@ -790,14 +790,22 @@
 	 */
 	public function GetTagList()
 	{
-		if (!$this->tagList) {
-			$this->tagList = new GitPHP_TagList($this);
-			$this->tagList->SetCompat($this->GetCompat());
-		}
-
 		return $this->tagList;
 	}
 
+	/**
+	 * Sets the tag list
+	 *
+	 * @param GitPHP_TagList $tagList tag list
+	 */
+	public function SetTagList($tagList)
+	{
+		if ($tagList && ($tagList->GetProject() !== $this))
+			throw new Exception('Invalid taglist for this project');
+
+		$this->tagList = $tagList;
+	}
+
 /*}}}2*/
 
 /* head loading methods {{{2*/
@@ -809,14 +817,22 @@
 	 */
 	public function GetHeadList()
 	{
-		if (!$this->headList) {
-			$this->headList = new GitPHP_HeadList($this);
-			$this->headList->SetCompat($this->GetCompat());
-		}
-
 		return $this->headList;
 	}
 
+	/**
+	 * Sets the head list
+	 *
+	 * @param GitPHP_HeadList $headList head list
+	 */
+	public function SetHeadList($headList)
+	{
+		if ($headList && ($headList->GetProject() !== $this))
+			throw new Exception('Invalid headlist for this project');
+
+		$this->headList = $headList;
+	}
+
 /*}}}2*/
 
 /* object loader/manager methods {{{2*/
@@ -828,24 +844,43 @@
 	 */
 	public function GetObjectLoader()
 	{
-		if (!$this->objectLoader) {
-			$this->objectLoader = new GitPHP_GitObjectLoader($this);
-		}
-
 		return $this->objectLoader;
 	}
 
 	/**
+	 * Sets the git object loader for this project
+	 *
+	 * @param GitPHP_GitObjectLoader $objectLoader object loader
+	 */
+	public function SetObjectLoader($objectLoader)
+	{
+		if ($objectLoader && ($objectLoader->GetProject() !== $this))
+			throw new Exception('Invalid object loader for this project');
+
+		$this->objectLoader = $objectLoader;
+	}
+
+	/**
 	 * Get the git object manager for this project
 	 *
 	 * @return GitPHP_GitObjectManager
 	 */
 	public function GetObjectManager()
 	{
-		if (!$this->objectManager)
-			$this->objectManager = new GitPHP_GitObjectManager($this);
-
 		return $this->objectManager;
+	}
+
+	/**
+	 * Set the git object manager for this project
+	 *
+	 * @param GitPHP_GitObjectManager $objectManager object manager
+	 */
+	public function SetObjectManager($objectManager)
+	{
+		if ($objectManager && ($objectManager->GetProject() !== $this))
+			throw new Exception('Invalid object manager for this project');
+
+		$this->objectManager = $objectManager;
 	}
 
 /*}}}2*/

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

--- a/include/git/projectlist/ProjectListArrayLegacy.class.php
+++ b/include/git/projectlist/ProjectListArrayLegacy.class.php
@@ -80,8 +80,6 @@
 
 		$projectObj = new GitPHP_Project($this->projectRoot, $proj);
 
-		$this->InjectProjectDependencies($projectObj);
-
 		$this->ApplyGlobalConfig($projectObj);
 
 		$this->ApplyGitConfig($projectObj);
@@ -89,6 +87,8 @@
 		if ($projectCat != GitPHP_ProjectListArrayLegacy::NoCategory)
 			$projectObj->SetCategory($projectCat);
 
+		$this->InjectProjectDependencies($projectObj);
+
 		return $projectObj;
 	}
 

--- a/include/git/projectlist/ProjectListBase.class.php
+++ b/include/git/projectlist/ProjectListBase.class.php
@@ -210,8 +210,6 @@
 	{
 		$project = new GitPHP_Project(GitPHP_Util::AddSlash($this->projectRoot), $proj);
 
-		$this->InjectProjectDependencies($project);
-
 		$this->ApplyGlobalConfig($project);
 
 		$this->ApplyGitConfig($project);
@@ -220,6 +218,8 @@
 			$this->ApplyProjectSettings($project, $this->projectSettings[$proj]);
 		}
 
+		$this->InjectProjectDependencies($project);
+
 		return $project;
 	}
 
@@ -233,13 +233,29 @@
 		if (!$project)
 			return;
 
+		$compat = $project->GetCompat();
+
+		$headList = new GitPHP_HeadList($project);
+		$headList->SetCompat($compat);
+		$project->SetHeadList($headList);
+
+		$tagList = new GitPHP_TagList($project);
+		$tagList->SetCompat($compat);
+		$project->SetTagList($tagList);
+
+		if (!$compat) {
+			$loader = new GitPHP_GitObjectLoader($project);
+			$project->SetObjectLoader($loader);
+		}
+
+		$manager = new GitPHP_GitObjectManager($project);
 		if ($this->memoryCache) {
-			$project->GetObjectManager()->SetMemoryCache($this->memoryCache);
-		}
-
+			$manager->SetMemoryCache($this->memoryCache);
+		}
 		if ($this->cache) {
-			$project->GetObjectManager()->SetCache($this->cache);
-		}
+			$manager->SetCache($this->cache);
+		}
+		$project->SetObjectManager($manager);
 	}
 
 	/**

--- a/include/git/projectlist/ProjectListDirectory.class.php
+++ b/include/git/projectlist/ProjectListDirectory.class.php
@@ -99,8 +99,6 @@
 
 			$project = new GitPHP_Project($this->projectRoot, $proj);
 
-			$this->InjectProjectDependencies($project);
-
 			$category = trim(dirname($proj));
 			if (!(empty($category) || (strpos($category, '.') === 0))) {
 				$project->SetCategory($category);
@@ -119,6 +117,8 @@
 				$this->ApplyProjectSettings($project, $this->projectSettings[$proj]);
 			}
 
+			$this->InjectProjectDependencies($project);
+
 			return $project;
 
 		} catch (Exception $e) {

--- a/include/git/projectlist/ProjectListFile.class.php
+++ b/include/git/projectlist/ProjectListFile.class.php
@@ -94,8 +94,6 @@
 
 		$projectObj = new GitPHP_Project($this->projectRoot, $proj);
 
-		$this->InjectProjectDependencies($projectObj);
-
 		$this->ApplyGlobalConfig($projectObj);
 
 		$this->ApplyGitConfig($projectObj);
@@ -106,6 +104,8 @@
 		if ($this->projectSettings && isset($this->projectSettings[$proj])) {
 			$this->ApplyProjectSettings($projectObj, $this->projectSettings[$proj]);
 		}
+
+		$this->InjectProjectDependencies($projectObj);
 
 		return $projectObj;
 	}

--- a/include/git/projectlist/ProjectListScmManager.class.php
+++ b/include/git/projectlist/ProjectListScmManager.class.php
@@ -99,8 +99,6 @@
 
 		$projectObj = new GitPHP_Project($this->projectRoot, $proj);
 
-		$this->InjectProjectDependencies($projectObj);
-
 		$this->ApplyGlobalConfig($projectObj);
 
 		$this->ApplyGitConfig($projectObj);
@@ -116,6 +114,8 @@
 		if ($this->projectSettings && isset($this->projectSettings[$proj])) {
 			$this->ApplyProjectSettings($projectObj, $this->projectSettings[$proj]);
 		}
+
+		$this->InjectProjectDependencies($projectObj);
 
 		return $projectObj;
 	}

comments