Completed
Push — master ( 72c194...b92126 )
by Christopher
53:06 queued 38:10
created

Connection::connectSQLite()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 9
rs 9.6667
cc 2
eloc 6
nc 2
nop 1
1
<?php
2
3
namespace Ganga\Potato;
4
5
use SQLite3;
6
7
/**
8
 * Class to define connection to sqlite database;
9
 */
10
class Connection
11
{
12
    protected static $conn;
13
14
    /**
15
     * Constructor
16
     * Declare an instance of SQLite class
17
     */
18
    public function __construct($config)
19
    {
20
        if (!is_array($config)) {
21
            throw new PotatoException("Database Config must be an array");
22
        }
23
24
        if (!isset($config['type']) || empty($config['type'])) {
25
            throw new PotatoException("You must specify a database type in the config");
26
        }
27
28
        if (!isset($config['database']) || empty($config['database'])) {
29
            throw new PotatoException("You must provide a database in the config");
30
        }
31
32
        $type = strtolower($config['type']);
33
        switch ($type) {
34
            case 'sqlite':
35
                self::$conn = $this->connectSQLite($config);
36
                break;
37
            case 'mysql':
38
39
                break;
40
            case 'postgres':
41
            case 'pgssql':
42
43
                break;
44
            case 'mongo':
45
46
                break;
47
        }
48
    }
49
50
    /**
51
     * Get an instance of the db connection
52
     * @return SQLite3 connection
53
     */
54
    public static function db()
55
    {
56
        return self::$conn;
57
    }
58
59
    public function connectMySQL()
60
    {
61
62
    }
63
64
    public function connectSQLite($config)
65
    {
66
        $conn = new SQLite3($config['database']);
67
        if (!$conn) {
68
            return $conn->lastErrorMsg();
69
        } else {
70
            return $conn;
71
        }
72
    }
73
74
    public function connectPostrges()
75
    {
76
        
77
    }
78
}
79