Url path is now available in split parts id needed

master 1.2.0
Julien Rosset 3 years ago
parent 8e23b983da
commit 47f1fd4d02

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

Loading…
Cancel
Save