Example #1
0
 /**
  * Handles and routes any HTTP request using a subclass that can handles it. URLs are like:
  *
  *   index.php?page=Photo&id=1243&...
  *
  * But usually the user will see pretty URLs that rewrite to the above such as
  *
  *   photo/1243?...
  *
  * @access public
  * @param  array $get
  * @param  array $post
  * @param  array $files
  * @param  array $cookies
  * @param  array $server
  * @return void
  */
 public static function handleRequest($get, $post, $files, $cookies, $server)
 {
     try {
         $page = isset($get['page']) ? $get['page'] : 'mainPage';
         $dbIsCurrent = Models\Database::installedSchemaIsCorrectVersion();
         if (!$dbIsCurrent && substr($page, 0, 5) !== 'setup') {
             if (!Models\Database::connectionParametersAreSet() && $page != 'setupInstall') {
                 header('Location: ' . SetupInstallController::getUrl());
                 return;
             }
             if ($page != 'setupUpgrade' && $page != 'setupInstall') {
                 header('Location: ' . SetupUpgradeController::getUrl());
                 return;
             }
         }
         $controllerClass = 'CameraLife\\Controllers\\' . ucfirst($page) . 'Controller';
         if (!class_exists($controllerClass)) {
             throw new \Exception('Page not found');
         }
         if (isset($get['id'])) {
             $controller = new $controllerClass($get['id']);
         } else {
             $controller = new $controllerClass();
         }
         $method = 'handle' . ucfirst(strtolower($server['REQUEST_METHOD']));
         $controller->{$method}($get, $post, $files, $cookies);
     } catch (\Exception $e) {
         self::handleException($e);
     }
 }