| 1 | <?php |
||||||||||
| 2 | |||||||||||
| 3 | use Lagdo\DbAdmin\Db; |
||||||||||
| 4 | use Lagdo\DbAdmin\Db\Config; |
||||||||||
| 5 | use Lagdo\DbAdmin\Db\Driver\Exception; |
||||||||||
|
0 ignored issues
–
show
|
|||||||||||
| 6 | use Lagdo\DbAdmin\Db\Driver\Facades; |
||||||||||
| 7 | use Lagdo\DbAdmin\Db\Service; |
||||||||||
| 8 | use Lagdo\DbAdmin\Driver; |
||||||||||
| 9 | use Lagdo\DbAdmin\Ui; |
||||||||||
| 10 | |||||||||||
| 11 | use function Jaxon\jaxon; |
||||||||||
| 12 | |||||||||||
| 13 | function getAuth($di): Config\AuthInterface |
||||||||||
| 14 | { |
||||||||||
| 15 | return $di->h(Config\AuthInterface::class) ? |
||||||||||
| 16 | $di->g(Config\AuthInterface::class) : |
||||||||||
| 17 | new class implements Config\AuthInterface { |
||||||||||
| 18 | public function user(): string |
||||||||||
| 19 | { |
||||||||||
| 20 | return ''; |
||||||||||
| 21 | } |
||||||||||
| 22 | public function role(): string |
||||||||||
| 23 | { |
||||||||||
| 24 | return ''; |
||||||||||
| 25 | } |
||||||||||
| 26 | }; |
||||||||||
| 27 | } |
||||||||||
| 28 | |||||||||||
| 29 | return [ |
||||||||||
| 30 | 'metadata' => [ |
||||||||||
| 31 | 'format' => 'attributes', |
||||||||||
| 32 | ], |
||||||||||
| 33 | 'directories' => [ |
||||||||||
| 34 | [ |
||||||||||
| 35 | 'path' => __DIR__ . '/../app/ajax/Admin', |
||||||||||
| 36 | 'namespace' => 'Lagdo\\DbAdmin\\Ajax\\Admin', |
||||||||||
| 37 | 'autoload' => false, |
||||||||||
| 38 | ], |
||||||||||
| 39 | ], |
||||||||||
| 40 | 'views' => [ |
||||||||||
| 41 | 'dbadmin::codes' => [ |
||||||||||
| 42 | 'directory' => __DIR__ . '/../templates/codes', |
||||||||||
| 43 | 'extension' => '', |
||||||||||
| 44 | 'renderer' => 'jaxon', |
||||||||||
| 45 | ], |
||||||||||
| 46 | 'dbadmin::views' => [ |
||||||||||
| 47 | 'directory' => __DIR__ . '/../templates/views', |
||||||||||
| 48 | 'extension' => '.php', |
||||||||||
| 49 | 'renderer' => 'jaxon', |
||||||||||
| 50 | ], |
||||||||||
| 51 | 'dbadmin::templates' => [ |
||||||||||
| 52 | 'directory' => __DIR__ . '/../templates/views', |
||||||||||
| 53 | 'extension' => '.php', |
||||||||||
| 54 | 'renderer' => 'jaxon', |
||||||||||
| 55 | ], |
||||||||||
| 56 | 'pagination' => [ |
||||||||||
| 57 | 'directory' => __DIR__ . '/../templates/pagination', |
||||||||||
| 58 | 'extension' => '.php', |
||||||||||
| 59 | 'renderer' => 'jaxon', |
||||||||||
| 60 | ], |
||||||||||
| 61 | ], |
||||||||||
| 62 | 'container' => [ |
||||||||||
| 63 | 'set' => [ |
||||||||||
| 64 | // Selected database driver |
||||||||||
| 65 | Driver\DriverInterface::class => function($di) { |
||||||||||
| 66 | // Register a driver for each database server. |
||||||||||
| 67 | $package = $di->g(Db\DbAdminPackage::class); |
||||||||||
| 68 | foreach($package->getServers() as $server => $options) { |
||||||||||
| 69 | $di->set("dbadmin_driver_$server", fn() => |
||||||||||
| 70 | Db\Driver\AppDriver::createDriver($options)); |
||||||||||
| 71 | } |
||||||||||
| 72 | |||||||||||
| 73 | $server = $di->g('dbadmin_config_server'); |
||||||||||
| 74 | return $di->g("dbadmin_driver_$server"); |
||||||||||
| 75 | }, |
||||||||||
| 76 | // The database driver used in the application |
||||||||||
| 77 | Db\Driver\AppDriver::class => function($di) { |
||||||||||
| 78 | // This class will "clone" the selected driver, and define the callbacks. |
||||||||||
| 79 | // By doing this, the driver classes will call the driver without the callbacks. |
||||||||||
| 80 | $driver = new Db\Driver\AppDriver($di->g(Driver\DriverInterface::class)); |
||||||||||
| 81 | $timer = $di->g(Service\TimerService::class); |
||||||||||
| 82 | $driver->addQueryCallback(fn() => $timer->stop()); |
||||||||||
| 83 | $logger = $di->g(Service\Admin\QueryLogger::class); |
||||||||||
| 84 | if ($logger !== null) { |
||||||||||
| 85 | $driver->addQueryCallback(fn(string $query) => $logger->saveCommand($query)); |
||||||||||
| 86 | } |
||||||||||
| 87 | return $driver; |
||||||||||
| 88 | }, |
||||||||||
| 89 | // Facades to the DB driver features |
||||||||||
| 90 | Facades\CommandFacade::class => function($di) { |
||||||||||
| 91 | $dbFacade = $di->g(Db\Driver\DbFacade::class); |
||||||||||
| 92 | $timer = $di->g(Service\TimerService::class); |
||||||||||
| 93 | $logger = $di->g(Service\Admin\QueryLogger::class); |
||||||||||
| 94 | return new Facades\CommandFacade($dbFacade, $timer, $logger); |
||||||||||
| 95 | }, |
||||||||||
| 96 | Facades\DatabaseFacade::class => function($di) { |
||||||||||
| 97 | $dbFacade = $di->g(Db\Driver\DbFacade::class); |
||||||||||
| 98 | $server = $di->g('dbadmin_config_server'); |
||||||||||
| 99 | $package = $di->g(Db\DbAdminPackage::class); |
||||||||||
| 100 | $options = $package->getServerOptions($server); |
||||||||||
| 101 | return new Facades\DatabaseFacade($dbFacade, $options); |
||||||||||
| 102 | }, |
||||||||||
| 103 | Facades\ExportFacade::class => function($di) { |
||||||||||
| 104 | $dbFacade = $di->g(Db\Driver\DbFacade::class); |
||||||||||
| 105 | return new Facades\ExportFacade($dbFacade); |
||||||||||
| 106 | }, |
||||||||||
| 107 | Facades\ImportFacade::class => function($di) { |
||||||||||
| 108 | $dbFacade = $di->g(Db\Driver\DbFacade::class); |
||||||||||
| 109 | $timer = $di->g(Service\TimerService::class); |
||||||||||
| 110 | $logger = $di->g(Service\Admin\QueryLogger::class); |
||||||||||
| 111 | return new Facades\ImportFacade($dbFacade, $timer, $logger); |
||||||||||
| 112 | }, |
||||||||||
| 113 | Facades\QueryFacade::class => function($di) { |
||||||||||
| 114 | $dbFacade = $di->g(Db\Driver\DbFacade::class); |
||||||||||
| 115 | return new Facades\QueryFacade($dbFacade); |
||||||||||
| 116 | }, |
||||||||||
| 117 | Facades\SelectFacade::class => function($di) { |
||||||||||
| 118 | $dbFacade = $di->g(Db\Driver\DbFacade::class); |
||||||||||
| 119 | $timer = $di->g(Service\TimerService::class); |
||||||||||
| 120 | return new Facades\SelectFacade($dbFacade, $timer); |
||||||||||
| 121 | }, |
||||||||||
| 122 | Facades\ServerFacade::class => function($di) { |
||||||||||
| 123 | $dbFacade = $di->g(Db\Driver\DbFacade::class); |
||||||||||
| 124 | $server = $di->g('dbadmin_config_server'); |
||||||||||
| 125 | $package = $di->g(Db\DbAdminPackage::class); |
||||||||||
| 126 | $options = $package->getServerOptions($server); |
||||||||||
| 127 | return new Facades\ServerFacade($dbFacade, $options); |
||||||||||
| 128 | }, |
||||||||||
| 129 | Facades\TableFacade::class => function($di) { |
||||||||||
| 130 | $dbFacade = $di->g(Db\Driver\DbFacade::class); |
||||||||||
| 131 | return new Facades\TableFacade($dbFacade); |
||||||||||
| 132 | }, |
||||||||||
| 133 | Facades\UserFacade::class => function($di) { |
||||||||||
| 134 | $dbFacade = $di->g(Db\Driver\DbFacade::class); |
||||||||||
| 135 | return new Facades\UserFacade($dbFacade); |
||||||||||
| 136 | }, |
||||||||||
| 137 | Facades\ViewFacade::class => function($di) { |
||||||||||
| 138 | $dbFacade = $di->g(Db\Driver\DbFacade::class); |
||||||||||
| 139 | return new Facades\ViewFacade($dbFacade); |
||||||||||
| 140 | }, |
||||||||||
| 141 | Config\UserFileReader::class => function($di) { |
||||||||||
| 142 | return new Config\UserFileReader(getAuth($di)); |
||||||||||
| 143 | }, |
||||||||||
| 144 | // Database options for audit |
||||||||||
| 145 | 'dbaudit_database_server' => function($di) { |
||||||||||
| 146 | $package = $di->g(Db\DbAdminPackage::class); |
||||||||||
| 147 | return !$package->hasAuditDatabase() ? null : |
||||||||||
| 148 | $package->getOption('audit.database'); |
||||||||||
| 149 | }, |
||||||||||
| 150 | // Database driver for audit |
||||||||||
| 151 | 'dbaudit_database_driver' => function($di) { |
||||||||||
| 152 | $options = $di->g('dbaudit_database_server'); |
||||||||||
| 153 | return Db\Driver\AppDriver::createDriver($options); |
||||||||||
| 154 | }, |
||||||||||
| 155 | // Connection to the audit database |
||||||||||
| 156 | Service\Admin\ConnectionProxy::class => function($di) { |
||||||||||
| 157 | $driver = $di->g('dbaudit_database_driver'); |
||||||||||
| 158 | $database = $di->g('dbaudit_database_server'); |
||||||||||
| 159 | $reader = $di->g(Config\UserFileReader::class); |
||||||||||
| 160 | return new Service\Admin\ConnectionProxy(getAuth($di), $driver, |
||||||||||
| 161 | $reader->getServerOptions($database)); |
||||||||||
| 162 | }, |
||||||||||
| 163 | // Query logger |
||||||||||
| 164 | Service\Admin\QueryLogger::class => function($di) { |
||||||||||
| 165 | $package = $di->g(Db\DbAdminPackage::class); |
||||||||||
| 166 | $options = $package->getOption('audit.options'); |
||||||||||
| 167 | $database = $di->g('dbaudit_database_server'); |
||||||||||
| 168 | if (!is_array($database) || !is_array($options) || |
||||||||||
| 169 | !$di->h(Config\AuthInterface::class)) { |
||||||||||
| 170 | return null; |
||||||||||
| 171 | } |
||||||||||
| 172 | |||||||||||
| 173 | // User database, different from the audit database. |
||||||||||
| 174 | $server = $di->g('dbadmin_config_server'); |
||||||||||
| 175 | $serverOptions = $package->getServerOptions($server); |
||||||||||
| 176 | $dbFacade = $di->g(Db\Driver\DbFacade::class); |
||||||||||
| 177 | $options['database'] = $dbFacade->getDatabaseOptions($serverOptions); |
||||||||||
| 178 | |||||||||||
| 179 | $proxy = $di->g(Service\Admin\ConnectionProxy::class); |
||||||||||
| 180 | return new Service\Admin\QueryLogger($proxy, $options); |
||||||||||
| 181 | }, |
||||||||||
| 182 | // Query history |
||||||||||
| 183 | Service\Admin\QueryHistory::class => function($di) { |
||||||||||
| 184 | $package = $di->g(Db\DbAdminPackage::class); |
||||||||||
| 185 | $options = $package->getOption('audit.options'); |
||||||||||
| 186 | $database = $di->g('dbaudit_database_server'); |
||||||||||
| 187 | if (!is_array($database) || !is_array($options) || |
||||||||||
| 188 | !$di->h(Config\AuthInterface::class)) { |
||||||||||
| 189 | return null; |
||||||||||
| 190 | } |
||||||||||
| 191 | |||||||||||
| 192 | $proxy = $di->g(Service\Admin\ConnectionProxy::class); |
||||||||||
| 193 | return new Service\Admin\QueryHistory($proxy, $options); |
||||||||||
| 194 | }, |
||||||||||
| 195 | // Query favorites |
||||||||||
| 196 | Service\Admin\QueryFavorite::class => function($di) { |
||||||||||
| 197 | $package = $di->g(Db\DbAdminPackage::class); |
||||||||||
| 198 | $options = $package->getOption('audit.options'); |
||||||||||
| 199 | $database = $di->g('dbaudit_database_server'); |
||||||||||
| 200 | if (!is_array($database) || !is_array($options) || |
||||||||||
| 201 | !$di->h(Config\AuthInterface::class)) { |
||||||||||
| 202 | return null; |
||||||||||
| 203 | } |
||||||||||
| 204 | |||||||||||
| 205 | $proxy = $di->g(Service\Admin\ConnectionProxy::class); |
||||||||||
| 206 | return new Service\Admin\QueryFavorite($proxy, $options); |
||||||||||
| 207 | }, |
||||||||||
| 208 | ], |
||||||||||
| 209 | 'auto' => [ |
||||||||||
| 210 | // The translator |
||||||||||
| 211 | Db\Translator::class, |
||||||||||
| 212 | // The string manipulation class |
||||||||||
| 213 | Driver\Utils\Str::class, |
||||||||||
| 214 | // The user input |
||||||||||
| 215 | Driver\Utils\Input::class, |
||||||||||
| 216 | // The utils class |
||||||||||
| 217 | Driver\Utils\Utils::class, |
||||||||||
| 218 | // The db classes |
||||||||||
| 219 | Db\Page\AppPage::class, |
||||||||||
| 220 | // The facade to the database features |
||||||||||
| 221 | Db\Driver\DbFacade::class, |
||||||||||
| 222 | // The Timer service |
||||||||||
| 223 | Service\TimerService::class, |
||||||||||
| 224 | // The UI builders |
||||||||||
| 225 | Ui\UiBuilder::class, |
||||||||||
| 226 | Ui\InputBuilder::class, |
||||||||||
| 227 | Ui\MenuBuilder::class, |
||||||||||
| 228 | Ui\Data\EditUiBuilder::class, |
||||||||||
| 229 | Ui\Select\OptionsUiBuilder::class, |
||||||||||
| 230 | Ui\Select\ResultUiBuilder::class, |
||||||||||
| 231 | Ui\Select\SelectUiBuilder::class, |
||||||||||
| 232 | Ui\Database\ServerUiBuilder::class, |
||||||||||
| 233 | Ui\Command\QueryUiBuilder::class, |
||||||||||
| 234 | Ui\Command\AuditUiBuilder::class, |
||||||||||
| 235 | Ui\Command\ImportUiBuilder::class, |
||||||||||
| 236 | Ui\Command\ExportUiBuilder::class, |
||||||||||
| 237 | Ui\Table\TableUiBuilder::class, |
||||||||||
| 238 | Ui\Table\ViewUiBuilder::class, |
||||||||||
| 239 | ], |
||||||||||
| 240 | 'alias' => [ |
||||||||||
| 241 | // The translator |
||||||||||
| 242 | Driver\Utils\TranslatorInterface::class => Db\Translator::class, |
||||||||||
| 243 | ], |
||||||||||
| 244 | ], |
||||||||||
| 245 | 'exceptions' => [ |
||||||||||
| 246 | Exception\DbException::class => function(Exception\DbException $dbException) { |
||||||||||
| 247 | $response = jaxon()->getResponse(); |
||||||||||
| 248 | $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
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
Loading history...
|
|||||||||||
| 249 | return $response; |
||||||||||
| 250 | }, |
||||||||||
| 251 | ], |
||||||||||
| 252 | ]; |
||||||||||
| 253 |
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: