Add specific exception for disabled search
Add specific exception for disabled search

--- a/include/controller/Controller_Message.class.php
+++ b/include/controller/Controller_Message.class.php
@@ -154,6 +154,18 @@
 			return 'Project is required';
 		}
 
+		if ($exception instanceof GitPHP_SearchDisabledException) {
+			if ($exception->FileSearch) {
+				if ($this->resource)
+					return $this->resource->translate('File search has been disabled');
+				return 'File search has been disabled';
+			} else {
+				if ($this->resource)
+					return $this->resource->translate('Search has been disabled');
+				return 'Search has been disabled';
+			}
+		}
+
 		return $exception->getMessage();
 	}
 

--- a/include/controller/Controller_Search.class.php
+++ b/include/controller/Controller_Search.class.php
@@ -46,7 +46,7 @@
 		parent::__construct();
 
 		if (!$this->config->GetValue('search')) {
-			throw new GitPHP_MessageException(__('Search has been disabled'), true);
+			throw new GitPHP_SearchDisabledException();
 		}
 	}
 
@@ -97,7 +97,7 @@
 
 		if ($this->params['searchtype'] == GitPHP_Controller_Search::FileSearch) {
 			if (!$this->config->GetValue('filesearch')) {
-				throw new GitPHP_MessageException(__('File search has been disabled'), true);
+				throw new GitPHP_SearchDisabledException(true);
 			}
 
 		}

--- /dev/null
+++ b/include/exception/SearchDisabledException.class.php
@@ -1,1 +1,38 @@
+<?php
+/**
+ * Custom exception when trying to perform a disabled search
+ *
+ * @author Christopher Han <xiphux@gmail.com>
+ * @copyright Copyright (c) 2012 Christopher Han
+ * @package GitPHP
+ * @subpackage Exception
+ */
+class GitPHP_SearchDisabledException extends GitPHP_MessageException
+{
+	/**
+	 * Whether this exception is for file searching
+	 *
+	 * @var boolean
+	 */
+	public $FileSearch;
 
+	/**
+	 * Constructor
+	 *
+	 * @param boolean $fileSearch true if filesearch
+	 * @param string $message message
+	 * @param int $code code
+	 */
+	public function __construct($fileSearch = false, $message = '', $code = 0)
+	{
+		$this->FileSearch = $fileSearch;
+		if (empty($message)) {
+			if ($fileSearch)
+				$message = 'File search has been disabled';
+			else
+				$message = 'Search has been disabled';
+		}
+		parent::__construct($message, true, 200, $code);
+	}
+}
+

comments