Indefero

Indefero Git Source Tree

Root/src/IDF/Views/Source/Precondition.php

1<?php
2/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3/*
4# ***** BEGIN LICENSE BLOCK *****
5# This file is part of InDefero, an open source project management application.
6# Copyright (C) 2010 Céondo Ltd and contributors.
7#
8# InDefero is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation; either version 2 of the License, or
11# (at your option) any later version.
12#
13# InDefero is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with this program; if not, write to the Free Software
20# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21#
22# ***** END LICENSE BLOCK ***** */
23
24class IDF_Views_Source_Precondition
25{
26 /**
27 * Ensures that the configured SCM for the project is available
28 *
29 * @param $request
30 * @return true | Pluf_HTTP_Response_Redirect
31 */
32 static public function scmAvailable($request)
33 {
34 $scm = IDF_Scm::get($request->project);
35 if (!$scm->isAvailable()) {
36 $url = Pluf_HTTP_URL_urlForView('IDF_Views_Source::help',
37 array($request->project->shortname));
38 return new Pluf_HTTP_Response_Redirect($url);
39 }
40 return true;
41 }
42
43 /**
44 * Validates the revision given in the URL path and acts accordingly
45 *
46 * @param $request
47 * @return true | Pluf_HTTP_Response_Redirect
48 * @throws Exception
49 */
50 static public function revisionValid($request)
51 {
52 list($url_info, $url_matches) = $request->view;
53 list(, $project, $commit) = $url_matches;
54
55 $scm = IDF_Scm::get($request->project);
56 $res = $scm->validateRevision($commit);
57 switch ($res) {
58 case IDF_Scm::REVISION_VALID:
59 return true;
60 case IDF_Scm::REVISION_INVALID:
61 $url = Pluf_HTTP_URL_urlForView('IDF_Views_Source::invalidRevision',
62 array($request->project->shortname, $commit));
63 return new Pluf_HTTP_Response_Redirect($url);
64 case IDF_Scm::REVISION_AMBIGUOUS:
65 $url = Pluf_HTTP_URL_urlForView('IDF_Views_Source::disambiguateRevision',
66 array($request->project->shortname,
67 $commit,
68 $url_info['model'].'::'.$url_info['method']));
69 return new Pluf_HTTP_Response_Redirect($url);
70 default:
71 throw new Exception('unknown validation result: '. $res);
72 }
73 }
74}
75

Archive Download this file