properly detect path info when running in the phar without /www/

This commit is contained in:
Christian Weiske 2011-08-19 07:46:45 +02:00
parent 2333ebf0e7
commit 557467b2b4
2 changed files with 27 additions and 4 deletions

View File

@ -29,10 +29,13 @@ class SemanticScuttle_Environment
*/
public static function getServerPathInfo()
{
if (isset($_SERVER['PHAR_PATH_TRANSLATED'])
&& '/' . $_SERVER['SCRIPT_NAME'] == $_SERVER['PATH_INFO']
) {
return null;
if (isset($_SERVER['PHAR_PATH_TRANSLATED'])) {
$fscript = '/' . $_SERVER['SCRIPT_NAME'];
if ($fscript == $_SERVER['PATH_INFO']) {
return null;
} else if (substr($_SERVER['PATH_INFO'], 0, strlen($fscript)) == $fscript) {
return substr($_SERVER['PATH_INFO'], strlen($fscript));
}
}
if (isset($_SERVER['PATH_INFO'])) {

View File

@ -272,6 +272,26 @@ class SemanticScuttle_EnvironmentTest extends PHPUnit_Framework_TestCase
);
}
public function testGetServerPathInfoPharWithInfoWithoutWww()
{
$_SERVER = array(
'PATH' => '/usr/local/bin:/usr/bin:/bin',
'SERVER_NAME' => '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/tags.php/test',
'SCRIPT_NAME' => 'tags.php',
'PATH_INFO' => '/tags.php/test',
'PATH_TRANSLATED' => 'phar:///home/cweiske/Dev/semanticscuttle/cwdev/dist/SemanticScuttle-0.98.X.phar/www/tags.php',
'PHP_SELF' => '/SemanticScuttle-0.98.X.phar/tags.php/test',
'PHAR_PATH_TRANSLATED' => '/home/cweiske/Dev/html/hosts/dist.bm.bogo/tags.php/test',
);
$this->assertEquals(
'/test', SemanticScuttle_Environment::getServerPathInfo()
);
}
public function testGetRootWithConfigPreset()
{
$GLOBALS['root'] = 'https://happy.penguin.example.org/walks/away/';