public function isValid() { if ($this->scheme === null || $this->getAuthority() !== null) { return false; } return parent::isValid(); }
public function normalize() { parent::normalize(); if ($this->getPort() === '') { $this->setPort(null); } return $this; }
/** * @see http://tools.ietf.org/html/rfc3986#section-5.2.2 * @return GenericUri **/ public final function transform(GenericUri $reference, $strict = true) { if ($this->getScheme() === null) { throw new WrongStateException('URI without scheme cannot be a base URI'); } if ($reference->getScheme() !== ($strict ? null : $this->getScheme())) { $class = get_class($reference); $result = new $class(); $result->setScheme($reference->getScheme())->setUserInfo($reference->getUserInfo())->setHost($reference->getHost())->setPort($reference->getPort())->setPath(self::removeDotSegments($reference->getPath()))->setQuery($reference->getQuery()); } else { $result = new $this(); $result->setScheme($this->getScheme()); if ($reference->getAuthority() !== null) { $result->setUserInfo($reference->getUserInfo())->setHost($reference->getHost())->setPort($reference->getPort())->setPath(self::removeDotSegments($reference->getPath()))->setQuery($reference->getQuery()); } else { $result->setUserInfo($this->getUserInfo())->setHost($this->getHost())->setPort($this->getPort()); $path = $reference->getPath(); if (!$path) { $result->setPath($this->getPath())->setQuery($reference->getQuery() !== null ? $reference->getQuery() : $this->getQuery()); } else { $result->setQuery($reference->getQuery()); if ($path[0] == '/') { $result->setPath($path); } else { $result->setPath(self::removeDotSegments(self::mergePath($reference->getPath()))); } } } } $result->setFragment($reference->getFragment()); return $result; }
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; }
/** * @deprecated by GenericUri::normalize **/ public static function normalizeUri($uri) { return GenericUri::create()->parse($uri, true)->normalize()->toString(); }
/** * @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); }