Issues (56)

config/dbadmin.php (2 issues)

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

242
            $response->dialog->/** @scrutinizer ignore-call */ 
243
                               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...
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

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