Add method compatibility with UriInterface

master 1.3.0
Julien Rosset 3 years ago
parent 64924af14e
commit 9e87fee2ff

@ -6,7 +6,8 @@
"minimum-stability": "stable", "minimum-stability": "stable",
"require": { "require": {
"php": "^7.4 || ^8.0", "php": "^7.4 || ^8.0",
"jrosset/collections": "^2.0" "jrosset/collections": "^2.0",
"guzzlehttp/psr7": "^2.4"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {

@ -2,10 +2,12 @@
namespace jrosset\UrlInfo; namespace jrosset\UrlInfo;
use GuzzleHttp\Psr7\Uri;
use jrosset\Collections\Collection; use jrosset\Collections\Collection;
use jrosset\Collections\ICollection; use jrosset\Collections\ICollection;
use jrosset\Collections\IImmutableCollection; use jrosset\Collections\IImmutableCollection;
use jrosset\Collections\ImmutableCollection; use jrosset\Collections\ImmutableCollection;
use Psr\Http\Message\UriInterface;
/** /**
* An utils class about URL parts * An utils class about URL parts
@ -71,6 +73,33 @@ class UrlInfo {
return $this->build(); 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 * Ensure the return value is null if the given is an empty string
* *

Loading…
Cancel
Save