Passed
Push — main ( 490261...bec1fb )
by Thierry
01:59
created

DbAdmin   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 108
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 29
dl 0
loc 108
rs 10
c 0
b 0
f 0
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A connect() 0 14 2
A getBreadcrumbs() 0 3 1
A lang() 0 3 1
A __construct() 0 8 1
A setBreadcrumbs() 0 3 1
A admin() 0 3 1
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;
0 ignored issues
show
Bug introduced by
The trait Lagdo\DbAdmin\DbAdmin\TableTrait requires the property $input which is not provided by Lagdo\DbAdmin\DbAdmin.
Loading history...
22
    use DbAdmin\TableSelectTrait;
0 ignored issues
show
Bug introduced by
The trait Lagdo\DbAdmin\DbAdmin\TableSelectTrait requires the property $input which is not provided by Lagdo\DbAdmin\DbAdmin.
Loading history...
23
    use DbAdmin\TableQueryTrait;
0 ignored issues
show
Bug introduced by
The trait Lagdo\DbAdmin\DbAdmin\TableQueryTrait requires the property $input which is not provided by Lagdo\DbAdmin\DbAdmin.
Loading history...
24
    use DbAdmin\ViewTrait;
0 ignored issues
show
Bug introduced by
The trait Lagdo\DbAdmin\DbAdmin\ViewTrait requires the property $input which is not provided by Lagdo\DbAdmin\DbAdmin.
Loading history...
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', $this->trans);
0 ignored issues
show
Bug introduced by
$this->trans of type object is incompatible with the type string expected by parameter $value of Jaxon\Utils\View\Renderer::share(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

55
        $jaxon->view()->share('trans', /** @scrutinizer ignore-type */ $this->trans);
Loading history...
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