Exemplo n.º 1
0
 /**
  * GetController
  *
  * Gets a controller for an action
  *
  * @access public
  * @static
  * @param string $action action
  * @return mixed controller object
  */
 public static function GetController($action)
 {
     $controller = null;
     switch ($action) {
         case 'search':
             require_once GITPHP_CONTROLLERDIR . 'Controller_Search.class.php';
             $controller = new GitPHP_Controller_Search();
             break;
         case 'commitdiff':
         case 'commitdiff_plain':
             require_once GITPHP_CONTROLLERDIR . 'Controller_Commitdiff.class.php';
             $controller = new GitPHP_Controller_Commitdiff();
             if ($action === 'commitdiff_plain') {
                 $controller->SetParam('plain', true);
             }
             break;
         case 'blobdiff':
         case 'blobdiff_plain':
             require_once GITPHP_CONTROLLERDIR . 'Controller_Blobdiff.class.php';
             $controller = new GitPHP_Controller_Blobdiff();
             if ($action === 'blobdiff_plain') {
                 $controller->SetParam('plain', true);
             }
             break;
         case 'history':
             require_once GITPHP_CONTROLLERDIR . 'Controller_History.class.php';
             $controller = new GitPHP_Controller_History();
             break;
         case 'shortlog':
         case 'log':
             require_once GITPHP_CONTROLLERDIR . 'Controller_Log.class.php';
             $controller = new GitPHP_Controller_Log();
             if ($action === 'shortlog') {
                 $controller->SetParam('short', true);
             }
             break;
         case 'snapshot':
             require_once GITPHP_CONTROLLERDIR . 'Controller_Snapshot.class.php';
             $controller = new GitPHP_Controller_Snapshot();
             break;
         case 'tree':
             require_once GITPHP_CONTROLLERDIR . 'Controller_Tree.class.php';
             $controller = new GitPHP_Controller_Tree();
             break;
         case 'tag':
             require_once GITPHP_CONTROLLERDIR . 'Controller_Tag.class.php';
             $controller = new GitPHP_Controller_Tag();
             break;
         case 'tags':
             require_once GITPHP_CONTROLLERDIR . 'Controller_Tags.class.php';
             $controller = new GitPHP_Controller_Tags();
             break;
         case 'heads':
             require_once GITPHP_CONTROLLERDIR . 'Controller_Heads.class.php';
             $controller = new GitPHP_Controller_Heads();
             break;
         case 'blame':
             require_once GITPHP_CONTROLLERDIR . 'Controller_Blame.class.php';
             $controller = new GitPHP_Controller_Blame();
             break;
         case 'blob':
         case 'blob_plain':
             require_once GITPHP_CONTROLLERDIR . 'Controller_Blob.class.php';
             $controller = new GitPHP_Controller_Blob();
             if ($action === 'blob_plain') {
                 $controller->SetParam('plain', true);
             }
             break;
         case 'atom':
         case 'rss':
             require_once GITPHP_CONTROLLERDIR . 'Controller_Feed.class.php';
             $controller = new GitPHP_Controller_Feed();
             if ($action == 'rss') {
                 $controller->SetParam('format', GITPHP_FEED_FORMAT_RSS);
             } else {
                 if ($action == 'atom') {
                     $controller->SetParam('format', GITPHP_FEED_FORMAT_ATOM);
                 }
             }
             break;
         case 'commit':
             require_once GITPHP_CONTROLLERDIR . 'Controller_Commit.class.php';
             $controller = new GitPHP_Controller_Commit();
             break;
         case 'summary':
             require_once GITPHP_CONTROLLERDIR . 'Controller_Project.class.php';
             $controller = new GitPHP_Controller_Project();
             break;
         case 'project_index':
             require_once GITPHP_CONTROLLERDIR . 'Controller_ProjectList.class.php';
             $controller = new GitPHP_Controller_ProjectList();
             $controller->SetParam('txt', true);
             break;
         case 'opml':
             require_once GITPHP_CONTROLLERDIR . 'Controller_ProjectList.class.php';
             $controller = new GitPHP_Controller_ProjectList();
             $controller->SetParam('opml', true);
             break;
         default:
             if (isset($_GET['p'])) {
                 require_once GITPHP_CONTROLLERDIR . 'Controller_Project.class.php';
                 $controller = new GitPHP_Controller_Project();
             } else {
                 require_once GITPHP_CONTROLLERDIR . 'Controller_ProjectList.class.php';
                 $controller = new GitPHP_Controller_ProjectList();
             }
     }
     return $controller;
 }
