ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
Uri.php
Go to the documentation of this file.
1 <?php
43 
47  protected static $scheme;
48 
52  protected static $baseUri;
53 
57  protected static $uri;
58 
62  protected static $queryString;
63 
69  public static function getBaseUri( $reload = false ) {
70  if ( $reload || is_null(self::$baseUri) ) {
71  $requestUri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $_SERVER['PHP_SELF']; //Full Request URI
72  $scriptName = $_SERVER['SCRIPT_NAME']; //Script path from docroot
73  $baseUri = strpos($requestUri, $scriptName) === 0 ? $scriptName : str_replace('\\', '/', dirname($scriptName));
74  self::$baseUri = rtrim($baseUri, '/');
75  }
76  return self::$baseUri;
77  }
78 
85  public static function getUri( $reload = false ) {
86  if ( $reload || is_null(self::$uri) ) {
87  $uri = '';
88  if ( !empty($_SERVER['PATH_INFO']) ) {
89  $uri = $_SERVER['PATH_INFO'];
90  } else {
91  if ( isset($_SERVER['REQUEST_URI']) ) {
92  $uri = parse_url(self::getScheme() . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], PHP_URL_PATH);
93  } else if ( isset($_SERVER['PHP_SELF']) ) {
94  $uri = $_SERVER['PHP_SELF'];
95  } else {
96  throw new RuntimeException('Unable to detect request URI');
97  }
98  }
99  if ( self::getBaseUri() !== '' && strpos($uri, self::getBaseUri()) === 0 ) {
100  $uri = substr($uri, strlen(self::getBaseUri()));
101  }
102  self::$uri = '/' . ltrim($uri, '/');
103  }
104  return self::$uri;
105  }
106 
112  public static function getScheme( $reload = false ) {
113  if ( $reload || is_null(self::$scheme) ) {
114  self::$scheme = ( empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] === 'off' ) ? 'http' : 'https';
115  }
116  return self::$scheme;
117  }
118 
124  public static function getQueryString( $reload = false ) {
125  if ( $reload || is_null(self::$queryString) ) {
126  self::$queryString = $_SERVER['QUERY_STRING'];
127  }
128  return self::$queryString;
129  }
130 
131 }