src/Http/Kernel.php
/**
	 * Detects if the application is running in a subdirectory and saves relevant information.
	 */
Detects if the application is running in a subdirectory and saves relevant information.
Detects if the application is running in a subdirectory and saves relevant information .
private function detectSubdirectory() {
		$rootPath = Application::root();
		$requestUri = $_SERVER['REQUEST_URI'];
		$queryString = '';
		if (strpos($requestUri, '?') !== false) {
			$queryString = substr($requestUri, strpos($requestUri, '?'));
			$requestUri = substr($requestUri, 0, strpos($requestUri, '?'));
		}
		$root = Path::parse(str_replace('\\', '/', $rootPath));
		$uri = Path::parse($requestUri);
		$shifted = '';
		for ($i = count($uri) - 1; $i >= 0; $i--) {
			$node = $uri[$i];
			if ($node->directory) {
				if (!empty($root) && $root[count($root) - 1]->name == $node->name) {
					$shifted = '/' . $node->name . $shifted;
					array_pop($root);
				}
			}
		}
		$_SERVER['SUBDIRECTORY'] = trim($shifted, '/');
		$this->subdirectory = $_SERVER['SUBDIRECTORY'];
		$newRequestUri = $requestUri;
		$newRequestUri = substr($newRequestUri, strlen($shifted));
		if (Application::routing() === 'legacy') {
			$nodes = Path::parse($newRequestUri);
			if (empty($nodes) || $nodes[count($nodes) - 1]->directory) {
				$newRequestUri .= 'index.php';
			}
		}
		$_SERVER['REQUEST_URI'] = $newRequestUri . $queryString;
	}
private function detectSubdirectory ( ) { $ rootPath = Application :: root ( ) ; $ requestUri = $ _SERVER [ 'REQUEST_URI' ] ; $ queryString = '' ; if ( strpos ( $ requestUri , '?' ) !== false ) { $ queryString = substr ( $ requestUri , strpos ( $ requestUri , '?' ) ) ; $ requestUri = substr ( $ requestUri , 0 , strpos ( $ requestUri , '?' ) ) ; } $ root = Path :: parse ( str_replace ( '\\' , '/' , $ rootPath ) ) ; $ uri = Path :: parse ( $ requestUri ) ; $ shifted = '' ; for ( $ i = count ( $ uri ) - 1 ; $ i >= 0 ; $ i -- ) { $ node = $ uri [ $ i ] ; if ( $ node -> directory ) { if ( ! empty ( $ root ) && $ root [ count ( $ root ) - 1 ] -> name == $ node -> name ) { $ shifted = '/' . $ node -> name . $ shifted ; array_pop ( $ root ) ; } } } $ _SERVER [ 'SUBDIRECTORY' ] = trim ( $ shifted , '/' ) ; $ this -> subdirectory = $ _SERVER [ 'SUBDIRECTORY' ] ; $ newRequestUri = $ requestUri ; $ newRequestUri = substr ( $ newRequestUri , strlen ( $ shifted ) ) ; if ( Application :: routing ( ) === 'legacy' ) { $ nodes = Path :: parse ( $ newRequestUri ) ; if ( empty ( $ nodes ) || $ nodes [ count ( $ nodes ) - 1 ] -> directory ) { $ newRequestUri .= 'index.php' ; } } $ _SERVER [ 'REQUEST_URI' ] = $ newRequestUri . $ queryString ; }
Detects if the application is running in a subdirectory and saves relevant information.
Detects if the application is running in a subdirectory and saves relevant information .