Taufan Aditya | 655a89f | 2012-03-29 03:00:56 +0700 | [diff] [blame^] | 1 | <?php |
| 2 | |
| 3 | class Mock_Database_DB { |
| 4 | |
| 5 | private $config = array(); |
| 6 | |
| 7 | /** |
| 8 | * Prepare database configuration skeleton |
| 9 | * |
| 10 | * @param array DB configuration to set |
| 11 | * @return void |
| 12 | */ |
| 13 | public function __construct($config = array()) |
| 14 | { |
| 15 | include_once(BASEPATH.'database/DB.php'); |
| 16 | |
| 17 | $this->config = $config; |
| 18 | } |
| 19 | |
| 20 | public function set_config($group = 'default') |
| 21 | { |
| 22 | if ( ! isset($this->config[$group])) |
| 23 | { |
| 24 | throw new InvalidArgumentException('Group '.$group.' not exists'); |
| 25 | } |
| 26 | |
| 27 | if ( ! empty($this->config[$group]['dsn'])) |
| 28 | { |
| 29 | $dsn = $this->config[$group]['dsn']; |
| 30 | } |
| 31 | else |
| 32 | { |
| 33 | $config = $this->config[$group]; |
| 34 | $dsn = $config['dbdriver'].'://'.$config['username'].':'.$config['password'] |
| 35 | .'@'.$config['hostname'].'/'.$config['database']; |
| 36 | |
| 37 | } |
| 38 | |
| 39 | $params = array_slice($this->config[$group], 6); |
| 40 | |
| 41 | return $dsn.http_build_query($params); |
| 42 | } |
| 43 | } |