Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/ZF-206' of https://github.com/Maks3w/zf2 into ho…
Browse files Browse the repository at this point in the history
…tfix/zf2-206
  • Loading branch information
weierophinney committed May 20, 2012
2 parents 3426297 + 6aed368 commit 024e8cb
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 19 deletions.
23 changes: 6 additions & 17 deletions src/PhpEnvironment/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,21 +311,10 @@ protected function detectBaseUrl()
} else {
// Backtrack up the SCRIPT_FILENAME to find the portion
// matching PHP_SELF.
$path = $phpSelf ?: '';
if (!isset($path[1]) || $path[1] !== '~') {
$segments = array_reverse(explode('/', trim($filename, '/')));
} else {
$segments = array_reverse(explode('/', trim($path, '/')));
}
$index = 0;
$last = count($segments);
$baseUrl = '';

do {
$segment = $segments[$index];
$baseUrl = '/' . $segment . $baseUrl;
$index++;
} while ($last > $index && false !== ($pos = strpos($path, $baseUrl)) && 0 !== $pos);

$basename = basename($filename);
$path = ($phpSelf ? trim($phpSelf, '/') : '');
$baseUrl = '/'. substr($path, 0, strpos($path, $basename)) . $basename;
}

// Does the base URL have anything in common with the request URI?
Expand Down Expand Up @@ -370,7 +359,7 @@ protected function detectBaseUrl()
/**
* Autodetect the base path of the request
*
* Uses several crtieria to determine the base path of the request.
* Uses several criteria to determine the base path of the request.
*
* @return string
*/
Expand All @@ -386,7 +375,7 @@ protected function detectBasePath()

// basename() matches the script filename; return the directory
if (basename($baseUrl) === $filename) {
return dirname($baseUrl);
return str_replace('\\', '/', dirname($baseUrl));
}

// Base path is identical to base URL
Expand Down
34 changes: 32 additions & 2 deletions test/PhpEnvironment/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function tearDown()
/**
* Data provider for testing base URL and path detection.
*/
public static function baseUrlandPathProvider()
public static function baseUrlAndPathProvider()
{
return array(
array(
Expand Down Expand Up @@ -160,11 +160,41 @@ public static function baseUrlandPathProvider()
'/~username/public',
'/~username/public'
),
// ZF2-206
array(
array(
'SCRIPT_NAME' => '/zf2tut/index.php',
'REQUEST_URI' => '/zf2tut/',
'PHP_SELF' => '/zf2tut/index.php',
'SCRIPT_FILENAME' => 'c:/ZF2Tutorial/public/index.php',
'ORIG_SCRIPT_NAME'=> null
),
'/zf2tut',
'/zf2tut'
),
array(
array(
'REQUEST_URI' => '/html/index.php/news/3?var1=val1&var2=/index.php',
'PHP_SELF' => '/html/index.php/news/3',
'SCRIPT_FILENAME' => '/var/web/html/index.php',
),
'/html/index.php',
'/html'
),
array(
array(
'REQUEST_URI' => '/html/index.php/news/index.php',
'PHP_SELF' => '/html/index.php/news/index.php',
'SCRIPT_FILENAME' => '/var/web/html/index.php',
),
'/html/index.php',
'/html'
),
);
}

/**
* @dataProvider baseUrlandPathProvider
* @dataProvider baseUrlAndPathProvider
* @param array $server
* @param string $baseUrl
* @param string $basePath
Expand Down

0 comments on commit 024e8cb

Please # to comment.