Conditions | 6 |
Paths | 4 |
Total Lines | 23 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
26 | public static function get(array $config) |
||
27 | { |
||
28 | if (!isset($config['driver']) || !$config['driver']) { |
||
29 | throw new \RuntimeException('no driver specified'); |
||
30 | } |
||
31 | |||
32 | $driver = strtolower($config['driver']); |
||
33 | |||
34 | if (!in_array($driver, array('sqlite', 'mysql', 'sqlserver', 'postgre'), true)) { |
||
35 | throw new \UnexpectedValueException('PDO driver "' . $driver . '" not supported by PIMF'); |
||
36 | } |
||
37 | |||
38 | if (!extension_loaded('pdo') || !extension_loaded('pdo_' . $driver)) { |
||
39 | throw new \RuntimeException('Please navigate to "http://php.net/manual/pdo.installation.php" ' |
||
40 | . ' to find out how to install "PDO" with "pdo_' . $driver . '" on your system!'); |
||
41 | } |
||
42 | |||
43 | $driver = '\Pimf\Pdo\\' . ucfirst($driver); |
||
44 | |||
45 | $pdo = new $driver(); |
||
46 | |||
47 | return $pdo->connect($config); |
||
48 | } |
||
49 | } |
||
50 |