Example #1
0
 /**
  * Initialize the URI class.
  *
  * @return void
  */
 public static function initialize()
 {
     // We need to get the different sections from the URI to process the
     // correct route.
     // Standard request in the browser?
     if (isset($_SERVER['REQUEST_URI'])) {
         // Get the active URI.
         $request = $_SERVER['REQUEST_URI'];
         $host = $_SERVER['HTTP_HOST'];
         $protocol = 'http' . (Request::https() ? 's' : '');
         $base = $protocol . '//' . $host;
         $uri = $base . $request;
         // Build the URI segments.
         $length = strlen($base);
         $str = (string) substr($uri, $length);
         $arr = (array) explode('/', trim($str, '/'));
         $segments = [];
         foreach ($arr as $segment) {
             if ($segment !== '') {
                 array_push($segments, $segment);
             }
         }
         // Assign properties.
         static::$base = $base;
         static::$uri = $uri;
         static::$segments = $segments;
     } else {
         if (isset($_SERVER['argv'])) {
             $segments = [];
             foreach ($_SERVER['argv'] as $arg) {
                 if ($arg !== $_SERVER['SCRIPT_NAME']) {
                     array_push($segments, $arg);
                 }
             }
             static::$segments = $segments;
         }
     }
 }