From 85df9e5ab2fb6789f34d01b5625da4f31f91bf67 Mon Sep 17 00:00:00 2001 From: Thomas Keller Date: Thu, 2 Sep 2010 12:22:59 +0000 Subject: [PATCH] move IDF_View_Source_Precondition into a separate class file --- src/IDF/Views/Source.php | 53 ------------------- src/IDF/Views/Source/Precondition.php | 74 +++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 53 deletions(-) create mode 100644 src/IDF/Views/Source/Precondition.php diff --git a/src/IDF/Views/Source.php b/src/IDF/Views/Source.php index dcebdab..2d1b3f8 100644 --- a/src/IDF/Views/Source.php +++ b/src/IDF/Views/Source.php @@ -601,56 +601,3 @@ function IDF_Views_Source_ShortenString($string, $length) return substr($string, 0, $preflen).$ellipse. substr($string, -($length - $preflen - mb_strlen($ellipse))); } - -class IDF_Views_Source_Precondition -{ - /** - * Ensures that the configured SCM for the project is available - * - * @param $request - * @return true | Pluf_HTTP_Response_Redirect - */ - static public function scmAvailable($request) - { - $scm = IDF_Scm::get($request->project); - if (!$scm->isAvailable()) { - $url = Pluf_HTTP_URL_urlForView('IDF_Views_Source::help', - array($request->project->shortname)); - return new Pluf_HTTP_Response_Redirect($url); - } - return true; - } - - /** - * Validates the revision given in the URL path and acts accordingly - * - * @param $request - * @return true | Pluf_HTTP_Response_Redirect - * @throws Exception - */ - static public function revisionValid($request) - { - list($url_info, $url_matches) = $request->view; - list(, $project, $commit) = $url_matches; - - $scm = IDF_Scm::get($request->project); - $res = $scm->validateRevision($commit); - switch ($res) { - case IDF_Scm::REVISION_VALID: - return true; - case IDF_Scm::REVISION_INVALID: - $url = Pluf_HTTP_URL_urlForView('IDF_Views_Source::invalidRevision', - array($request->project->shortname, $commit)); - return new Pluf_HTTP_Response_Redirect($url); - case IDF_Scm::REVISION_AMBIGUOUS: - $url = Pluf_HTTP_URL_urlForView('IDF_Views_Source::disambiguateRevision', - array($request->project->shortname, - $commit, - $url_info['model'].'::'.$url_info['method'])); - return new Pluf_HTTP_Response_Redirect($url); - default: - throw new Exception('unknown validation result: '. $res); - } - } -} - diff --git a/src/IDF/Views/Source/Precondition.php b/src/IDF/Views/Source/Precondition.php new file mode 100644 index 0000000..39b6ab4 --- /dev/null +++ b/src/IDF/Views/Source/Precondition.php @@ -0,0 +1,74 @@ +project); + if (!$scm->isAvailable()) { + $url = Pluf_HTTP_URL_urlForView('IDF_Views_Source::help', + array($request->project->shortname)); + return new Pluf_HTTP_Response_Redirect($url); + } + return true; + } + + /** + * Validates the revision given in the URL path and acts accordingly + * + * @param $request + * @return true | Pluf_HTTP_Response_Redirect + * @throws Exception + */ + static public function revisionValid($request) + { + list($url_info, $url_matches) = $request->view; + list(, $project, $commit) = $url_matches; + + $scm = IDF_Scm::get($request->project); + $res = $scm->validateRevision($commit); + switch ($res) { + case IDF_Scm::REVISION_VALID: + return true; + case IDF_Scm::REVISION_INVALID: + $url = Pluf_HTTP_URL_urlForView('IDF_Views_Source::invalidRevision', + array($request->project->shortname, $commit)); + return new Pluf_HTTP_Response_Redirect($url); + case IDF_Scm::REVISION_AMBIGUOUS: + $url = Pluf_HTTP_URL_urlForView('IDF_Views_Source::disambiguateRevision', + array($request->project->shortname, + $commit, + $url_info['model'].'::'.$url_info['method'])); + return new Pluf_HTTP_Response_Redirect($url); + default: + throw new Exception('unknown validation result: '. $res); + } + } +}