diff --git a/composer.json b/composer.json index 6de82b8..b72b113 100644 --- a/composer.json +++ b/composer.json @@ -4,9 +4,10 @@ "keywords": [ ], "minimum-stability": "stable", - "require": { - "php": "^7.4 || ^8.0", - "jrosset/collections": "^2.0" + "require": { + "php": "^7.4 || ^8.0", + "jrosset/collections": "^2.0", + "guzzlehttp/psr7": "^2.4" }, "autoload": { "psr-4": { diff --git a/src/UrlInfo/UrlInfo.php b/src/UrlInfo/UrlInfo.php index 0ee8f84..e3ced2b 100644 --- a/src/UrlInfo/UrlInfo.php +++ b/src/UrlInfo/UrlInfo.php @@ -2,10 +2,12 @@ namespace jrosset\UrlInfo; +use GuzzleHttp\Psr7\Uri; use jrosset\Collections\Collection; use jrosset\Collections\ICollection; use jrosset\Collections\IImmutableCollection; use jrosset\Collections\ImmutableCollection; +use Psr\Http\Message\UriInterface; /** * An utils class about URL parts @@ -71,6 +73,33 @@ class UrlInfo { return $this->build(); } + /** + * Create from an {@see UriInterface} + * + * @param UriInterface $uri The URI + * + * @return static The new instance + */ + public static function fromUriInterface (UriInterface $uri): self { + return new static ((string)$uri); + } + /** + * Create a new {@see Uri} from current URL + * + * @return Uri The Uri instance + */ + public function toUri (): Uri { + return new Uri($this->build()); + } + /** + * Create a new {@see UriInterface} from current URL + * + * @return UriInterface The UriInterface instance + */ + public function toUriInterface (): UriInterface { + return $this->toUri(); + } + /** * Ensure the return value is null if the given is an empty string *