Rev 29 | Rev 34 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 29 | Rev 31 | ||
|---|---|---|---|
| Line 55... | Line 55... | ||
| 55 | * already initialized.
|
55 | * already initialized.
|
| 56 | * @return Application
|
56 | * @return Application
|
| 57 | */
|
57 | */
|
| 58 | public static function getInstance(Application $instance = null) |
58 | public static function getInstance(Application $instance = null) |
| 59 | {
|
59 | {
|
| 60 | if (is_null(self::$_instance)) |
60 | if (self::$_instance === null) |
| 61 | {
|
61 | {
|
| 62 | self::$_instance = ($instance === null) ? new self() : $instance; |
62 | self::$_instance = ($instance === null) ? new self() : $instance; |
| 63 | }
|
63 | }
|
| 64 | 64 | ||
| 65 | return self::$_instance; |
65 | return self::$_instance; |
| Line 162... | Line 162... | ||
| 162 | * <code>null</code> if there is no such <var>$key</var>
|
162 | * <code>null</code> if there is no such <var>$key</var>
|
| 163 | * in <var>$array</var>
|
163 | * in <var>$array</var>
|
| 164 | */
|
164 | */
|
| 165 | public static function getParam($key, array $array = null) |
165 | public static function getParam($key, array $array = null) |
| 166 | {
|
166 | {
|
| 167 | if (is_null($array)) |
167 | if ($array === null) |
| 168 | {
|
168 | {
|
| 169 | $array = $_GET; |
169 | $array = $_GET; |
| 170 | }
|
170 | }
|
| 171 | 171 | ||
| 172 | return isset($array[$key]) ? $array[$key] : null; |
172 | return isset($array[$key]) ? $array[$key] : null; |
| Line 240... | Line 240... | ||
| 240 | {
|
240 | {
|
| 241 | /* FastCGI */
|
241 | /* FastCGI */
|
| 242 | $url = self::getParam('URL', $_SERVER); |
242 | $url = self::getParam('URL', $_SERVER); |
| 243 | if ($url === null) |
243 | if ($url === null) |
| 244 | {
|
244 | {
|
| - | 245 | /* Server/PHP too old, compute URI */
|
|
| - | 246 | $url = self::getParam('REQUEST_URI', $_SERVER); |
|
| - | 247 | if (preg_match('/^[^?]+/', $url, $matches) > 0) |
|
| - | 248 | {
|
|
| - | 249 | $url = $matches[0]; |
|
| - | 250 | }
|
|
| - | 251 | else
|
|
| - | 252 | {
|
|
| - | 253 | /* Has .php in it, but at least it works */
|
|
| - | 254 | $url = self::getParam('SCRIPT_NAME', $_SERVER); |
|
| - | 255 | if ($url === null) |
|
| - | 256 | {
|
|
| 245 | throw new Exception( |
257 | throw new Exception( |
| 246 | 'Neither $_SERVER["SCRIPT_URL"] nor $_SERVER["URL"] is available, cannot continue.'); |
258 | 'None of $_SERVER["SCRIPT_URL"], $_SERVER["URL"],'
|
| - | 259 | . ' $_SERVER["REQUEST_URI"], or $_SERVER["SCRIPT_NAME"]' |
|
| - | 260 | . ' is available, cannot continue.'); |
|
| - | 261 | }
|
|
| - | 262 | }
|
|
| 247 | }
|
263 | }
|
| 248 | }
|
264 | }
|
| 249 | 265 | ||
| 250 | $query = (!is_null($controller) ? 'controller=' . $controller : '') |
266 | $query = (($controller !== null) ? 'controller=' . $controller : '') |
| 251 | . (!is_null($action) ? '&action=' . $action : '') |
267 | . (($action !== null) ? '&action=' . $action : '') |
| 252 | . (!is_null($id) ? '&id=' . $id : ''); |
268 | . (($id !== null) ? '&id=' . $id : ''); |
| 253 | 269 | ||
| 254 | return $url . ($query ? '?' . $query : ''); |
270 | return $url . ($query ? '?' . $query : ''); |
| 255 | }
|
271 | }
|
| 256 | 272 | ||
| 257 | /**
|
273 | /**
|
| 258 | * Performs a server-side redirect within the application
|
274 | * Performs a server-side redirect within the application
|
| 259 | */
|
275 | */
|
| 260 | public static function redirect($query = '') |
276 | public static function redirect($query = '') |
| 261 | {
|
277 | {
|
| 262 | $script_uri = self::getParam('SCRIPT_URI', $_SERVER); |
278 | $script_uri = self::getParam('SCRIPT_URI', $_SERVER); |
| 263 | if (is_null($script_uri)) |
279 | if ($script_uri === null) |
| 264 | {
|
280 | {
|
| 265 | /* Server/PHP too old, compute URI */
|
281 | /* Server/PHP too old, compute URI */
|
| 266 | if (preg_match('/^[^?]+/', |
282 | if (preg_match('/^[^?]+/', |
| 267 | self::getParam('REQUEST_URI', $_SERVER), $matches) > 0) |
283 | self::getParam('REQUEST_URI', $_SERVER), $matches) > 0) |
| 268 | {
|
284 | {
|