Example #1
0
 /**
  * Inits Orion's URI context.
  * Basically retreiving and parsing : base directory, requested URI, module URI, URI parameters, and mode.
  * 
  * Throw an Exception if no compatible URI is found.
  */
 public static function init($path)
 {
     try {
         self::$URI = $_SERVER['REQUEST_URI'];
         if (\Orion::config()->defined('BASE_DIR')) {
             self::$BASE_DIR = \Orion::config()->get('BASE_DIR');
         } else {
             self::$BASE_DIR = '';
         }
         if (\Orion::config()->defined('MODULE_SEPARATOR')) {
             self::$MODULE_SEP = \Orion::config()->get('MODULE_SEPARATOR');
         } else {
             self::$MODULE_SEP = '/';
         }
         self::$PATH = $path;
         $uri = self::getRelativeURI();
         $modelist = \Orion::config()->get('MODE_LIST');
         if ($uri == '') {
             $mode = \Orion::config()->get('DEFAULT_MODE');
             if (!array_key_exists($mode, $modelist)) {
                 throw new Exception("Default mode isn't registered in MODE_LIST", E_USER_ERROR, get_class());
             }
             \Orion::setMode($mode);
             self::$MODULE_EXT = $modelist[$mode];
             self::$MODULE_NAME = \Orion::config()->get('DEFAULT_MODULE');
             self::$MODULE_URI = '';
         } else {
             foreach ($modelist as $mode => $ext) {
                 $matches = array();
                 // Module-only URI type (ex: module.html)
                 if (preg_match('#^(\\w+)' . Tools::escapeRegex($ext) . '$#', $uri, $matches)) {
                     \Orion::setMode($mode);
                     self::$MODULE_EXT = $ext;
                     self::$MODULE_NAME = $matches[1];
                     self::$MODULE_URI = null;
                     break;
                 } elseif (preg_match('#^(\\w+)' . self::$MODULE_SEP . '(.*)' . Tools::escapeRegex($ext) . '$#', $uri, $matches)) {
                     \Orion::setMode($mode);
                     self::$MODULE_EXT = $ext;
                     self::$MODULE_NAME = $matches[1];
                     self::$MODULE_URI = $matches[2];
                     break;
                 }
             }
         }
         // No compatible URI found, redirecting.
         if (self::$MODULE_NAME == null) {
             Context::redirect(404);
         }
     } catch (Exception $e) {
         throw $e;
     }
 }