for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Facile\MongoDbBundle\Models;
/**
* Class ConnectionConfiguration.
*/
class ConnectionConfiguration
{
/** @var string */
private $host;
/** @var int */
private $port;
private $username;
private $password;
* ConnectionConfiguration constructor.
*
* @param string $host
* @param int $port
* @param string $username
* @param string $password
public function __construct(string $host, int $port, string $username = '', string $password = '')
$this->host = $host;
$this->port = $port;
$this->username = $username;
$this->password = $password;
}
* @return string
public function getHost(): string
return $this->host;
* @return int
public function getPort(): int
return $this->port;
public function getUsername(): string
return $this->username;
* @return bool
public function hasCredentials(): bool
return !empty($this->username);
public function getPassword(): string
return $this->password;
public function getConnectionUri(): string
$credentials = $this->hasCredentials() ?
sprintf('%s:%s@', $this->username, $this->password) :
'';
$uri = sprintf(
'mongodb://%s%s:%d',
$credentials,
$this->host,
$this->port
);
return $uri;