szurubooru/src/DatabaseConnection.php

35 lines
695 B
PHP
Raw Normal View History

<?php
namespace Szurubooru;
final class DatabaseConnection
{
private $database;
private $connection;
public function __construct(\Szurubooru\Config $config)
{
$connectionString = $this->getConnectionString($config);
$this->connection = new \MongoClient($connectionString);
2014-08-30 18:11:04 +02:00
$this->database = $this->connection->selectDb($config->database->name);
}
public function getConnection()
{
return $this->connection;
}
public function getDatabase()
{
return $this->database;
}
private function getConnectionString(\Szurubooru\Config $config)
{
return sprintf(
'mongodb://%s:%d/%s',
2014-08-30 18:11:04 +02:00
$config->database->host,
$config->database->port,
$config->database->name);
}
}