Skip to content

Commit

Permalink
RequestFactory: script path is not detected from DOCUMENT_ROOT & SCRI…
Browse files Browse the repository at this point in the history
…PT_FILENAME (BC break)

see #31

Conflicts:
	src/Http/RequestFactory.php
  • Loading branch information
dg committed Dec 27, 2014
1 parent 2988978 commit 297e73a
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 16 deletions.
13 changes: 2 additions & 11 deletions src/Http/RequestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,9 @@ public function createHttpRequest()
$url->setQuery(isset($tmp[1]) ? $tmp[1] : '');

// detect script path
if (isset($_SERVER['SCRIPT_NAME'])) {
$script = $_SERVER['SCRIPT_NAME'];
} elseif (isset($_SERVER['DOCUMENT_ROOT'], $_SERVER['SCRIPT_FILENAME'])
&& strncmp($_SERVER['DOCUMENT_ROOT'], $_SERVER['SCRIPT_FILENAME'], strlen($_SERVER['DOCUMENT_ROOT'])) === 0
) {
$script = '/' . ltrim(strtr(substr($_SERVER['SCRIPT_FILENAME'], strlen($_SERVER['DOCUMENT_ROOT'])), '\\', '/'), '/');
} else {
$script = '/';
}

$path = strtolower($path) . '/';
$script = strtolower($script) . '/';
$script = isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] . '/' : '/';
$script = strtolower($script);
$max = min(strlen($path), strlen($script));
for ($i = 0; $i < $max; $i++) {
if ($path[$i] !== $script[$i]) {
Expand Down
1 change: 0 additions & 1 deletion tests/Http/Request.request.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ $_SERVER = array(
'REMOTE_ADDR' => '192.168.188.66',
'REQUEST_METHOD' => 'GET',
'REQUEST_URI' => '/file.php?x param=val.&pa%%72am=val2&param3=v%20a%26l%3Du%2Be)',
'SCRIPT_FILENAME' => '/public_html/www/file.php',
'SCRIPT_NAME' => '/file.php',
);

Expand Down
4 changes: 0 additions & 4 deletions tests/Http/RequestFactory.scriptPath.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ $factory = new RequestFactory;
test(function() use ($factory) {
$_SERVER = array(
'REQUEST_URI' => '/projects/modules-usage/www/',
'SCRIPT_FILENAME' => 'W:/projects/Modules-Usage/www/index.php',
'SCRIPT_NAME' => '/projects/modules-usage/www/index.php',
);

Expand All @@ -27,7 +26,6 @@ test(function() use ($factory) {
test(function() use ($factory) {
$_SERVER = array(
'REQUEST_URI' => '/projects/modules-usage/www/default/add-item',
'SCRIPT_FILENAME' => 'W:/projects/Modules-Usage/www/index.php',
'SCRIPT_NAME' => '/projects/Modules-Usage/www/index.php',
);

Expand All @@ -38,7 +36,6 @@ test(function() use ($factory) {
test(function() use ($factory) {
$_SERVER = array(
'REQUEST_URI' => '/www/index.php',
'SCRIPT_FILENAME' => 'w:\projects\modules-usage\www\index.php',
'SCRIPT_NAME' => '/www/index.php',
);

Expand All @@ -49,7 +46,6 @@ test(function() use ($factory) {
test(function() use ($factory) {
$_SERVER = array(
'REQUEST_URI' => '/www/',
'SCRIPT_FILENAME' => 'w:\projects\modules-usage\www\index.php',
'SCRIPT_NAME' => '/www/',
);

Expand Down

0 comments on commit 297e73a

Please sign in to comment.