Normalize the URL so that double slashes and relative paths are removed
public function normalizePath() {
if ($this->path == '*') {
return $this;
}
if ($this->path && $this->path != '/') {
// Replace // and /./ with /
$this->path = str_replace(array(
'/./',
'//',
), '/', $this->path);
// Remove trailing relative paths if possible
$segments = $this
->getPathSegments();
$last = end($segments);
$trailingSlash = false;
if ($last === '') {
array_pop($segments);
$trailingSlash = true;
}
while ($last == '..' || $last == '.') {
if ($last == '..') {
array_pop($segments);
$last = array_pop($segments);
}
if ($last == '.' || $last == '') {
$last = array_pop($segments);
}
}
$this->path = implode('/', $segments);
if ($trailingSlash) {
$this->path .= '/';
}
}
// Must always start with a slash
if (substr($this->path, 0, 1) != '/') {
$this->path = '/' . $this->path;
}
return $this;
}