Passed
Push — main ( b09a59...ef0562 )
by Thierry
25:19 queued 18:47
created

DbAdmin::queries()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Lagdo\DbAdmin;
4
5
use Lagdo\DbAdmin\Driver\DriverInterface;
6
use Lagdo\DbAdmin\Driver\UtilInterface;
7
use Lagdo\DbAdmin\Db\Admin;
8
9
use Lagdo\DbAdmin\DbAdmin\AbstractAdmin;
10
11
use Exception;
12
13
/**
14
 * Admin to calls to the database functions
15
 */
16
class DbAdmin extends AbstractAdmin
17
{
18
    use DbAdmin\ServerTrait;
19
    use DbAdmin\UserTrait;
20
    use DbAdmin\DatabaseTrait;
21
    use DbAdmin\TableTrait;
22
    use DbAdmin\TableSelectTrait;
23
    use DbAdmin\TableQueryTrait;
24
    use DbAdmin\ViewTrait;
25
    use DbAdmin\CommandTrait;
26
    use DbAdmin\ExportTrait;
27
    use DbAdmin\ImportTrait;
28
29
    /**
30
     * The breadcrumbs items
31
     *
32
     * @var array
33
     */
34
    protected $breadcrumbs = [];
35
36
    /**
37
     * The Jaxon Adminer package
38
     *
39
     * @var Package
40
     */
41
    protected $package;
42
43
    /**
44
     * The constructor
45
     *
46
     * @param Package $package    The Adminer package
47
     */
48
    public function __construct(Package $package)
49
    {
50
        $this->package = $package;
51
52
        $jaxon = \jaxon();
53
        $this->trans = $jaxon->di()->get(Db\Translator::class);
54
        // Make the translator available into views
55
        $jaxon->view()->share('trans', /** @scrutinizer ignore-type */ $this->trans);
56
    }
57
58
    /**
59
     * Get a translated string
60
     * The first parameter is mandatory. Optional parameters can follow.
61
     *
62
     * @param string
63
     *
64
     * @return string
65
     */
66
    public function lang($idf)
67
    {
68
        return \call_user_func_array([$this->trans, "lang"], \func_get_args());
69
    }
70
71
    /**
72
     * Get the breadcrumbs items
73
     *
74
     * @return array
75
     */
76
    public function getBreadcrumbs()
77
    {
78
        return $this->breadcrumbs;
79
    }
80
81
    /**
82
     * Set the breadcrumbs items
83
     *
84
     * @param array $breadcrumbs
85
     *
86
     * @return void
87
     */
88
    protected function setBreadcrumbs(array $breadcrumbs)
89
    {
90
        $this->breadcrumbs = $breadcrumbs;
91
    }
92
93
    /**
94
     * @return AbstractAdmin
95
     */
96
    public function admin()
97
    {
98
        return $this;
99
    }
100
101
    /**
102
     * Connect to a database server
103
     *
104
     * @param string $server    The selected server
105
     * @param string $database  The database name
106
     * @param string $schema    The database schema
107
     *
108
     * @return array
109
     */
110
    public function connect(string $server, string $database = '', string $schema = '')
111
    {
112
        // Prevent multiple calls.
113
        if (!$this->driver) {
114
            $di = \jaxon()->di();
115
            // Save the selected server options in the di container.
116
            $di->val('adminer_config_driver', $this->package->getServerDriver($server));
117
            $di->val('adminer_config_options', $this->package->getServerOptions($server));
118
            $this->driver = $di->get(DriverInterface::class);
119
            $this->util = $di->get(UtilInterface::class);
120
            $this->admin = $di->get(Admin::class);
121
        }
122
        // Connect to the selected server
123
        $this->driver->connect($database, $schema);
124
    }
125
126
    /**
127
     * Get the remembered queries
128
     *
129
     * @return array
130
     */
131
    public function queries()
132
    {
133
        return $this->driver->queries();
134
    }
135
}
136