Better DI for database.
[rock.divinelegy.git] / DataAccess / DatabaseFactory.php
1 <?php
2
3 namespace DataAccess;
4
5 use DataAccess\IDatabaseFactory;
6
7 use PDO;
8
9 class DatabaseFactory implements IDatabaseFactory {
10
11 private $_username;
12 private $_password;
13 private $_dsn;
14
15 public function __construct($dbCredentials)
16 {
17 $credentials = include $dbCredentials;
18 //TODO: should probably do all this through a configuration object or something
19 $this->_dsn = $credentials['dsn'];
20 $this->_username = $credentials['user'];
21 $this->_password = $credentials['pass'];
22 }
23
24 public function createInstance()
25 {
26 $options = array(PDO::ATTR_EMULATE_PREPARES => false,
27 PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);
28 return new PDO($this->_dsn, $this->_username, $this->_password, $options);
29 }
30 }