| 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(): Config\AuthInterface |
||||||||||
| 14 | { |
||||||||||
| 15 | return new class implements Config\AuthInterface { |
||||||||||
| 16 | public function user(): string |
||||||||||
| 17 | { |
||||||||||
| 18 | return ''; |
||||||||||
| 19 | } |
||||||||||
| 20 | public function role(): string |
||||||||||
| 21 | { |
||||||||||
| 22 | return ''; |
||||||||||
| 23 | } |
||||||||||
| 24 | }; |
||||||||||
| 25 | } |
||||||||||
| 26 | |||||||||||
| 27 | return [ |
||||||||||
| 28 | 'metadata' => [ |
||||||||||
| 29 | 'format' => 'attributes', |
||||||||||
| 30 | ], |
||||||||||
| 31 | 'directories' => [ |
||||||||||
| 32 | [ |
||||||||||
| 33 | 'path' => __DIR__ . '/../app/ajax/Audit', |
||||||||||
| 34 | 'namespace' => 'Lagdo\\DbAdmin\\Ajax\\Audit', |
||||||||||
| 35 | 'autoload' => false, |
||||||||||
| 36 | ], |
||||||||||
| 37 | ], |
||||||||||
| 38 | 'views' => [ |
||||||||||
| 39 | 'dbadmin::codes' => [ |
||||||||||
| 40 | 'directory' => __DIR__ . '/../templates/codes', |
||||||||||
| 41 | 'extension' => '', |
||||||||||
| 42 | 'renderer' => 'jaxon', |
||||||||||
| 43 | ], |
||||||||||
| 44 | 'dbadmin::views' => [ |
||||||||||
| 45 | 'directory' => __DIR__ . '/../templates/views', |
||||||||||
| 46 | 'extension' => '.php', |
||||||||||
| 47 | 'renderer' => 'jaxon', |
||||||||||
| 48 | ], |
||||||||||
| 49 | 'dbadmin::templates' => [ |
||||||||||
| 50 | 'directory' => __DIR__ . '/../templates/views', |
||||||||||
| 51 | 'extension' => '.php', |
||||||||||
| 52 | 'renderer' => 'jaxon', |
||||||||||
| 53 | ], |
||||||||||
| 54 | 'pagination' => [ |
||||||||||
| 55 | 'directory' => __DIR__ . '/../templates/pagination', |
||||||||||
| 56 | 'extension' => '.php', |
||||||||||
| 57 | 'renderer' => 'jaxon', |
||||||||||
| 58 | ], |
||||||||||
| 59 | ], |
||||||||||
| 60 | 'container' => [ |
||||||||||
| 61 | 'set' => [ |
||||||||||
| 62 | // Selected database driver |
||||||||||
| 63 | Driver\DriverInterface::class => function($di) { |
||||||||||
| 64 | // Register a driver for each database server. |
||||||||||
| 65 | $package = $di->g(Db\DbAdminPackage::class); |
||||||||||
| 66 | foreach($package->getServers() as $server => $options) { |
||||||||||
| 67 | $di->set("dbadmin_driver_$server", fn() => |
||||||||||
| 68 | Db\Driver\AppDriver::createDriver($options)); |
||||||||||
| 69 | } |
||||||||||
| 70 | |||||||||||
| 71 | $server = $di->g('dbadmin_config_server'); |
||||||||||
| 72 | return $di->g("dbadmin_driver_$server"); |
||||||||||
| 73 | }, |
||||||||||
| 74 | // Facades to the DB driver features |
||||||||||
| 75 | Facades\CommandFacade::class => function($di) { |
||||||||||
| 76 | $dbFacade = $di->g(Db\Driver\DbFacade::class); |
||||||||||
| 77 | $timer = $di->g(Service\TimerService::class); |
||||||||||
| 78 | $logger = $di->g(Service\Admin\QueryLogger::class); |
||||||||||
| 79 | return new Facades\CommandFacade($dbFacade, $timer, $logger); |
||||||||||
| 80 | }, |
||||||||||
| 81 | Facades\DatabaseFacade::class => function($di) { |
||||||||||
| 82 | $dbFacade = $di->g(Db\Driver\DbFacade::class); |
||||||||||
| 83 | $server = $di->g('dbadmin_config_server'); |
||||||||||
| 84 | $package = $di->g(Db\DbAdminPackage::class); |
||||||||||
| 85 | $options = $package->getServerOptions($server); |
||||||||||
| 86 | return new Facades\DatabaseFacade($dbFacade, $options); |
||||||||||
| 87 | }, |
||||||||||
| 88 | Facades\ExportFacade::class => function($di) { |
||||||||||
| 89 | $dbFacade = $di->g(Db\Driver\DbFacade::class); |
||||||||||
| 90 | return new Facades\ExportFacade($dbFacade); |
||||||||||
| 91 | }, |
||||||||||
| 92 | Facades\ImportFacade::class => function($di) { |
||||||||||
| 93 | $dbFacade = $di->g(Db\Driver\DbFacade::class); |
||||||||||
| 94 | $timer = $di->g(Service\TimerService::class); |
||||||||||
| 95 | $logger = $di->g(Service\Admin\QueryLogger::class); |
||||||||||
| 96 | return new Facades\ImportFacade($dbFacade, $timer, $logger); |
||||||||||
| 97 | }, |
||||||||||
| 98 | Facades\QueryFacade::class => function($di) { |
||||||||||
| 99 | $dbFacade = $di->g(Db\Driver\DbFacade::class); |
||||||||||
| 100 | return new Facades\QueryFacade($dbFacade); |
||||||||||
| 101 | }, |
||||||||||
| 102 | Facades\SelectFacade::class => function($di) { |
||||||||||
| 103 | $dbFacade = $di->g(Db\Driver\DbFacade::class); |
||||||||||
| 104 | $timer = $di->g(Service\TimerService::class); |
||||||||||
| 105 | return new Facades\SelectFacade($dbFacade, $timer); |
||||||||||
| 106 | }, |
||||||||||
| 107 | Facades\ServerFacade::class => function($di) { |
||||||||||
| 108 | $dbFacade = $di->g(Db\Driver\DbFacade::class); |
||||||||||
| 109 | $server = $di->g('dbadmin_config_server'); |
||||||||||
| 110 | $package = $di->g(Db\DbAdminPackage::class); |
||||||||||
| 111 | $options = $package->getServerOptions($server); |
||||||||||
| 112 | return new Facades\ServerFacade($dbFacade, $options); |
||||||||||
| 113 | }, |
||||||||||
| 114 | Facades\TableFacade::class => function($di) { |
||||||||||
| 115 | $dbFacade = $di->g(Db\Driver\DbFacade::class); |
||||||||||
| 116 | return new Facades\TableFacade($dbFacade); |
||||||||||
| 117 | }, |
||||||||||
| 118 | Facades\UserFacade::class => function($di) { |
||||||||||
| 119 | $dbFacade = $di->g(Db\Driver\DbFacade::class); |
||||||||||
| 120 | return new Facades\UserFacade($dbFacade); |
||||||||||
| 121 | }, |
||||||||||
| 122 | Facades\ViewFacade::class => function($di) { |
||||||||||
| 123 | $dbFacade = $di->g(Db\Driver\DbFacade::class); |
||||||||||
| 124 | return new Facades\ViewFacade($dbFacade); |
||||||||||
| 125 | }, |
||||||||||
| 126 | Config\UserFileReader::class => function() { |
||||||||||
| 127 | return new Config\UserFileReader(getAuth()); |
||||||||||
|
0 ignored issues
–
show
The call to
getAuth() has too few arguments starting with di.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above. Loading history...
|
|||||||||||
| 128 | }, |
||||||||||
| 129 | // Connection to the audit database |
||||||||||
| 130 | Service\Audit\ConnectionProxy::class => function($di) { |
||||||||||
| 131 | $package = $di->g(Db\DbAuditPackage::class); |
||||||||||
| 132 | $database = $package->getOption('database'); |
||||||||||
| 133 | $driver = Db\Driver\AppDriver::createDriver($database); |
||||||||||
| 134 | $reader = $di->g(Config\UserFileReader::class); |
||||||||||
| 135 | return new Service\Audit\ConnectionProxy($driver, |
||||||||||
|
0 ignored issues
–
show
It seems like
$driver can also be of type null; however, parameter $driver of Lagdo\DbAdmin\Db\Service...ionProxy::__construct() does only seem to accept Lagdo\DbAdmin\Driver\DriverInterface, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||||||
| 136 | $reader->getServerOptions($database)); |
||||||||||
| 137 | }, |
||||||||||
| 138 | // Query audit |
||||||||||
| 139 | Service\Audit\QueryLogger::class => function($di) { |
||||||||||
| 140 | $package = $di->g(Db\DbAuditPackage::class); |
||||||||||
| 141 | $database = $package->getOption('database'); |
||||||||||
| 142 | $options = $package->getOption('options', []); |
||||||||||
| 143 | if (!is_array($database) || !is_array($options)) { |
||||||||||
| 144 | return null; |
||||||||||
| 145 | } |
||||||||||
| 146 | |||||||||||
| 147 | $proxy = $di->g(Service\Audit\ConnectionProxy::class); |
||||||||||
| 148 | return new Service\Audit\QueryLogger($proxy, $options); |
||||||||||
| 149 | }, |
||||||||||
| 150 | ], |
||||||||||
| 151 | 'auto' => [ |
||||||||||
| 152 | // The translator |
||||||||||
| 153 | Lagdo\DbAdmin\Db\Translator::class, |
||||||||||
| 154 | // The string manipulation class |
||||||||||
| 155 | Driver\Utils\Str::class, |
||||||||||
| 156 | // The user input |
||||||||||
| 157 | Driver\Utils\Input::class, |
||||||||||
| 158 | // The utils class |
||||||||||
| 159 | Driver\Utils\Utils::class, |
||||||||||
| 160 | // The db classes |
||||||||||
| 161 | Db\Page\AppPage::class, |
||||||||||
| 162 | // The facade to the database features |
||||||||||
| 163 | Db\Driver\DbFacade::class, |
||||||||||
| 164 | // The Timer service |
||||||||||
| 165 | Service\TimerService::class, |
||||||||||
| 166 | // The UI builders |
||||||||||
| 167 | Ui\UiBuilder::class, |
||||||||||
| 168 | Ui\InputBuilder::class, |
||||||||||
| 169 | Ui\MenuBuilder::class, |
||||||||||
| 170 | Ui\AuditUiBuilder::class, |
||||||||||
| 171 | ], |
||||||||||
| 172 | 'alias' => [ |
||||||||||
| 173 | // The translator |
||||||||||
| 174 | Driver\Utils\TranslatorInterface::class => Db\Translator::class, |
||||||||||
| 175 | ], |
||||||||||
| 176 | ], |
||||||||||
| 177 | 'exceptions' => [ |
||||||||||
| 178 | Exception\DbException::class => function(Exception\DbException $dbException) { |
||||||||||
| 179 | $response = jaxon()->getResponse(); |
||||||||||
| 180 | $response->dialog->warning($dbException->getMessage()); |
||||||||||
|
0 ignored issues
–
show
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...
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...
|
|||||||||||
| 181 | return $response; |
||||||||||
| 182 | }, |
||||||||||
| 183 | ], |
||||||||||
| 184 | ]; |
||||||||||
| 185 |
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: