mirror of
https://github.com/til-schneider/slim-wiki.git
synced 2025-08-12 19:44:14 +02:00
Moved index.php code in function in order to prevent pollution of the global namespace (because former global variables are local now)
This commit is contained in:
@@ -1,40 +1,42 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
ini_set('display_errors', 1);
|
function init() {
|
||||||
|
ini_set('display_errors', 1);
|
||||||
|
|
||||||
// Split URI example: 'http://localhost/slim-wiki/myfolder/mypage?action=bla'
|
// Split URI example: 'http://localhost/slim-wiki/myfolder/mypage?action=bla'
|
||||||
// into $appPath example: '/slim-wiki'
|
// into $appPath example: '/slim-wiki'
|
||||||
// and $requestPathArray example: array('myfolder', 'mypage')
|
// and $requestPathArray example: array('myfolder', 'mypage')
|
||||||
|
|
||||||
$uriPathArray = explode("/", parse_url($_SERVER['REQUEST_URI'])['path']);
|
$uriPathArray = explode("/", parse_url($_SERVER['REQUEST_URI'])['path']);
|
||||||
$scriptPathArray = explode("/", dirname($_SERVER['SCRIPT_NAME']));
|
$scriptPathArray = explode("/", dirname($_SERVER['SCRIPT_NAME']));
|
||||||
|
|
||||||
$basePathArray = array();
|
$basePathArray = array();
|
||||||
$requestPathArray = array();
|
$requestPathArray = array();
|
||||||
$isBasePath = true;
|
$isBasePath = true;
|
||||||
foreach ($uriPathArray as $level => $uriDir) {
|
foreach ($uriPathArray as $level => $uriDir) {
|
||||||
$scriptDir = isset($scriptPathArray[$level]) ? $scriptPathArray[$level] : null;
|
$scriptDir = isset($scriptPathArray[$level]) ? $scriptPathArray[$level] : null;
|
||||||
if ($isBasePath && $scriptDir != $uriDir) {
|
if ($isBasePath && $scriptDir != $uriDir) {
|
||||||
// The URI path differs from the script path here -> We arrived at the level where the app is installed
|
// The URI path differs from the script path here -> We arrived at the level where the app is installed
|
||||||
$isBasePath = false;
|
$isBasePath = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($isBasePath) {
|
||||||
|
$basePathArray[] = $uriDir;
|
||||||
|
} else {
|
||||||
|
$requestPathArray[] = $uriDir;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
$basePath = rtrim(implode('/', $basePathArray), '/') . '/';
|
||||||
|
|
||||||
if ($isBasePath) {
|
$https = false;
|
||||||
$basePathArray[] = $uriDir;
|
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
|
||||||
} else {
|
$https = true;
|
||||||
$requestPathArray[] = $uriDir;
|
|
||||||
}
|
}
|
||||||
|
$baseUrl = 'http' . ($https ? 's' : '') . '://' . $_SERVER['HTTP_HOST'] . $basePath;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/server/logic/Main.php';
|
||||||
|
|
||||||
|
Main::get()->dispatch($baseUrl, $basePath, $requestPathArray);
|
||||||
}
|
}
|
||||||
$basePath = rtrim(implode('/', $basePathArray), '/') . '/';
|
|
||||||
|
|
||||||
$https = false;
|
init();
|
||||||
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
|
|
||||||
$https = true;
|
|
||||||
}
|
|
||||||
$baseUrl = 'http' . ($https ? 's' : '') . '://' . $_SERVER['HTTP_HOST'] . $basePath;
|
|
||||||
|
|
||||||
unset($uriPathArray, $scriptPathArray, $basePathArray, $isBasePath, $https);
|
|
||||||
|
|
||||||
require_once __DIR__ . '/server/logic/Main.php';
|
|
||||||
|
|
||||||
Main::get()->dispatch($baseUrl, $basePath, $requestPathArray);
|
|
||||||
|
Reference in New Issue
Block a user