17 use Psr\Http\Message\UriInterface;
26 class Uri implements UriInterface
104 if (!is_string($uri)) {
105 $argumentType = is_object($uri) ? get_class($uri) : gettype($uri);
106 throw new \InvalidArgumentException(
'URI passed must be a string, but is of type "' . $argumentType .
'"', 1436717320);
120 $uriParts = parse_url($uri);
122 if ($uriParts ===
false) {
123 throw new \InvalidArgumentException(
'The parsedUri string appears to be malformed', 1436717322);
126 if (isset($uriParts[
'scheme'])) {
130 if (isset($uriParts[
'user'])) {
131 $this->userInfo = $uriParts[
'user'];
132 if (isset($uriParts[
'pass'])) {
133 $this->userInfo .=
':' . $uriParts[
'pass'];
137 if (isset($uriParts[
'host'])) {
138 $this->host = $uriParts[
'host'];
141 if (isset($uriParts[
'port'])) {
142 $this->port = (int)$uriParts[
'port'];
145 if (isset($uriParts[
'path'])) {
149 if (isset($uriParts[
'query'])) {
153 if (isset($uriParts[
'fragment'])) {
197 if (empty($this->host)) {
202 if (!empty($this->userInfo)) {
266 return $this->
isNonStandardPort($this->scheme, $this->host, $this->port) ? $this->port :
null;
365 $clonedObject = clone $this;
367 return $clonedObject;
388 if (!empty($password)) {
392 $clonedObject = clone $this;
394 return $clonedObject;
412 $clonedObject = clone $this;
413 $clonedObject->host =
$host;
414 return $clonedObject;
438 if (\
TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger(
$port) ===
false) {
440 throw new \InvalidArgumentException(
'Invalid port "' . $argumentType .
'" specified, must be an integer.', 1436717324);
444 if ($port < 1 || $port > 65535) {
445 throw new \InvalidArgumentException(
'Invalid port "' .
$port .
'" specified, must be a valid TCP/UDP port.', 1436717326);
449 $clonedObject = clone $this;
450 $clonedObject->port =
$port;
451 return $clonedObject;
480 throw new \InvalidArgumentException(
'Invalid path provided. Must be of type string.', 1436717328);
483 if (strpos(
$path,
'?') !==
false) {
484 throw new \InvalidArgumentException(
'Invalid path provided. Must not contain a query string.', 1436717330);
487 if (strpos(
$path,
'#') !==
false) {
488 throw new \InvalidArgumentException(
'Invalid path provided; must not contain a URI fragment', 1436717332);
492 $clonedObject = clone $this;
493 $clonedObject->path =
$path;
494 return $clonedObject;
516 throw new \InvalidArgumentException(
'Query string must be a string.', 1436717334);
519 if (strpos(
$query,
'#') !==
false) {
520 throw new \InvalidArgumentException(
'Query string must not include a URI fragment.', 1436717336);
524 $clonedObject = clone $this;
525 $clonedObject->query =
$query;
526 return $clonedObject;
547 $clonedObject = clone $this;
549 return $clonedObject;
579 if (!empty($this->scheme)) {
580 $uri .= $this->scheme .
':';
590 $uri .=
'/' . ltrim(
$path,
'/');
596 if ($this->fragment) {
640 if (!array_key_exists(
$scheme, $this->supportedSchemes)) {
641 throw new \InvalidArgumentException(
'Unsupported scheme "' .
$scheme .
'"; must be any empty string or in the set (' . implode(
', ', array_keys($this->supportedSchemes)) .
')', 1436717338);
655 return preg_replace_callback(
656 '/(?:[^' . self::UNRESERVED_CHARLIST .
':@&=\+\$,\/;%]+|%(?![A-Fa-f0-9]{2}))/',
657 function ($matches) {
658 return rawurlencode($matches[0]);
678 $parts = explode(
'&',
$query);
679 foreach ($parts as $index => $part) {
681 if ($value ===
null) {
688 return implode(
'&', $parts);
699 $data = explode(
'=', $value, 2);
700 if (count($data) === 1) {
733 return preg_replace_callback(
734 '/(?:[^' . self::UNRESERVED_CHARLIST . self::SUBDELIMITER_CHARLIST .
'%:@\/\?]+|%(?![A-Fa-f0-9]{2}))/',
735 function ($matches) {
736 return rawurlencode($matches[0]);