Add "clearDomain" and "keepDomainOnly" methods

master 1.5.0
Julien Rosset 2 years ago
parent b994ef40fd
commit 41ec33dc9b

@ -16,8 +16,8 @@
"minimum-stability": "stable", "minimum-stability": "stable",
"require": { "require": {
"php": "^7.4 || ^8.0", "php": "^7.4 || ^8.0",
"jrosset/collections": "^2.3 || ^3.0", "jrosset/collections": "^2.3 || ^3.5",
"guzzlehttp/psr7": "^2.4" "guzzlehttp/psr7": "^2.6"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {

@ -1,4 +1,5 @@
<?php <?php
/** @noinspection PhpUnused */
namespace jrosset\UrlInfo; namespace jrosset\UrlInfo;
@ -10,7 +11,7 @@ use jrosset\Collections\ImmutableCollection;
use Psr\Http\Message\UriInterface; use Psr\Http\Message\UriInterface;
/** /**
* An utils class about URL parts * A utils class about URL parts
*/ */
class UrlInfo { class UrlInfo {
/** /**
@ -164,6 +165,30 @@ class UrlInfo {
return $url; return $url;
} }
/**
* Clear the “domain” parts of the URL and keep only path, arguments and anchor
*
* @return $this
*/
public function clearDomain (): self {
$this->setProtocol();
$this->setHost();
$this->setUser();
$this->setPass();
return $this;
}
/**
* Keep only the “domain” parts of the URL and clear path, arguments and anchor
*
* @return $this
*/
public function keepDomainOnly (): self {
$this->setPath();
$this->setArguments();
$this->setAnchor();
return $this;
}
/** /**
* Is the URL protocol set ? * Is the URL protocol set ?
* *

Loading…
Cancel
Save