config.php$0 ➔ role()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
use Lagdo\DbAdmin\Admin;
4
use Lagdo\DbAdmin\Command;
5
use Lagdo\DbAdmin\Config;
6
use Lagdo\DbAdmin\Db;
7
use Lagdo\DbAdmin\Driver;
8
use Lagdo\DbAdmin\Ui;
9
10
use function Jaxon\jaxon;
11
12
return [
13
    'metadata' => 'annotations',
14
    'directories' => [
15
        [
16
            'path' => __DIR__ . '/../app/ajax/App',
17
            'namespace' => 'Lagdo\\DbAdmin\\Ajax\\App',
18
            'autoload' => false,
19
        ],
20
    ],
21
    'views' => [
22
        'dbadmin::codes' => [
23
            'directory' => __DIR__ . '/../templates/codes',
24
            'extension' => '',
25
            'renderer' => 'jaxon',
26
        ],
27
        'dbadmin::views' => [
28
            'directory' => __DIR__ . '/../templates/views',
29
            'extension' => '.php',
30
            'renderer' => 'jaxon',
31
        ],
32
        'dbadmin::templates' => [
33
            'directory' => __DIR__ . '/../templates/views',
34
            'extension' => '.php',
35
            'renderer' => 'jaxon',
36
        ],
37
        'pagination' => [
38
            'directory' => __DIR__ . '/../templates/pagination',
39
            'extension' => '.php',
40
            'renderer' => 'jaxon',
41
        ],
42
    ],
43
    'container' => [
44
        'set' => [
45
            // Selected database driver
46
            Driver\DriverInterface::class => function($di) {
47
                // The key below is defined by the corresponding plugin package.
48
                return $di->g('dbadmin_driver_' . $di->g('dbadmin_config_driver'));
49
            },
50
            // The database driver used in the application
51
            Db\CallbackDriver::class => function($di) {
52
                // This class will "clone" the selected driver, and define the callbacks.
53
                // By doing this, the driver classes will call the driver without the callbacks.
54
                $driver = new Db\CallbackDriver($di->g(Driver\DriverInterface::class));
55
                $timer = $di->g(Command\TimerService::class);
56
                $driver->addQueryCallback(fn() => $timer->stop());
57
                $logging = $di->g(Command\LoggingService::class);
58
                if ($logging !== null) {
59
                    $driver->addQueryCallback(fn(string $query) => $logging->saveCommand($query));
60
                }
61
                return $driver;
62
            },
63
            // Facades to the DB driver features
64
            Db\Facades\CommandFacade::class => function($di) {
65
                $dbFacade = $di->g(Db\DbFacade::class);
66
                $timer = $di->g(Command\TimerService::class);
67
                $logging = $di->g(Command\LoggingService::class);
68
                return new Db\Facades\CommandFacade($dbFacade, $timer, $logging);
69
            },
70
            Db\Facades\DatabaseFacade::class => function($di) {
71
                $dbFacade = $di->g(Db\DbFacade::class);
72
                return new Db\Facades\DatabaseFacade($dbFacade, $dbFacade->getServerOptions());
73
            },
74
            Db\Facades\ExportFacade::class => function($di) {
75
                $dbFacade = $di->g(Db\DbFacade::class);
76
                return new Db\Facades\ExportFacade($dbFacade);
77
            },
78
            Db\Facades\ImportFacade::class => function($di) {
79
                $dbFacade = $di->g(Db\DbFacade::class);
80
                $timer = $di->g(Command\TimerService::class);
81
                $logging = $di->g(Command\LoggingService::class);
82
                return new Db\Facades\ImportFacade($dbFacade, $timer, $logging);
83
            },
84
            Db\Facades\QueryFacade::class => function($di) {
85
                $dbFacade = $di->g(Db\DbFacade::class);
86
                return new Db\Facades\QueryFacade($dbFacade);
87
            },
88
            Db\Facades\SelectFacade::class => function($di) {
89
                $dbFacade = $di->g(Db\DbFacade::class);
90
                $timer = $di->g(Command\TimerService::class);
91
                return new Db\Facades\SelectFacade($dbFacade, $timer);
92
            },
93
            Db\Facades\ServerFacade::class => function($di) {
94
                $dbFacade = $di->g(Db\DbFacade::class);
95
                return new Db\Facades\ServerFacade($dbFacade, $dbFacade->getServerOptions());
96
            },
97
            Db\Facades\TableFacade::class => function($di) {
98
                $dbFacade = $di->g(Db\DbFacade::class);
99
                return new Db\Facades\TableFacade($dbFacade);
100
            },
101
            Db\Facades\UserFacade::class => function($di) {
102
                $dbFacade = $di->g(Db\DbFacade::class);
103
                return new Db\Facades\UserFacade($dbFacade);
104
            },
105
            Db\Facades\ViewFacade::class => function($di) {
106
                $dbFacade = $di->g(Db\DbFacade::class);
107
                return new Db\Facades\ViewFacade($dbFacade);
108
            },
109
            Config\AuthInterface::class => fn() =>
110
                new class implements Config\AuthInterface {
111
                    public function user(): string
112
                    {
113
                        return '';
114
                    }
115
                    public function role(): string
116
                    {
117
                        return '';
118
                    }
119
                },
120
            Config\UserFileReader::class => function($di) {
121
                $auth = $di->get(Config\AuthInterface::class);
122
                return new Config\UserFileReader($auth);
123
            },
124
            // Query logging
125
            Command\LoggingService::class => function($di) {
126
                $package = $di->g(Lagdo\DbAdmin\Package::class);
127
                $options = $package->getOption('logging.options');
128
                $database = $package->getOption('logging.database');
129
                $driverId = 'dbadmin_driver_' . ($database['driver'] ?? '');
130
                if (!$di->h($driverId) || !is_array($options) || !is_array($database)) {
131
                    return null;
132
                }
133
134
                $auth = $di->g(Config\AuthInterface::class);
135
                $db = $di->g(Db\DbFacade::class);
136
                return new Command\LoggingService($auth, $db,
137
                    $di->g($driverId), $database, $options);
138
            },
139
        ],
140
        'auto' => [
141
            // The translator
142
            Lagdo\DbAdmin\Translator::class,
143
            // The string manipulation class
144
            Driver\Utils\Str::class,
145
            // The user input
146
            Driver\Utils\Input::class,
147
            // The utils class
148
            Driver\Utils\Utils::class,
149
            // The facade to the database features
150
            Db\DbFacade::class,
151
            // The Timer service
152
            Command\TimerService::class,
153
            // The db classes
154
            Admin\Admin::class,
155
            // The UI builders
156
            Ui\UiBuilder::class,
157
            Ui\InputBuilder::class,
158
            Ui\MenuBuilder::class,
159
            Ui\Database\ServerUiBuilder::class,
160
            Ui\Command\QueryUiBuilder::class,
161
            Ui\Command\ImportUiBuilder::class,
162
            Ui\Command\ExportUiBuilder::class,
163
            Ui\Table\SelectUiBuilder::class,
164
            Ui\Table\TableUiBuilder::class,
165
            Ui\Table\ViewUiBuilder::class,
166
        ],
167
        'alias' => [
168
            // The translator
169
            Driver\Utils\TranslatorInterface::class => Lagdo\DbAdmin\Translator::class,
170
        ],
171
    ],
172
    'exceptions' => [
173
        Db\Exception\DbException::class => function(Db\Exception\DbException $dbException) {
174
            $response = jaxon()->getResponse();
175
            $response->dialog->warning($dbException->getMessage());
0 ignored issues
show
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

175
            $response->dialog->/** @scrutinizer ignore-call */ 
176
                               warning($dbException->getMessage());
Loading history...
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

175
            $response->dialog->/** @scrutinizer ignore-call */ 
176
                               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...
176
            return $response;
177
        },
178
    ],
179
];
180