summaryrefslogtreecommitdiff
path: root/vendor/fguillot/picodb/lib/PicoDb/DriverFactory.php
blob: 13151ba7161bd6ed1e49b41ee1a9d06546020b90 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php

namespace PicoDb;

use LogicException;
use PicoDb\Driver\Mssql;
use PicoDb\Driver\Mysql;
use PicoDb\Driver\Postgres;
use PicoDb\Driver\Sqlite;

/**
 * Class DriverFactory
 *
 * @package PicoDb
 * @author  Frederic Guillot
 */
class DriverFactory
{
    /**
     * Get database driver from settings or environment URL
     *
     * @access public
     * @param  array $settings
     * @return Mssql|Mysql|Postgres|Sqlite
     */
    public static function getDriver(array $settings)
    {
        if (! isset($settings['driver'])) {
            throw new LogicException('You must define a database driver');
        }

        switch ($settings['driver']) {
            case 'sqlite':
                return new Sqlite($settings);
            case 'mssql':
                return new Mssql($settings);
            case 'mysql':
                return new Mysql($settings);
            case 'postgres':
                return new Postgres($settings);
            default:
                throw new LogicException('This database driver is not supported');
        }
    }
}