From 0acff609f4feabdb52f65a15fcc668aad37369fa Mon Sep 17 00:00:00 2001 From: yggverse Date: Tue, 16 Apr 2024 18:44:00 +0300 Subject: [PATCH] implement custom Address::get attributes --- src/Address.php | 47 ++++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/src/Address.php b/src/Address.php index f8b7e71..7ed5232 100644 --- a/src/Address.php +++ b/src/Address.php @@ -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() ); }