for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Nyholm\Dsn\Configuration;
/**
* A "URL like" DSN string.
*
* Example:
* - memcached://user:[email protected]?weight=50
* - 127.0.0.1:80
* - amqp://127.0.0.1/%2f/messages
* @author Tobias Nyholm <[email protected]>
*/
class Url extends Dsn
{
use UserPasswordTrait;
* @var string
private $host;
* @var int|null
private $port;
* @var string|null
private $path;
public function __construct(?string $scheme, string $host, ?int $port = null, ?string $path = null, array $parameters = [], array $authentication = [])
$this->host = $host;
$this->port = $port;
$this->path = $path;
$this->setAuthentication($authentication);
parent::__construct($scheme, $parameters);
}
public function getHost(): string
return $this->host;
public function withHost(string $host): self
$new = clone $this;
$new->host = $host;
return $new;
public function getPort(): ?int
return $this->port;
public function withPort(?int $port): self
$new->port = $port;
public function getPath(): ?string
return $this->path;
public function withPath(?string $path): self
$new->path = $path;
public function __toString()
$parameters = $this->getParameters();
$scheme = $this->getScheme();
return
(empty($scheme) ? '' : $scheme.'://').
$this->getUserInfoString().
$this->getHost().
(empty($this->port) ? '' : ':'.$this->port).
($this->getPath() ?? '').
(empty($parameters) ? '' : '?'.http_build_query($parameters));