for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* This file is part of the Borobudur-Event-Sourcing package.
*
* (c) Hexacodelabs <http://hexacodelabs.com>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Borobudur\EventSourcing\Storage\Mongo;
/**
* @author Iqbal Maulana <[email protected]>
* @created 8/20/15
class MongoConfig
{
* @var string
public $dsn;
public $host;
public $database;
public $user;
public $pass;
* @var int
public $port;
* Constructor.
* @param string $database
* @param string $host
* @param string $user
* @param string|null $pass
* @param int|null $port
public function __construct($database, $host = null, $user = null, $pass = null, $port = null)
$this->host = $host ?: 'localhost';
$this->database = $database;
$this->user = $user;
$this->pass = $pass;
$this->port = $port ?: 27017;
$this->dsn = $this->buildDsn();
}
* Build dsn.
* @return string
private function buildDsn()
$str = 'mongodb://';
$str .= $this->buildAuth();
if ($this->user) {
$str .= '@';
return $str . $this->host . ':' . $this->port;
* Build auth.
private function buildAuth()
$str = '';
$str .= $this->user;
if ($this->user && $this->pass) {
$str .= ':' . $this->pass;
return $str;