for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Nyholm\Dsn\Configuration;
/**
* Base DSN object.
*
* Example:
* - null://
* - redis:?host[h1]&host[h2]&host[/foo:]
* @author Tobias Nyholm <[email protected]>
*/
class Dsn
{
* @var string|null
private $scheme;
* @var array
private $parameters = [];
public function __construct(?string $scheme, array $parameters = [])
$this->scheme = $scheme;
$this->parameters = $parameters;
}
public function getScheme(): ?string
return $this->scheme;
public function withScheme(?string $scheme): self
$new = clone $this;
$new->scheme = $scheme;
return $new;
public function getParameters(): array
return $this->parameters;
* @param mixed|null $default
* @return mixed
public function getParameter(string $key, $default = null)
return \array_key_exists($key, $this->parameters) ? $this->parameters[$key] : $default;
* @param mixed $value
public function withParameter(string $key, $value): self
$new->parameters[$key] = $value;
public function withoutParameter(string $key): self
unset($new->parameters[$key]);
public function getHost(): ?string
return null;
public function getPort(): ?int
public function getPath(): ?string
public function getUser(): ?string
public function getPassword(): ?string
* @var string
public function __toString()
return sprintf('%s://%s', $this->getScheme(), empty($this->parameters) ? '' : '?'.http_build_query($this->parameters));