dbadmin.php$0 ➔ user()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
1
<?php
2
3
use Lagdo\DbAdmin\Admin;
4
use Lagdo\DbAdmin\Config;
5
use Lagdo\DbAdmin\Db;
6
use Lagdo\DbAdmin\Driver;
7
use Lagdo\DbAdmin\Service;
8
use Lagdo\DbAdmin\Ui;
9
10
use function Jaxon\jaxon;
11
12
function getAuth($di): Config\AuthInterface
13
{
14
    return $di->h(Config\AuthInterface::class) ?
15
        $di->g(Config\AuthInterface::class) :
16
        new class implements Config\AuthInterface {
17
            public function user(): string
18
            {
19
                return '';
20
            }
21
            public function role(): string
22
            {
23
                return '';
24
            }
25
        };
26
}
27
28
return [
29
    'metadata' => 'annotations',
30
    'directories' => [
31
        [
32
            'path' => __DIR__ . '/../app/ajax/App',
33
            'namespace' => 'Lagdo\\DbAdmin\\Ajax\\App',
34
            'autoload' => false,
35
        ],
36
    ],
37
    'views' => [
38
        'dbadmin::codes' => [
39
            'directory' => __DIR__ . '/../templates/codes',
40
            'extension' => '',
41
            'renderer' => 'jaxon',
42
        ],
43
        'dbadmin::views' => [
44
            'directory' => __DIR__ . '/../templates/views',
45
            'extension' => '.php',
46
            'renderer' => 'jaxon',
47
        ],
48
        'dbadmin::templates' => [
49
            'directory' => __DIR__ . '/../templates/views',
50
            'extension' => '.php',
51
            'renderer' => 'jaxon',
52
        ],
53
        'pagination' => [
54
            'directory' => __DIR__ . '/../templates/pagination',
55
            'extension' => '.php',
56
            'renderer' => 'jaxon',
57
        ],
58
    ],
59
    'container' => [
60
        'set' => [
61
            // Selected database driver
62
            Driver\DriverInterface::class => function($di) {
63
                // Register a driver for each database server.
64
                $package = $di->g(Lagdo\DbAdmin\DbAdminPackage::class);
65
                foreach($package->getServers() as $server => $options) {
66
                    $di->set("dbadmin_driver_$server", fn() =>
67
                        Driver\Driver::createDriver($options));
68
                }
69
70
                $server = $di->g('dbadmin_config_server');
71
                return $di->g("dbadmin_driver_$server");
72
            },
73
            // The database driver used in the application
74
            Db\AppDriver::class => function($di) {
75
                // This class will "clone" the selected driver, and define the callbacks.
76
                // By doing this, the driver classes will call the driver without the callbacks.
77
                $driver = new Db\AppDriver($di->g(Driver\DriverInterface::class));
78
                $timer = $di->g(Service\TimerService::class);
79
                $driver->addQueryCallback(fn() => $timer->stop());
80
                $logger = $di->g(Service\DbAdmin\QueryLogger::class);
81
                if ($logger !== null) {
82
                    $driver->addQueryCallback(fn(string $query) => $logger->saveCommand($query));
83
                }
84
                return $driver;
85
            },
86
            // Facades to the DB driver features
87
            Db\Facades\CommandFacade::class => function($di) {
88
                $dbFacade = $di->g(Db\DbFacade::class);
89
                $timer = $di->g(Service\TimerService::class);
90
                $logger = $di->g(Service\DbAdmin\QueryLogger::class);
91
                return new Db\Facades\CommandFacade($dbFacade, $timer, $logger);
92
            },
93
            Db\Facades\DatabaseFacade::class => function($di) {
94
                $dbFacade = $di->g(Db\DbFacade::class);
95
                $server = $di->g('dbadmin_config_server');
96
                $package = $di->g(Lagdo\DbAdmin\DbAdminPackage::class);
97
                $options = $package->getServerOptions($server);
98
                return new Db\Facades\DatabaseFacade($dbFacade, $options);
99
            },
100
            Db\Facades\ExportFacade::class => function($di) {
101
                $dbFacade = $di->g(Db\DbFacade::class);
102
                return new Db\Facades\ExportFacade($dbFacade);
103
            },
104
            Db\Facades\ImportFacade::class => function($di) {
105
                $dbFacade = $di->g(Db\DbFacade::class);
106
                $timer = $di->g(Service\TimerService::class);
107
                $logger = $di->g(Service\DbAdmin\QueryLogger::class);
108
                return new Db\Facades\ImportFacade($dbFacade, $timer, $logger);
109
            },
110
            Db\Facades\QueryFacade::class => function($di) {
111
                $dbFacade = $di->g(Db\DbFacade::class);
112
                return new Db\Facades\QueryFacade($dbFacade);
113
            },
114
            Db\Facades\SelectFacade::class => function($di) {
115
                $dbFacade = $di->g(Db\DbFacade::class);
116
                $timer = $di->g(Service\TimerService::class);
117
                return new Db\Facades\SelectFacade($dbFacade, $timer);
118
            },
119
            Db\Facades\ServerFacade::class => function($di) {
120
                $dbFacade = $di->g(Db\DbFacade::class);
121
                $server = $di->g('dbadmin_config_server');
122
                $package = $di->g(Lagdo\DbAdmin\DbAdminPackage::class);
123
                $options = $package->getServerOptions($server);
124
                return new Db\Facades\ServerFacade($dbFacade, $options);
125
            },
126
            Db\Facades\TableFacade::class => function($di) {
127
                $dbFacade = $di->g(Db\DbFacade::class);
128
                return new Db\Facades\TableFacade($dbFacade);
129
            },
130
            Db\Facades\UserFacade::class => function($di) {
131
                $dbFacade = $di->g(Db\DbFacade::class);
132
                return new Db\Facades\UserFacade($dbFacade);
133
            },
134
            Db\Facades\ViewFacade::class => function($di) {
135
                $dbFacade = $di->g(Db\DbFacade::class);
136
                return new Db\Facades\ViewFacade($dbFacade);
137
            },
138
            Config\UserFileReader::class => function($di) {
139
                return new Config\UserFileReader(getAuth($di));
140
            },
141
            // Database options for logging
142
            'dbadmin_logging_database' => function($di) {
143
                $package = $di->g(Lagdo\DbAdmin\DbAdminPackage::class);
144
                return !$package->hasLoggingDatabase() ? null :
145
                    $package->getOption('logging.database');
146
            },
147
            // Database driver for logging
148
            'dbadmin_logging_driver' => function($di) {
149
                $options = $di->g('dbadmin_logging_database');
150
                return Driver\Driver::createDriver($options);
151
            },
152
            // Query logger
153
            Service\DbAdmin\QueryLogger::class => function($di) {
154
                $package = $di->g(Lagdo\DbAdmin\DbAdminPackage::class);
155
                $options = $package->getOption('logging.options');
156
                $database = $di->g('dbadmin_logging_database');
157
                if (!is_array($database) || !is_array($options) ||
158
                    !$di->h(Config\AuthInterface::class)) {
159
                    return null;
160
                }
161
162
                // User database, different from the logging database.
163
                $server = $di->g('dbadmin_config_server');
164
                $serverOptions = $package->getServerOptions($server);
165
                $dbFacade = $di->g(Db\DbFacade::class);
166
                $options['database'] = $dbFacade->getDatabaseOptions($serverOptions);
167
168
                $reader = $di->g(Config\UserFileReader::class);
169
                $database = $reader->getServerOptions($database);
170
                return new Service\DbAdmin\QueryLogger(getAuth($di),
171
                    $di->g('dbadmin_logging_driver'), $database, $options);
172
            },
173
            // Query history
174
            Service\DbAdmin\QueryHistory::class => function($di) {
175
                $package = $di->g(Lagdo\DbAdmin\DbAdminPackage::class);
176
                $options = $package->getOption('logging.options');
177
                $database = $di->g('dbadmin_logging_database');
178
                if (!is_array($database) || !is_array($options) ||
179
                    !$di->h(Config\AuthInterface::class)) {
180
                    return null;
181
                }
182
183
                $reader = $di->g(Config\UserFileReader::class);
184
                $database = $reader->getServerOptions($database);
185
                return new Service\DbAdmin\QueryHistory(getAuth($di),
186
                    $di->g('dbadmin_logging_driver'), $database, $options);
187
            },
188
            // Query favorites
189
            Service\DbAdmin\QueryFavorite::class => function($di) {
190
                $package = $di->g(Lagdo\DbAdmin\DbAdminPackage::class);
191
                $options = $package->getOption('logging.options');
192
                $database = $di->g('dbadmin_logging_database');
193
                if (!is_array($database) || !is_array($options) ||
194
                    !$di->h(Config\AuthInterface::class)) {
195
                    return null;
196
                }
197
198
                $reader = $di->g(Config\UserFileReader::class);
199
                $database = $reader->getServerOptions($database);
200
                return new Service\DbAdmin\QueryFavorite(getAuth($di),
201
                    $di->g('dbadmin_logging_driver'), $database, $options);
202
            },
203
        ],
204
        'auto' => [
205
            // The translator
206
            Lagdo\DbAdmin\Translator::class,
207
            // The string manipulation class
208
            Driver\Utils\Str::class,
209
            // The user input
210
            Driver\Utils\Input::class,
211
            // The utils class
212
            Driver\Utils\Utils::class,
213
            // The facade to the database features
214
            Db\DbFacade::class,
215
            // The Timer service
216
            Service\TimerService::class,
217
            // The db classes
218
            Admin\Admin::class,
219
            // The UI builders
220
            Ui\UiBuilder::class,
221
            Ui\InputBuilder::class,
222
            Ui\MenuBuilder::class,
223
            Ui\Database\ServerUiBuilder::class,
224
            Ui\Command\QueryUiBuilder::class,
225
            Ui\Command\LogUiBuilder::class,
226
            Ui\Command\ImportUiBuilder::class,
227
            Ui\Command\ExportUiBuilder::class,
228
            Ui\Table\SelectUiBuilder::class,
229
            Ui\Table\TableUiBuilder::class,
230
            Ui\Table\ViewUiBuilder::class,
231
        ],
232
        'alias' => [
233
            // The translator
234
            Driver\Utils\TranslatorInterface::class => Lagdo\DbAdmin\Translator::class,
235
        ],
236
    ],
237
    'exceptions' => [
238
        Db\Exception\DbException::class => function(Db\Exception\DbException $dbException) {
239
            $response = jaxon()->getResponse();
240
            $response->dialog->warning($dbException->getMessage());
0 ignored issues
show
Bug introduced by
The method warning() does not exist on null. ( Ignorable by Annotation )

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

240
            $response->dialog->/** @scrutinizer ignore-call */ 
241
                               warning($dbException->getMessage());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method warning() does not exist on Jaxon\Plugin\ResponsePluginInterface. It seems like you code against a sub-type of Jaxon\Plugin\ResponsePluginInterface such as Jaxon\Plugin\Response\Dialog\DialogPlugin. ( Ignorable by Annotation )

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

240
            $response->dialog->/** @scrutinizer ignore-call */ 
241
                               warning($dbException->getMessage());
Loading history...
241
            return $response;
242
        },
243
    ],
244
];
245