Exemplo n.º 2
0
 /**
  * Gets a controller for an action
  *
  * @return GitPHP_ControllerBase
  */
 public function GetController()
 {
     $params = $this->QueryVarArrayToParameterArray($_GET);
     if (!empty($_POST)) {
         $params = array_merge($params, $this->QueryVarArrayToParameterArray($_POST));
     }
     if (!empty($_GET['q'])) {
         $restparams = GitPHP_Router::ReadCleanUrl($_SERVER['REQUEST_URI']);
         if (count($restparams) > 0) {
             $params = array_merge($params, $restparams);
         }
     }
     $controller = null;
     $action = null;
     if (!empty($params['action'])) {
         $action = $params['action'];
     }
     switch ($action) {
         case 'search':
             $controller = new GitPHP_Controller_Search();
             break;
         case 'commitdiff':
         case 'commitdiff_plain':
             $controller = new GitPHP_Controller_Commitdiff();
             if ($action === 'commitdiff_plain') {
                 $controller->SetParam('output', 'plain');
             }
             break;
         case 'blobdiff':
         case 'blobdiff_plain':
             $controller = new GitPHP_Controller_Blobdiff();
             if ($action === 'blobdiff_plain') {
                 $controller->SetParam('output', 'plain');
             }
             break;
         case 'history':
             $controller = new GitPHP_Controller_History();
             break;
         case 'shortlog':
         case 'log':
             $controller = new GitPHP_Controller_Log();
             if ($action === 'shortlog') {
                 $controller->SetParam('short', true);
             }
             break;
         case 'snapshot':
             $controller = new GitPHP_Controller_Snapshot();
             break;
         case 'tree':
         case 'trees':
             $controller = new GitPHP_Controller_Tree();
             break;
         case 'tags':
             if (empty($params['tag'])) {
                 $controller = new GitPHP_Controller_Tags();
                 break;
             }
         case 'tag':
             $controller = new GitPHP_Controller_Tag();
             break;
         case 'heads':
             $controller = new GitPHP_Controller_Heads();
             break;
         case 'blame':
             $controller = new GitPHP_Controller_Blame();
             break;
         case 'blob':
         case 'blobs':
         case 'blob_plain':
             $controller = new GitPHP_Controller_Blob();
             if ($action === 'blob_plain') {
                 $controller->SetParam('output', 'plain');
             }
             break;
         case 'atom':
         case 'rss':
             $controller = new GitPHP_Controller_Feed();
             if ($action == 'rss') {
                 $controller->SetParam('format', GitPHP_Controller_Feed::RssFormat);
             } else {
                 if ($action == 'atom') {
                     $controller->SetParam('format', GitPHP_Controller_Feed::AtomFormat);
                 }
             }
             break;
         case 'commit':
         case 'commits':
             $controller = new GitPHP_Controller_Commit();
             break;
         case 'summary':
             $controller = new GitPHP_Controller_Project();
             break;
         case 'project_index':
         case 'projectindex':
             $controller = new GitPHP_Controller_ProjectList();
             $controller->SetParam('txt', true);
             break;
         case 'opml':
             $controller = new GitPHP_Controller_ProjectList();
             $controller->SetParam('opml', true);
             break;
         case 'login':
             $controller = new GitPHP_Controller_Login();
             if (!empty($_POST['username'])) {
                 $controller->SetParam('username', $_POST['username']);
             }
             if (!empty($_POST['password'])) {
                 $controller->SetParam('password', $_POST['password']);
             }
             break;
         case 'logout':
             $controller = new GitPHP_Controller_Logout();
             break;
         case 'graph':
         case 'graphs':
             //$controller = new GitPHP_Controller_Graph();
             //break;
         //$controller = new GitPHP_Controller_Graph();
         //break;
         case 'graphdata':
             //$controller = new GitPHP_Controller_GraphData();
             //break;
         //$controller = new GitPHP_Controller_GraphData();
         //break;
         default:
             if (!empty($params['project'])) {
                 $controller = new GitPHP_Controller_Project();
             } else {
                 $controller = new GitPHP_Controller_ProjectList();
             }
     }
     foreach ($params as $paramname => $paramval) {
         if ($paramname !== 'action') {
             $controller->SetParam($paramname, $paramval);
         }
     }
     $controller->SetRouter($this);
     return $controller;
 }