Add specific exception for invalid directory in config
Add specific exception for invalid directory in config

--- a/include/controller/Controller_Message.class.php
+++ b/include/controller/Controller_Message.class.php
@@ -202,6 +202,12 @@
 			return 'The Memcached or Memcache PHP extension is required for Memcache support';
 		}
 
+		if ($exception instanceof GitPHP_InvalidDirectoryConfigurationException) {
+			if ($this->resource)
+				return sprintf($this->resource->translate('%1$s is not a directory'), $exception->Directory);
+			return sprintf('%1$s is not a directory', $exception->Directory);
+		}
+
 		return $exception->getMessage();
 	}
 

--- /dev/null
+++ b/include/exception/InvalidDirectoryConfigurationException.class.php
@@ -1,1 +1,34 @@
+<?php
+/** 
+ * Custom exception when an invalid directory is configured
+ *
+ * @author Christopher Han <xiphux@gmail.com>
+ * @copyright Copyright (c) 2012 Christopher Han
+ * @package GitPHP
+ * @subpackage Exception
+ */
+class GitPHP_InvalidDirectoryConfigurationException extends GitPHP_MessageException
+{
+	/**
+	 * Directory
+	 *
+	 * @var string
+	 */
+	public $Directory;
 
+	/**
+	 * Constructor
+	 *
+	 * @param string $dir directory
+	 * @param string $message message
+	 * @param int $code exception code
+	 */
+	public function __construct($dir, $message = '', $code = 0)
+	{
+		$this->Directory = $dir;
+		if (empty($message))
+			$message = sprintf('%1$s is not a directory', $dir);
+		parent::__construct($message, true, 500, $code);
+	}
+}
+

--- a/include/git/projectlist/ProjectListBase.class.php
+++ b/include/git/projectlist/ProjectListBase.class.php
@@ -113,7 +113,7 @@
 			throw new GitPHP_MissingProjectrootException();
 		}
 		if (!is_dir($this->projectRoot)) {
-			throw new GitPHP_MessageException(sprintf(__('%1$s is not a directory'), $this->projectRoot), true, 500);
+			throw new GitPHP_InvalidDirectoryConfigurationException($this->projectRoot);
 		}
 
 		$this->memoryCache = new GitPHP_MemoryCache(GitPHP_Config::GetInstance()->GetValue('objectmemory'));

comments