Browse Source

implement custom Address::get attributes

main
yggverse 8 months ago
parent
commit
0acff609f4
  1. 47
      src/Address.php

47
src/Address.php

@ -198,28 +198,37 @@ class Address @@ -198,28 +198,37 @@ class Address
$this->_separator = $value;
}
public function get(): string
public function get(
bool $scheme = true,
bool $user = true,
bool $pass = true,
bool $host = true,
bool $port = true,
bool $path = true,
bool $query = true,
bool $fragment = true,
): string
{
$address = '';
if ($scheme = $this->getScheme())
if ($scheme && $this->getScheme())
{
$address .= sprintf(
'%s:%s%s',
$scheme,
$this->getScheme(),
$this->getSeparator(),
$this->getSeparator()
);
}
if ($user = $this->getUser())
if ($user && $this->getUser())
{
if ($pass = $this->getPass())
if ($pass && $this->getPass())
{
$address .= sprintf(
'%s:%s@',
$user,
$pass
$this->getUser(),
$this->getPass()
);
}
@ -227,47 +236,47 @@ class Address @@ -227,47 +236,47 @@ class Address
{
$address .= sprintf(
'%s@',
$user
$this->getUser()
);
}
}
if ($host = $this->getHost())
if ($host && $this->getHost())
{
$address .= $host;
$address .= $this->getHost();
}
if ($port = $this->getPort())
if ($port && $this->getPort())
{
$address .= sprintf(
':%d',
$port
$this->getPort()
);
}
if ($path = $this->getPath())
if ($path && $this->getPath())
{
if (!str_starts_with($path, $this->getSeparator()))
if (!str_starts_with($this->getPath(), $this->getSeparator()))
{
$address .= $this->getSeparator();
}
$address .= $path;
$address .= $this->getPath();
}
if ($query = $this->getQuery())
if ($query && $this->getQuery())
{
$address .= sprintf(
'?%s',
$query
$this->getQuery()
);
}
if ($fragment = $this->getFragment())
if ($fragment && $this->getFragment())
{
$address .= sprintf(
'#%s',
$fragment
$this->getFragment()
);
}

Loading…
Cancel
Save