Make db properly configurable.
authorCameron Ball <cameron@getapproved.com.au>
Mon, 22 Sep 2014 07:57:24 +0000 (15:57 +0800)
committerCameron Ball <cameron@getapproved.com.au>
Mon, 22 Sep 2014 07:57:24 +0000 (15:57 +0800)
.gitignore
DataAccess/DataMapper/DataMapper.php
config/DI.php
config/db.php.example [new file with mode: 0644]

index 7f3b1d0..2026b2f 100644 (file)
@@ -1,4 +1,5 @@
 nbproject
 logs
 composer.lock
-vendor
\ No newline at end of file
+vendor
+db.php
index b33923c..9944116 100644 (file)
@@ -14,8 +14,9 @@ class DataMapper implements IDataMapper
     private $_db;\r
     private $_maps;\r
     \r
-    public function __construct($maps)\r
+    public function __construct($maps, $dbCredentials)\r
     {\r
+        $credentials = include $dbCredentials;\r
         //TODO: should probably do all this through a configuration object or something\r
         $dsn = 'mysql:host=localhost;dbname=divinelegy;charset=utf8';\r
         $username = 'root';\r
@@ -23,7 +24,7 @@ class DataMapper implements IDataMapper
         $options = array(PDO::ATTR_EMULATE_PREPARES => false,\r
                          PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);\r
         \r
-        $this->_db = new PDO($dsn, $username, $password, $options);        \r
+        $this->_db = new PDO($dsn, $credentials['user'], $credentials['pass'], $options);        \r
         $this->_maps = include $maps;\r
     }\r
     \r
index b1dbecc..4ba7524 100644 (file)
@@ -4,6 +4,7 @@ return [
     //values\r
     'datamapper.maps' => '../config/DataMaps.php',\r
     'router.maps' => '../config/Routes.php',\r
+    'db.credentials' => '../config/db.php',\r
     \r
     //entites\r
     'Domain\Entities\StepMania\ISimfile' => DI\object('Domain\Entities\StepMania\Simfile'),\r
@@ -17,6 +18,6 @@ return [
     //DA\r
     'DataAccess\StepMania\ISimfileRepository' => DI\object('DataAccess\StepMania\SimfileRepository'),\r
     'DataAccess\DataMapper\IDataMapper' => DI\object('DataAccess\DataMapper\DataMapper')\r
-        ->constructor(DI\link('datamapper.maps')),   \r
+        ->constructor(DI\link('datamapper.maps'), DI\link('db.credentials')),\r
     'DataAccess\Queries\IQueryBuilderFactory' => DI\object('DataAccess\Queries\QueryBuilderFactory')\r
 ];\r
diff --git a/config/db.php.example b/config/db.php.example
new file mode 100644 (file)
index 0000000..7a696bb
--- /dev/null
@@ -0,0 +1,7 @@
+<?php
+
+return [
+    'user' => 'username',
+    'pass' => 'password'
+];
+