|
|
@ -4,6 +4,8 @@ namespace jrosset\UrlInfo;
|
|
|
|
|
|
|
|
|
|
|
|
use jrosset\Collections\Collection;
|
|
|
|
use jrosset\Collections\Collection;
|
|
|
|
use jrosset\Collections\ICollection;
|
|
|
|
use jrosset\Collections\ICollection;
|
|
|
|
|
|
|
|
use jrosset\Collections\IImmutableCollection;
|
|
|
|
|
|
|
|
use jrosset\Collections\ImmutableCollection;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* An utils class about URL parts
|
|
|
|
* An utils class about URL parts
|
|
|
@ -30,9 +32,9 @@ class UrlInfo {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private ?string $pass;
|
|
|
|
private ?string $pass;
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @var string|null The URL path
|
|
|
|
* @var ICollection The parts of the URL path
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private ?string $path;
|
|
|
|
private ICollection $pathParts;
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @var ICollection The URL arguments
|
|
|
|
* @var ICollection The URL arguments
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -52,7 +54,7 @@ class UrlInfo {
|
|
|
|
$this->setHost();
|
|
|
|
$this->setHost();
|
|
|
|
$this->setPort();
|
|
|
|
$this->setPort();
|
|
|
|
$this->setUser();
|
|
|
|
$this->setUser();
|
|
|
|
$this->setPath();
|
|
|
|
$this->setPathParts();
|
|
|
|
$this->setArguments();
|
|
|
|
$this->setArguments();
|
|
|
|
$this->setAnchor();
|
|
|
|
$this->setAnchor();
|
|
|
|
|
|
|
|
|
|
|
@ -278,7 +280,15 @@ class UrlInfo {
|
|
|
|
* @return bool Is the URL path set ?
|
|
|
|
* @return bool Is the URL path set ?
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function hasPath (): bool {
|
|
|
|
public function hasPath (): bool {
|
|
|
|
return $this->path !== null;
|
|
|
|
return $this->hasPathParts();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Is the URL path parts set ?
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return bool Is the URL path set ?
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function hasPathParts (): bool {
|
|
|
|
|
|
|
|
return count($this->pathParts) > 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Is the URL path absolute ?
|
|
|
|
* Is the URL path absolute ?
|
|
|
@ -286,7 +296,7 @@ class UrlInfo {
|
|
|
|
* @return bool Is the URL path absolute ?
|
|
|
|
* @return bool Is the URL path absolute ?
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function isPathAbsolute (): bool {
|
|
|
|
public function isPathAbsolute (): bool {
|
|
|
|
return mb_substr($this->getPath(), 0, 1) === '/';
|
|
|
|
return $this->hasPathParts() && $this->pathParts[0] === '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* The URL path
|
|
|
|
* The URL path
|
|
|
@ -294,7 +304,15 @@ class UrlInfo {
|
|
|
|
* @return string|null The URL path
|
|
|
|
* @return string|null The URL path
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function getPath (): ?string {
|
|
|
|
public function getPath (): ?string {
|
|
|
|
return $this->path;
|
|
|
|
return $this->hasPathParts() ? $this->getPathParts()->join('/') : null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* The URL path parts
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return ICollection The URL path parts
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function getPathParts (): ICollection {
|
|
|
|
|
|
|
|
return $this->pathParts;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Set the URL path
|
|
|
|
* Set the URL path
|
|
|
@ -304,7 +322,17 @@ class UrlInfo {
|
|
|
|
* @return $this
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function setPath (?string $path = null): self {
|
|
|
|
public function setPath (?string $path = null): self {
|
|
|
|
$this->path = self::ensureNull($path);
|
|
|
|
return $this->setPathParts(ImmutableCollection::split($path ?? '', '/'));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Set the URL path parts
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param IImmutableCollection|null $pathParts The new URL path parts
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return $this
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function setPathParts (?IImmutableCollection $pathParts = null): self {
|
|
|
|
|
|
|
|
$this->pathParts = new Collection($pathParts);
|
|
|
|
return $this;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -337,12 +365,12 @@ class UrlInfo {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Set the URL arguments
|
|
|
|
* Set the URL arguments
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param ICollection|null $arguments The new URL arguments
|
|
|
|
* @param IImmutableCollection|null $arguments The new URL arguments
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return $this
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function setArguments (?ICollection $arguments = null): self {
|
|
|
|
public function setArguments (?IImmutableCollection $arguments = null): self {
|
|
|
|
$this->arguments = $arguments ?? new Collection();
|
|
|
|
$this->arguments = new Collection($arguments);
|
|
|
|
return $this;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|