public __toString ( ) : string | ||
return | string |
public function __toString()
{
$userPass = '';
if (false === $this->getUser()->isEmpty()) {
$userPass = \sprintf('%s@', $this->getUser());
if (false === $this->getPassword()->isEmpty()) {
$userPass = \sprintf('%s:%s@', $this->getUser(), $this->getPassword());
}
}
$port = '';
if (false === NullPortNumber::create()->sameValueAs($this->getPort())) {
$port = \sprintf(':%d', $this->getPort()->toNative());
}
$urlString = \sprintf('%s://%s%s%s%s%s%s', $this->getScheme(), $userPass, $this->getDomain(), $port, $this->getPath(), $this->getQueryString(), $this->getFragmentIdentifier());
return $urlString;
}
public function testNullPortUrlToString() { $nullPortUrl = new Url(new SchemeName('http'), new StringLiteral('user'), new StringLiteral(''), new Hostname('foo.com'), new NullPortNumber(), new Path('/bar'), new QueryString('?querystring'), new FragmentIdentifier('#fragmentidentifier')); $this->assertSame('http://[email protected]/bar?querystring#fragmentidentifier', $nullPortUrl->__toString()); }