Don't hold project reference in controller
Don't hold project reference in controller

--- a/include/controller/ControllerBase.class.php
+++ b/include/controller/ControllerBase.class.php
@@ -96,10 +96,11 @@
 		}
 
 		if (isset($_GET['p'])) {
-			$this->project = GitPHP_ProjectList::GetInstance()->GetProject(str_replace(chr(0), '', $_GET['p']));
-			if (!$this->project) {
+			$project = GitPHP_ProjectList::GetInstance()->GetProject(str_replace(chr(0), '', $_GET['p']));
+			if (!$project) {
 				throw new GitPHP_MessageException(sprintf(__('Invalid project %1$s'), $_GET['p']), true);
 			}
+			$this->project = $project->GetProject();
 		}
 
 		if (isset($_GET['s']))
@@ -111,6 +112,21 @@
 	}
 
 	/**
+	 * GetProject
+	 *
+	 * Gets the project for this controller
+	 *
+	 * @access public
+	 * @return mixed project
+	 */
+	public function GetProject()
+	{
+		if ($this->project)
+			return GitPHP_ProjectList::GetInstance()->GetProject($this->project);
+		return null;
+	}
+
+	/**
 	 * GetTemplate
 	 *
 	 * Gets the template for this controller
@@ -151,7 +167,7 @@
 			unset($projList);
 		}
 		if ($this->project && $projectKeys) {
-			$cacheKeyPrefix .= '|' . sha1($this->project->GetProject());
+			$cacheKeyPrefix .= '|' . sha1($this->project);
 		}
 		
 		return $cacheKeyPrefix;
@@ -271,7 +287,7 @@
 		$this->tpl->assign('action', $this->GetName());
 		$this->tpl->assign('actionlocal', $this->GetName(true));
 		if ($this->project)
-			$this->tpl->assign('project', $this->project);
+			$this->tpl->assign('project', $this->GetProject());
 		if (GitPHP_Config::GetInstance()->GetValue('search', true))
 			$this->tpl->assign('enablesearch', true);
 		if (GitPHP_Config::GetInstance()->GetValue('filesearch', true))
@@ -371,11 +387,11 @@
 		if (!$this->project)
 			return;
 
-		$epoch = $this->project->GetEpoch();
+		$epoch = $this->GetProject()->GetEpoch();
 		if (empty($epoch))
 			return;
 
-		$age = $this->project->GetAge();
+		$age = $this->GetProject()->GetAge();
 
 		$this->tpl->clearCache(null, $this->GetCacheKeyPrefix(), null, $age);
 		$this->tpl->clearCache('projectlist.tpl', $this->GetCacheKeyPrefix(false), null, $age);

--- a/include/controller/Controller_Blame.class.php
+++ b/include/controller/Controller_Blame.class.php
@@ -114,17 +114,17 @@
 	 */
 	protected function LoadData()
 	{
-		$head = $this->project->GetHeadCommit();
+		$head = $this->GetProject()->GetHeadCommit();
 		$this->tpl->assign('head', $head);
 
-		$commit = $this->project->GetCommit($this->params['hashbase']);
+		$commit = $this->GetProject()->GetCommit($this->params['hashbase']);
 		$this->tpl->assign('commit', $commit);
 
 		if ((!isset($this->params['hash'])) && (isset($this->params['file']))) {
 			$this->params['hash'] = $commit->PathToHash($this->params['file']);
 		}
 		
-		$blob = $this->project->GetBlob($this->params['hash']);
+		$blob = $this->GetProject()->GetBlob($this->params['hash']);
 		if ($this->params['file'])
 			$blob->SetPath($this->params['file']);
 		$blob->SetCommit($commit);

--- a/include/controller/Controller_Blob.class.php
+++ b/include/controller/Controller_Blob.class.php
@@ -126,11 +126,11 @@
 				$mime = null;
 				if (GitPHP_Config::GetInstance()->GetValue('filemimetype', true)) {
 					if ((!isset($this->params['hash'])) && (isset($this->params['file']))) {
-						$commit = $this->project->GetCommit($this->params['hashbase']);
+						$commit = $this->GetProject()->GetCommit($this->params['hashbase']);
 						$this->params['hash'] = $commit->PathToHash($this->params['file']);
 					}
 
-					$blob = $this->project->GetBlob($this->params['hash']);
+					$blob = $this->GetProject()->GetBlob($this->params['hash']);
 					$blob->SetPath($this->params['file']);
 
 					$mime = $blob->FileMime();
@@ -161,14 +161,14 @@
 	 */
 	protected function LoadData()
 	{
-		$commit = $this->project->GetCommit($this->params['hashbase']);
+		$commit = $this->GetProject()->GetCommit($this->params['hashbase']);
 		$this->tpl->assign('commit', $commit);
 
 		if ((!isset($this->params['hash'])) && (isset($this->params['file']))) {
 			$this->params['hash'] = $commit->PathToHash($this->params['file']);
 		}
 
-		$blob = $this->project->GetBlob($this->params['hash']);
+		$blob = $this->GetProject()->GetBlob($this->params['hash']);
 		if (!empty($this->params['file']))
 			$blob->SetPath($this->params['file']);
 		$blob->SetCommit($commit);
@@ -178,7 +178,7 @@
 			return;
 		}
 
-		$head = $this->project->GetHeadCommit();
+		$head = $this->GetProject()->GetHeadCommit();
 		$this->tpl->assign('head', $head);
 
 		$this->tpl->assign('tree', $commit->GetTree());

--- a/include/controller/Controller_Blobdiff.class.php
+++ b/include/controller/Controller_Blobdiff.class.php
@@ -132,7 +132,7 @@
 		if (isset($this->params['file']))
 			$this->tpl->assign('file', $this->params['file']);
 
-		$filediff = new GitPHP_FileDiff($this->project, $this->params['hashparent'], $this->params['hash']);
+		$filediff = new GitPHP_FileDiff($this->GetProject(), $this->params['hashparent'], $this->params['hash']);
 		$this->tpl->assign('filediff', $filediff);
 
 		if (isset($this->params['plain']) && ($this->params['plain'] === true)) {
@@ -143,15 +143,15 @@
 			$this->tpl->assign('sidebyside', true);
 		}
 
-		$commit = $this->project->GetCommit($this->params['hashbase']);
+		$commit = $this->GetProject()->GetCommit($this->params['hashbase']);
 		$this->tpl->assign('commit', $commit);
 
-		$blobparent = $this->project->GetBlob($this->params['hashparent']);
+		$blobparent = $this->GetProject()->GetBlob($this->params['hashparent']);
 		$blobparent->SetCommit($commit);
 		$blobparent->SetPath($this->params['file']);
 		$this->tpl->assign('blobparent', $blobparent);
 
-		$blob = $this->project->GetBlob($this->params['hash']);
+		$blob = $this->GetProject()->GetBlob($this->params['hash']);
 		$blob->SetPath($this->params['file']);
 		$this->tpl->assign('blob', $blob);
 

--- a/include/controller/Controller_Commit.class.php
+++ b/include/controller/Controller_Commit.class.php
@@ -110,7 +110,7 @@
 	 */
 	protected function LoadData()
 	{
-		$commit = $this->project->GetCommit($this->params['hash']);
+		$commit = $this->GetProject()->GetCommit($this->params['hash']);
 		$this->tpl->assign('commit', $commit);
 		$this->tpl->assign('tree', $commit->GetTree());
 		$treediff = $commit->DiffToParent();

--- a/include/controller/Controller_Commitdiff.class.php
+++ b/include/controller/Controller_Commitdiff.class.php
@@ -130,7 +130,7 @@
 	 */
 	protected function LoadData()
 	{
-		$co = $this->project->GetCommit($this->params['hash']);
+		$co = $this->GetProject()->GetCommit($this->params['hash']);
 		$this->tpl->assign('commit', $co);
 
 		if (isset($this->params['hashparent'])) {
@@ -141,7 +141,7 @@
 			$this->tpl->assign('sidebyside', true);
 		}
 
-		$treediff = new GitPHP_TreeDiff($this->project, $this->params['hash'], (isset($this->params['hashparent']) ? $this->params['hashparent'] : ''));
+		$treediff = new GitPHP_TreeDiff($this->GetProject(), $this->params['hash'], (isset($this->params['hashparent']) ? $this->params['hashparent'] : ''));
 		$this->tpl->assign('treediff', $treediff);
 	}
 

--- a/include/controller/Controller_Feed.class.php
+++ b/include/controller/Controller_Feed.class.php
@@ -141,7 +141,7 @@
 	 */
 	protected function LoadData()
 	{
-		$log = $this->project->GetLog('HEAD', GITPHP_FEED_ITEMS);
+		$log = $this->GetProject()->GetLog('HEAD', GITPHP_FEED_ITEMS);
 
 		$entries = count($log);
 

--- a/include/controller/Controller_Heads.class.php
+++ b/include/controller/Controller_Heads.class.php
@@ -98,10 +98,10 @@
 	 */
 	protected function LoadData()
 	{
-		$head = $this->project->GetHeadCommit();
+		$head = $this->GetProject()->GetHeadCommit();
 		$this->tpl->assign("head",$head);
 
-		$headlist = $this->project->GetHeads();
+		$headlist = $this->GetProject()->GetHeads();
 		if (isset($headlist) && (count($headlist) > 0)) {
 			$this->tpl->assign("headlist",$headlist);
 		}

--- a/include/controller/Controller_History.class.php
+++ b/include/controller/Controller_History.class.php
@@ -105,12 +105,12 @@
 	 */
 	protected function LoadData()
 	{
-		$co = $this->project->GetCommit($this->params['hash']);
+		$co = $this->GetProject()->GetCommit($this->params['hash']);
 		$this->tpl->assign('commit', $co);
 		$this->tpl->assign('tree', $co->GetTree());
 
 		$blobhash = $co->PathToHash($this->params['file']);
-		$blob = $this->project->GetBlob($blobhash);
+		$blob = $this->GetProject()->GetBlob($blobhash);
 		$blob->SetCommit($co);
 		$blob->SetPath($this->params['file']);
 		$this->tpl->assign('blob', $blob);

--- a/include/controller/Controller_Log.class.php
+++ b/include/controller/Controller_Log.class.php
@@ -117,11 +117,11 @@
 	 */
 	protected function LoadData()
 	{
-		$this->tpl->assign('commit', $this->project->GetCommit($this->params['hash']));
-		$this->tpl->assign('head', $this->project->GetHeadCommit());
+		$this->tpl->assign('commit', $this->GetProject()->GetCommit($this->params['hash']));
+		$this->tpl->assign('head', $this->GetProject()->GetHeadCommit());
 		$this->tpl->assign('page',$this->params['page']);
 
-		$revlist = $this->project->GetLog($this->params['hash'], 101, ($this->params['page'] * 100));
+		$revlist = $this->GetProject()->GetLog($this->params['hash'], 101, ($this->params['page'] * 100));
 		if ($revlist) {
 			if (count($revlist) > 100) {
 				$this->tpl->assign('hasmorerevs', true);
@@ -131,7 +131,7 @@
 		}
 
 		if (isset($this->params['mark'])) {
-			$this->tpl->assign('mark', $this->project->GetCommit($this->params['mark']));
+			$this->tpl->assign('mark', $this->GetProject()->GetCommit($this->params['mark']));
 		}
 	}
 

--- a/include/controller/Controller_Project.class.php
+++ b/include/controller/Controller_Project.class.php
@@ -97,9 +97,9 @@
 	 */
 	protected function LoadData()
 	{
-		$this->tpl->assign('head', $this->project->GetHeadCommit());
+		$this->tpl->assign('head', $this->GetProject()->GetHeadCommit());
 
-		$revlist = $this->project->GetLog('HEAD', 17);
+		$revlist = $this->GetProject()->GetLog('HEAD', 17);
 		if ($revlist) {
 			if (count($revlist) > 16) {
 				$this->tpl->assign('hasmorerevs', true);
@@ -108,7 +108,7 @@
 			$this->tpl->assign('revlist', $revlist);
 		}
 
-		$taglist = $this->project->GetTags(17);
+		$taglist = $this->GetProject()->GetTags(17);
 		if ($taglist) {
 			if (count($taglist) > 16) {
 				$this->tpl->assign('hasmoretags', true);
@@ -117,7 +117,7 @@
 			$this->tpl->assign('taglist', $taglist);
 		}
 
-		$headlist = $this->project->GetHeads(17);
+		$headlist = $this->GetProject()->GetHeads(17);
 		if ($headlist) {
 			if (count($headlist) > 17) {
 				$this->tpl->assign('hasmoreheads', true);

--- a/include/controller/Controller_Search.class.php
+++ b/include/controller/Controller_Search.class.php
@@ -137,7 +137,7 @@
 	 */
 	protected function LoadData()
 	{
-		$co = $this->project->GetCommit($this->params['hash']);
+		$co = $this->GetProject()->GetCommit($this->params['hash']);
 		$this->tpl->assign('commit', $co);
 
 		$results = array();
@@ -145,15 +145,15 @@
 			switch ($this->params['searchtype']) {
 
 				case GITPHP_SEARCH_COMMIT:
-					$results = $this->project->SearchCommit($this->params['search'], $co->GetHash(), 101, ($this->params['page'] * 100));
+					$results = $this->GetProject()->SearchCommit($this->params['search'], $co->GetHash(), 101, ($this->params['page'] * 100));
 					break;
 
 				case GITPHP_SEARCH_AUTHOR:
-					$results = $this->project->SearchAuthor($this->params['search'], $co->GetHash(), 101, ($this->params['page'] * 100));
+					$results = $this->GetProject()->SearchAuthor($this->params['search'], $co->GetHash(), 101, ($this->params['page'] * 100));
 					break;
 
 				case GITPHP_SEARCH_COMMITTER:
-					$results = $this->project->SearchCommitter($this->params['search'], $co->GetHash(), 101, ($this->params['page'] * 100));
+					$results = $this->GetProject()->SearchCommitter($this->params['search'], $co->GetHash(), 101, ($this->params['page'] * 100));
 					break;
 				case GITPHP_SEARCH_FILE:
 					$results = $co->SearchFiles($this->params['search'], 101, ($this->params['page'] * 100));

--- a/include/controller/Controller_Snapshot.class.php
+++ b/include/controller/Controller_Snapshot.class.php
@@ -39,10 +39,11 @@
 	public function __construct()
 	{
 		if (isset($_GET['p'])) {
-			$this->project = GitPHP_ProjectList::GetInstance()->GetProject(str_replace(chr(0), '', $_GET['p']));
-			if (!$this->project) {
+			$project = GitPHP_ProjectList::GetInstance()->GetProject(str_replace(chr(0), '', $_GET['p']));
+			if (!$project) {
 				throw new GitPHP_MessageException(sprintf(__('Invalid project %1$s'), $_GET['p']), true);
 			}
+			$this->project = $project->GetProject();
 		}
 
 		if (!$this->project) {
@@ -125,7 +126,7 @@
 	 */
 	protected function LoadHeaders()
 	{
-		$this->archive = new GitPHP_Archive($this->project, null, $this->params['format'], (isset($this->params['path']) ? $this->params['path'] : ''), (isset($this->params['prefix']) ? $this->params['prefix'] : ''));
+		$this->archive = new GitPHP_Archive($this->GetProject(), null, $this->params['format'], (isset($this->params['path']) ? $this->params['path'] : ''), (isset($this->params['prefix']) ? $this->params['prefix'] : ''));
 
 		switch ($this->archive->GetFormat()) {
 			case GITPHP_COMPRESS_TAR:
@@ -159,9 +160,9 @@
 		$commit = null;
 
 		if (!isset($this->params['hash']))
-			$commit = $this->project->GetHeadCommit();
+			$commit = $this->GetProject()->GetHeadCommit();
 		else
-			$commit = $this->project->GetCommit($this->params['hash']);
+			$commit = $this->GetProject()->GetCommit($this->params['hash']);
 
 		$this->archive->SetObject($commit);
 	}

--- a/include/controller/Controller_Tag.class.php
+++ b/include/controller/Controller_Tag.class.php
@@ -109,10 +109,10 @@
 	 */
 	protected function LoadData()
 	{
-		$head = $this->project->GetHeadCommit();
+		$head = $this->GetProject()->GetHeadCommit();
 		$this->tpl->assign('head', $head);
 
-		$tag = $this->project->GetTag($this->params['hash']);
+		$tag = $this->GetProject()->GetTag($this->params['hash']);
 
 		$this->tpl->assign("tag", $tag);
 	}

--- a/include/controller/Controller_Tags.class.php
+++ b/include/controller/Controller_Tags.class.php
@@ -98,10 +98,10 @@
 	 */
 	protected function LoadData()
 	{
-		$head = $this->project->GetHeadCommit();
+		$head = $this->GetProject()->GetHeadCommit();
 		$this->tpl->assign("head",$head);
 
-		$taglist = $this->project->GetTags();
+		$taglist = $this->GetProject()->GetTags();
 		if (isset($taglist) && (count($taglist) > 0)) {
 			$this->tpl->assign("taglist",$taglist);
 		}

--- a/include/controller/Controller_Tree.class.php
+++ b/include/controller/Controller_Tree.class.php
@@ -121,7 +121,7 @@
 			throw new Exception('Hashbase is required');
 		}
 
-		$commit = $this->project->GetCommit($this->params['hashbase']);
+		$commit = $this->GetProject()->GetCommit($this->params['hashbase']);
 
 		$this->tpl->assign('commit', $commit);
 
@@ -133,7 +133,7 @@
 			}
 		}
 
-		$tree = $this->project->GetTree($this->params['hash']);
+		$tree = $this->GetProject()->GetTree($this->params['hash']);
 		if (!$tree->GetCommit()) {
 			$tree->SetCommit($commit);
 		}

comments