Changed config.ini hierarchy

This commit is contained in:
Marcin Kurczewski 2014-08-30 18:11:04 +02:00
parent f3096ffc5d
commit ff310f56c5
3 changed files with 15 additions and 10 deletions

View file

@ -1,3 +1,7 @@
databaseHost = localhost [database]
databasePort = 27017; host = localhost
databaseName = booru-dev port = 27017;
name = booru-dev
[security]
secret = change

View file

@ -10,7 +10,7 @@ final class DatabaseConnection
{ {
$connectionString = $this->getConnectionString($config); $connectionString = $this->getConnectionString($config);
$this->connection = new \MongoClient($connectionString); $this->connection = new \MongoClient($connectionString);
$this->database = $this->connection->selectDb($config->databaseName); $this->database = $this->connection->selectDb($config->database->name);
} }
public function getConnection() public function getConnection()
@ -27,8 +27,8 @@ final class DatabaseConnection
{ {
return sprintf( return sprintf(
'mongodb://%s:%d/%s', 'mongodb://%s:%d/%s',
$config->databaseHost, $config->database->host,
$config->databasePort, $config->database->port,
$config->databaseName); $config->database->name);
} }
} }

View file

@ -12,9 +12,10 @@ abstract class AbstractDatabaseTest extends \PHPUnit_Framework_TestCase
$port = 27017; $port = 27017;
$database = 'test'; $database = 'test';
$config = new \Szurubooru\Config(); $config = new \Szurubooru\Config();
$config->databaseHost = 'localhost'; $config->database = new \StdClass;
$config->databasePort = 27017; $config->database->host = 'localhost';
$config->databaseName = 'test'; $config->database->port = 27017;
$config->database->name = 'test';
$this->databaseConnection = new \Szurubooru\DatabaseConnection($config); $this->databaseConnection = new \Szurubooru\DatabaseConnection($config);
$this->upgradeService = new \Szurubooru\UpgradeService($this->databaseConnection); $this->upgradeService = new \Szurubooru\UpgradeService($this->databaseConnection);
$this->upgradeService->prepareForUsage(); $this->upgradeService->prepareForUsage();