/** * @deprecated by GenericUri::normalize **/ public static function normalizeUri($uri) { return GenericUri::create()->parse($uri, true)->normalize()->toString(); }
private function getRealObject($object) { $result = $object; if (is_link($object)) { $result = readlink($object); if ($result === false) { throw new WrongStateException("invalid link: {$object}"); } if (substr($result, 0, 1) !== DIRECTORY_SEPARATOR) { $result = GenericUri::create()->setScheme('file')->setPath($object)->transform(GenericUri::create()->setPath($result))->getPath(); } } $realResult = realpath($result); if ($realResult === false) { throw new WrongStateException("invalid context: {$object} ({$result})"); } return $realResult; }
/** * @return ApplicationUrl **/ public function setPathByRequestUri($requestUri, $normalize = true) { if (!$this->base) { throw new WrongStateException('base url must be set first'); } $currentUrl = GenericUri::create()->parse($requestUri); if (!$currentUrl->isValid()) { throw new WrongArgumentException('wtf? request uri is invalid'); } if ($normalize) { $currentUrl->normalize(); } $path = $currentUrl->getPath(); // paranoia if (!$path || $path[0] !== '/') { $path = '/' . $path; } if (strpos($path, $this->base->getPath()) !== 0) { throw new WrongArgumentException('left parts of path and base url does not match: ' . "{$path} vs. " . $this->base->getPath()); } $actualPath = substr($path, strlen($this->base->getPath())); return $this->setPath($actualPath); }