|
|
@ -15,10 +15,10 @@ class Address |
|
|
|
private ?string $_query = null; |
|
|
|
private ?string $_query = null; |
|
|
|
private ?string $_fragment = null; |
|
|
|
private ?string $_fragment = null; |
|
|
|
|
|
|
|
|
|
|
|
private array $_dirs = []; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private string $_separator = '/'; |
|
|
|
private string $_separator = '/'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private array $_segments = []; |
|
|
|
|
|
|
|
|
|
|
|
public function __construct(?string $address = null) |
|
|
|
public function __construct(?string $address = null) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if ($address) |
|
|
|
if ($address) |
|
|
@ -39,7 +39,7 @@ class Address |
|
|
|
|
|
|
|
|
|
|
|
if ($pass = parse_url($address, PHP_URL_PASS)) |
|
|
|
if ($pass = parse_url($address, PHP_URL_PASS)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$this->setPath( |
|
|
|
$this->setPass( |
|
|
|
(string) $pass |
|
|
|
(string) $pass |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
@ -150,10 +150,12 @@ class Address |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (false !== strpos($value, '\\')) |
|
|
|
if (false !== strpos($value, '\\')) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$this->_separator = '\\'; |
|
|
|
$this->setSeparator( |
|
|
|
|
|
|
|
'\\' |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$this->_dirs = explode( |
|
|
|
$this->_segments = explode( |
|
|
|
$this->_separator, |
|
|
|
$this->_separator, |
|
|
|
$value |
|
|
|
$value |
|
|
|
); |
|
|
|
); |
|
|
@ -161,9 +163,9 @@ class Address |
|
|
|
$this->_path = $value; |
|
|
|
$this->_path = $value; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function getDirs(): array |
|
|
|
public function getSegments(): array |
|
|
|
{ |
|
|
|
{ |
|
|
|
return $this->_dirs; |
|
|
|
return $this->_segments; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function getQuery(): ?string |
|
|
|
public function getQuery(): ?string |
|
|
@ -191,6 +193,11 @@ class Address |
|
|
|
return $this->_separator; |
|
|
|
return $this->_separator; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function setSeparator(?string $value): void |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$this->_separator = $value; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function get(): string |
|
|
|
public function get(): string |
|
|
|
{ |
|
|
|
{ |
|
|
|
$address = ''; |
|
|
|
$address = ''; |
|
|
@ -198,8 +205,10 @@ class Address |
|
|
|
if ($scheme = $this->getScheme()) |
|
|
|
if ($scheme = $this->getScheme()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$address .= sprintf( |
|
|
|
$address .= sprintf( |
|
|
|
'%s://', |
|
|
|
'%s:%s%s', |
|
|
|
$scheme |
|
|
|
$scheme, |
|
|
|
|
|
|
|
$this->getSeparator(), |
|
|
|
|
|
|
|
$this->getSeparator() |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -210,7 +219,7 @@ class Address |
|
|
|
$address .= sprintf( |
|
|
|
$address .= sprintf( |
|
|
|
'%s:%s@', |
|
|
|
'%s:%s@', |
|
|
|
$user, |
|
|
|
$user, |
|
|
|
pass |
|
|
|
$pass |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -238,14 +247,7 @@ class Address |
|
|
|
|
|
|
|
|
|
|
|
if ($path = $this->getPath()) |
|
|
|
if ($path = $this->getPath()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$address .= sprintf( |
|
|
|
$address .= $path; |
|
|
|
'%s%s', |
|
|
|
|
|
|
|
$this->getSeparator(), |
|
|
|
|
|
|
|
trim( |
|
|
|
|
|
|
|
$path, |
|
|
|
|
|
|
|
$this->getSeparator() |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ($query = $this->getQuery()) |
|
|
|
if ($query = $this->getQuery()) |
|
|
@ -267,35 +269,102 @@ class Address |
|
|
|
return $address; |
|
|
|
return $address; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function absolute( |
|
|
|
public function getAbsolute( |
|
|
|
\Yggverse\Net\Address $address |
|
|
|
\Yggverse\Net\Address $base |
|
|
|
): string |
|
|
|
): ?string |
|
|
|
{ |
|
|
|
{ |
|
|
|
if ($address->isAbsolute()) |
|
|
|
if ($this->isAbsolute()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return $address->get(); |
|
|
|
return $this->get(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$address->setScheme( |
|
|
|
if ($base->isRelative()) |
|
|
|
$this->getScheme() |
|
|
|
{ |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->setScheme( |
|
|
|
|
|
|
|
$base->getScheme() |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->setUser( |
|
|
|
|
|
|
|
$base->getUser() |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->setPass( |
|
|
|
|
|
|
|
$base->getPass() |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->setHost( |
|
|
|
|
|
|
|
$base->getHost() |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->setPort( |
|
|
|
|
|
|
|
$base->getPort() |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->setSeparator( |
|
|
|
|
|
|
|
$base->getSeparator() |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
$address->setUser( |
|
|
|
if (str_starts_with((string) $this->getPath(), $this->getSeparator())) |
|
|
|
$this->getUser() |
|
|
|
{ |
|
|
|
|
|
|
|
return $this->get(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($path = $this->getPath()) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$prefix = array_reverse( |
|
|
|
|
|
|
|
$base->getSegments() |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
$address->setPass( |
|
|
|
array_shift( |
|
|
|
$this->getPass() |
|
|
|
$prefix |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
$address->setHost( |
|
|
|
$navigate = true; |
|
|
|
$this->getHost() |
|
|
|
|
|
|
|
|
|
|
|
$postfix = []; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($this->getSegments() as $index => $segment) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if ($segment == '.') |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($navigate && $segment == '..') |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (empty($prefix[$index])) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
unset( |
|
|
|
|
|
|
|
$prefix[$index] |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
$address->setPort( |
|
|
|
continue; |
|
|
|
$this->getPort() |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$navigate = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$postfix[] = $segment; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->setPath( |
|
|
|
|
|
|
|
implode( |
|
|
|
|
|
|
|
$this->getSeparator(), |
|
|
|
|
|
|
|
array_merge( |
|
|
|
|
|
|
|
array_reverse( |
|
|
|
|
|
|
|
$prefix |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
$postfix |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
) |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return ''; // @TODO |
|
|
|
return $this->get(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |