diff --git a/src/SemanticScuttle/Environment.php b/src/SemanticScuttle/Environment.php index df5a81c..0ffc69b 100644 --- a/src/SemanticScuttle/Environment.php +++ b/src/SemanticScuttle/Environment.php @@ -61,8 +61,17 @@ class SemanticScuttle_Environment return $GLOBALS['root']; } - $pieces = explode('/', $_SERVER['SCRIPT_NAME']); $rootTmp = '/'; + if (isset($_SERVER['PHAR_PATH_TRANSLATED'])) { + $rootTmp = $_SERVER['SCRIPT_NAME'] . '/'; + $_SERVER['SCRIPT_NAME'] = substr( + $_SERVER['PATH_TRANSLATED'], + strpos($_SERVER['PATH_TRANSLATED'], $rootTmp) + + strlen($rootTmp) + ); + } + + $pieces = explode('/', $_SERVER['SCRIPT_NAME']); foreach ($pieces as $piece) { //we eliminate possible sscuttle subfolders (like gsearch for example) if ($piece != '' && !strstr($piece, '.php') @@ -78,7 +87,7 @@ class SemanticScuttle_Environment //we do not prepend http since we also want to support https connections // "http" is not required; it's automatically determined by the browser // depending on the current connection. - return '//'. $_SERVER['HTTP_HOST'] . $rootTmp; + return '//' . $_SERVER['HTTP_HOST'] . $rootTmp; } } ?> \ No newline at end of file diff --git a/tests/SemanticScuttle/EnvironmentTest.php b/tests/SemanticScuttle/EnvironmentTest.php index 35851f0..b9c66bc 100644 --- a/tests/SemanticScuttle/EnvironmentTest.php +++ b/tests/SemanticScuttle/EnvironmentTest.php @@ -272,6 +272,48 @@ class SemanticScuttle_EnvironmentTest extends PHPUnit_Framework_TestCase SemanticScuttle_Environment::getRoot() ); } + + public function testGetRootFromPharIndex() + { + $_SERVER = array( + 'HTTP_HOST' => 'dist.bm.bogo', + 'DOCUMENT_ROOT' => '/etc/apache2/htdocs', + 'SCRIPT_FILENAME' => '/home/cweiske/Dev/html/hosts/dist.bm.bogo/SemanticScuttle-0.98.X.phar', + 'QUERY_STRING' => '', + 'REQUEST_URI' => '/SemanticScuttle-0.98.X.phar/www/index.php', + 'SCRIPT_NAME' => '/SemanticScuttle-0.98.X.phar', + 'PATH_INFO' => '/www/index.php', + 'PATH_TRANSLATED' => 'phar:///home/cweiske/Dev/semanticscuttle/cwdev/dist/SemanticScuttle-0.98.X.phar/www/index.php', + 'PHP_SELF' => '/SemanticScuttle-0.98.X.phar/www/index.php', + 'PHAR_PATH_TRANSLATED' => '/home/cweiske/Dev/html/hosts/dist.bm.bogo/www/index.php', + ); + $this->assertEquals( + '//dist.bm.bogo/SemanticScuttle-0.98.X.phar/www/', + SemanticScuttle_Environment::getRoot() + ); + } + + public function testGetRootFromPharWithSubpath() + { + $_SERVER = array( + 'HTTP_HOST' => 'dist.bm.bogo', + 'DOCUMENT_ROOT' => '/etc/apache2/htdocs', + 'SCRIPT_FILENAME' => '/home/cweiske/Dev/html/hosts/dist.bm.bogo/SemanticScuttle-0.98.X.phar', + 'QUERY_STRING' => 'no value', + 'REQUEST_URI' => '/SemanticScuttle-0.98.X.phar/www/index.php/foo/bar/', + 'SCRIPT_NAME' => '/SemanticScuttle-0.98.X.phar', + 'PATH_INFO' => '/foo/bar/', + 'PATH_TRANSLATED' => 'phar:///home/cweiske/Dev/semanticscuttle/cwdev/dist/SemanticScuttle-0.98.X.phar/www/index.php', + 'PHP_SELF' => '/SemanticScuttle-0.98.X.phar/www/index.php/foo/bar/', + 'REQUEST_TIME' => '1313425297', + 'PHAR_PATH_INFO' => '/www/index.php/foo/bar/', + 'PHAR_PATH_TRANSLATED' => '/home/cweiske/Dev/html/hosts/dist.bm.bogo/www/index.php/foo/bar/', + ); + $this->assertEquals( + '//dist.bm.bogo/SemanticScuttle-0.98.X.phar/www/', + SemanticScuttle_Environment::getRoot() + ); + } } ?> \ No newline at end of file