Passed
Push — main ( d541b3...582864 )
by Thierry
26:42 queued 18:14
created

Driver::postConnectConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 2
rs 10
1
<?php
2
3
namespace Lagdo\DbAdmin\Driver\Sqlite;
4
5
use Lagdo\DbAdmin\Driver\Exception\AuthException;
6
use Lagdo\DbAdmin\Driver\Driver as AbstractDriver;
7
use Lagdo\DbAdmin\Driver\TranslatorInterface;
8
use Lagdo\DbAdmin\Driver\UtilInterface;
9
10
use function class_exists;
11
use function extension_loaded;
12
13
class Driver extends AbstractDriver
14
{
15
    /**
16
     * The constructor
17
     *
18
     * @param UtilInterface $util
19
     * @param TranslatorInterface $trans
20
     * @param array $options
21
     */
22
    public function __construct(UtilInterface $util, TranslatorInterface $trans, array $options)
23
    {
24
        parent::__construct($util, $trans, $options);
25
26
        $this->server = new Db\Server($this, $this->util, $this->trans);
27
        $this->database = new Db\Database($this, $this->util, $this->trans);
28
        $this->table = new Db\Table($this, $this->util, $this->trans);
29
        $this->query = new Db\Query($this, $this->util, $this->trans);
30
        $this->grammar = new Db\Grammar($this, $this->util, $this->trans);
31
    }
32
33
    /**
34
     * @inheritDoc
35
     */
36
    public function name()
37
    {
38
        return "SQLite 3";
39
    }
40
41
    /**
42
     * @inheritDoc
43
     */
44
    protected function initConfig()
45
    {
46
        // Init config
47
        $this->config->jush = 'sqlite';
48
        $this->config->drivers = ["SQLite3", "PDO_SQLite"];
49
        $this->config->setTypes([ //! arrays
50
            'Numbers' => ["integer" => 0, "real" => 0, "numeric" => 0],
51
            'Strings' => ["text" => 0],
52
            'Binary' => ["blob" => 0],
53
        ]);
54
        // $this->config->unsigned = [];
55
        $this->config->operators = ["=", "<", ">", "<=", ">=", "!=", "LIKE", "LIKE %%",
56
            "IN", "IS NULL", "NOT LIKE", "NOT IN", "IS NOT NULL", "SQL"]; // REGEXP can be user defined function;
57
        $this->config->functions = ["hex", "length", "lower", "round", "unixepoch", "upper"];
58
        $this->config->grouping = ["avg", "count", "count distinct", "group_concat", "max", "min", "sum"];
59
        $this->config->editFunctions = [[
60
            // "text" => "date('now')/time('now')/datetime('now')",
61
        ],[
62
            "integer|real|numeric" => "+/-",
63
            // "text" => "date/time/datetime",
64
            "text" => "||",
65
        ]];
66
        $this->config->features = ['columns', 'database', 'drop_col', 'dump', 'indexes', 'descidx',
67
            'move_col', 'sql', 'status', 'table', 'trigger', 'variables', 'view', 'view_trigger'];
68
    }
69
70
    /**
71
     * @inheritDoc
72
     */
73
    protected function postConnectConfig()
74
    {}
75
76
    /**
77
     * @inheritDoc
78
     * @throws AuthException
79
     */
80
    protected function createConnection()
81
    {
82
        if (!$this->options('prefer_pdo', false) && class_exists("SQLite3")) {
83
            $connection = new Db\Sqlite\Connection($this, $this->util, $this->trans, 'SQLite3');
84
            return $this->connection = $connection;
85
        }
86
        if (extension_loaded("pdo_sqlite")) {
87
            $connection = new Db\Pdo\Connection($this, $this->util, $this->trans, 'PDO_SQLite');
88
            return $this->connection = $connection;
89
        }
90
        throw new AuthException($this->trans->lang('No package installed to open a Sqlite database.'));
91
    }
92
}
93