mirror of
https://github.com/YGGverse/net-php.git
synced 2025-02-05 03:14:46 +00:00
implement custom Address::get attributes
This commit is contained in:
parent
4f369bac45
commit
0acff609f4
@ -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
|
||||
{
|
||||
$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…
x
Reference in New Issue
Block a user