69 $parts = parse_url($uri);
70 if ($parts ===
false) {
71 throw new \InvalidArgumentException(
"Unable to parse URI: $uri");
152 return $uri->
getPort() ===
null
244 if (
$base !==
null) {
285 $rel =
new self($rel);
309 $decodedKey = rawurldecode(
$key);
310 $result = array_filter(explode(
'&',
$current),
function ($part) use ($decodedKey) {
311 return rawurldecode(explode(
'=', $part)[0]) !== $decodedKey;
339 $decodedKey = rawurldecode(
$key);
340 $result = array_filter(explode(
'&',
$current),
function ($part) use ($decodedKey) {
341 return rawurldecode(explode(
'=', $part)[0]) !== $decodedKey;
348 $key = strtr(
$key, self::$replaceQuery);
350 if ($value !==
null) {
351 $result[] =
$key .
'=' . strtr($value, self::$replaceQuery);
372 $uri->applyParts($parts);
373 $uri->validateState();
386 if ($this->userInfo !==
'') {
390 if ($this->port !==
null) {
431 if ($this->scheme ===
$scheme) {
437 $new->removeDefaultPort();
438 $new->validateState();
450 if ($this->userInfo ===
$info) {
456 $new->validateState();
465 if ($this->host ===
$host) {
471 $new->validateState();
480 if ($this->port ===
$port) {
486 $new->removeDefaultPort();
487 $new->validateState();
496 if ($this->path ===
$path) {
502 $new->validateState();
511 if ($this->query ===
$query) {
542 $this->scheme = isset($parts[
'scheme'])
545 $this->userInfo = isset($parts[
'user']) ? $parts[
'user'] :
'';
546 $this->host = isset($parts[
'host'])
549 $this->port = isset($parts[
'port'])
552 $this->path = isset($parts[
'path'])
555 $this->query = isset($parts[
'query'])
558 $this->fragment = isset($parts[
'fragment'])
561 if (isset($parts[
'pass'])) {
562 $this->userInfo .=
':' . $parts[
'pass'];
578 throw new \InvalidArgumentException(
'Scheme must be a string');
593 if (!is_string(
$host)) {
594 throw new \InvalidArgumentException(
'Host must be a string');
597 return strtolower(
$host);
609 if (
$port ===
null) {
615 throw new \InvalidArgumentException(
616 sprintf(
'Invalid port: %d. Must be between 1 and 65535',
$port)
625 if ($this->port !==
null && self::isDefaultPort($this)) {
641 if (!is_string(
$path)) {
642 throw new \InvalidArgumentException(
'Path must be a string');
645 return preg_replace_callback(
646 '/(?:[^' . self::$charUnreserved . self::$charSubDelims .
'%:@\/]++|%(?![A-Fa-f0-9]{2}))/',
647 [$this,
'rawurlencodeMatchZero'],
663 if (!is_string($str)) {
664 throw new \InvalidArgumentException(
'Query and fragment must be a string');
667 return preg_replace_callback(
668 '/(?:[^' . self::$charUnreserved . self::$charSubDelims .
'%:@\/\?]++|%(?![A-Fa-f0-9]{2}))/',
669 [$this,
'rawurlencodeMatchZero'],
676 return rawurlencode($match[0]);
681 if ($this->host ===
'' && ($this->scheme ===
'http' || $this->scheme ===
'https')) {
686 if (0 === strpos($this->path,
'//')) {
687 throw new \InvalidArgumentException(
'The path of a URI without an authority must not start with two slashes "//"');
689 if ($this->scheme ===
'' &&
false !== strpos(explode(
'/', $this->path, 2)[0],
':')) {
690 throw new \InvalidArgumentException(
'A relative URI must not have a path beginning with a segment containing a colon');
692 } elseif (isset($this->path[0]) && $this->path[0] !==
'/') {
694 'The path of a URI with an authority must start with a slash "/" or be empty. Automagically fixing the URI ' .
695 'by adding a leading slash to the path is deprecated since version 1.4 and will throw an exception instead.',
sprintf('%.4f', $callTime)
An exception for terminatinating execution or to throw for unit testing.
static removeDotSegments($path)
Removes dot segments from a path and returns the new path.
static resolve(UriInterface $base, UriInterface $rel)
Converts the relative URI into a new URI that is resolved against the base URI.
PSR-7 URI implementation.
getPath()
Retrieve the path component of the URI.
static isRelativePathReference(UriInterface $uri)
Whether the URI is a relative-path reference.
static isAbsolutePathReference(UriInterface $uri)
Whether the URI is a absolute-path reference.
getAuthority()
Retrieve the authority component of the URI.
static resolve(UriInterface $base, $rel)
Converts the relative URI into a new URI that is resolved against the base URI.
getScheme()
Retrieve the scheme component of the URI.
withFragment($fragment)
Return an instance with the specified URI fragment.
static withoutQueryValue(UriInterface $uri, $key)
Creates a new URI with a specific query string value removed.
applyParts(array $parts)
Apply parse_url parts to a URI.
filterPath($path)
Filters the path of a URI.
static fromParts(array $parts)
Creates a URI from a hash of parse_url components.
static composeComponents($scheme, $authority, $path, $query, $fragment)
Composes a URI reference string from its various components.
filterQueryAndFragment($str)
Filters the query string or fragment of a URI.
withHost($host)
Return an instance with the specified host.
getQuery()
Retrieve the query string of the URI.
static withQueryValue(UriInterface $uri, $key, $value)
Creates a new URI with a specific query string value.
getHost()
Retrieve the host component of the URI.
withQuery($query)
Return an instance with the specified query string.
withPath($path)
Return an instance with the specified path.
static isSameDocumentReference(UriInterface $uri, UriInterface $base=null)
Whether the URI is a same-document reference.
rawurlencodeMatchZero(array $match)
__toString()
Return the string representation as a URI reference.
static isDefaultPort(UriInterface $uri)
Whether the URI has the default port of the current scheme.
getUserInfo()
Retrieve the user information component of the URI.
getPort()
Retrieve the port component of the URI.
withScheme($scheme)
Return an instance with the specified scheme.
static isNetworkPathReference(UriInterface $uri)
Whether the URI is a network-path reference.
const HTTP_DEFAULT_HOST
Absolute http and https URIs require a host per RFC 7230 Section 2.7 but in generic URIs the host can...
static removeDotSegments($path)
Removes dot segments from a path and returns the new path.
static isAbsolute(UriInterface $uri)
Whether the URI is absolute, i.e.
withUserInfo($user, $password=null)
Return an instance with the specified user information.
getFragment()
Retrieve the fragment component of the URI.
withPort($port)
Return an instance with the specified port.
Value object representing a URI.
getScheme()
Retrieve the scheme component of the URI.
getAuthority()
Retrieve the authority component of the URI.
withQuery($query)
Return an instance with the specified query string.
getQuery()
Retrieve the query string of the URI.
getPath()
Retrieve the path component of the URI.
getPort()
Retrieve the port component of the URI.