Skip to content

Commit

Permalink
RequestFactory: optimized script path detection performance, thx @Jan…
Browse files Browse the repository at this point in the history
…Tvrdik [Closes #35]
  • Loading branch information
dg committed Dec 27, 2014
1 parent 6e592e5 commit f49fd2a
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/Http/RequestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,13 @@ public function createHttpRequest()
$url->setQuery(isset($tmp[1]) ? $tmp[1] : '');

// detect script path
$path .= '/';
$script = isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] . '/' : '/';
$max = min(strlen($path), strlen($script));
for ($i = 0; $i < $max; $i++) {
if ($path[$i] !== $script[$i]) {
break;
} elseif ($path[$i] === '/') {
$url->setScriptPath(substr($url->getPath(), 0, $i + 1));
}
$script = isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] : '/';
if ($path !== $script) {
$max = min(strlen($path), strlen($script));
for ($i = 0; $i < $max && $path[$i] === $script[$i]; $i++);
$path = substr($path, 0, strrpos($path, '/', $i - $max - 1) + 1);
}
$url->setScriptPath($path);

// GET, POST, COOKIE
$useFilter = (!in_array(ini_get('filter.default'), array('', 'unsafe_raw')) || ini_get('filter.default_flags'));
Expand Down

1 comment on commit f49fd2a

@JanTvrdik
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.