| Conditions | 5 |
| Paths | 5 |
| Total Lines | 29 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 19 | public static function factory($config) |
||
| 20 | { |
||
| 21 | switch ($config['save.handler']) { |
||
| 22 | case 'pdo': |
||
| 23 | if (!class_exists(PDO::class)) { |
||
| 24 | throw new RuntimeException("Required extension ext-pdo missing"); |
||
| 25 | } |
||
| 26 | return new Xhgui_Saver_Pdo( |
||
| 27 | new PDO( |
||
| 28 | $config['pdo']['dsn'], |
||
| 29 | $config['pdo']['user'], |
||
| 30 | $config['pdo']['pass'] |
||
| 31 | ), |
||
| 32 | $config['pdo']['table'] |
||
| 33 | ); |
||
| 34 | |||
| 35 | case 'mongodb': |
||
| 36 | if (!class_exists(Manager::class)) { |
||
| 37 | throw new RuntimeException("Required extension ext-mongodb missing"); |
||
| 38 | } |
||
| 39 | $mongo = new MongoClient($config['db.host'], $config['db.options'], $config['db.driverOptions']); |
||
| 40 | $collection = $mongo->{$config['db.db']}->results; |
||
| 41 | $collection->findOne(); |
||
| 42 | return new Xhgui_Saver_Mongo($collection); |
||
| 43 | |||
| 44 | default: |
||
| 45 | throw new RuntimeException("Unsupported save handler: {$config['save.handler']}"); |
||
| 46 | } |
||
| 47 | } |
||
| 48 | } |
||
| 49 |