-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathindex.php
More file actions
75 lines (63 loc) · 2.64 KB
/
index.php
File metadata and controls
75 lines (63 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
namespace docker {
function adminer_object() {
/**
* Prefills the “Server” field with the ADMINER_DEFAULT_SERVER environment variable.
*/
final class DefaultServerPlugin extends \Adminer\Plugin {
public function __construct(
private \Adminer\Adminer $adminer
) { }
public function loginFormField(...$args) {
return (function (...$args) {
$field = $this->loginFormField(...$args);
// Set default values via env vars.
$defaultDbDriver = getenv('ADMINER_DEFAULT_DB_DRIVER') ?: 'server';
$defaultDbHost = getenv('ADMINER_DEFAULT_DB_HOST') ?: '';
$defaultDb = getenv('ADMINER_DEFAULT_DB_NAME') ?: '';
$defaultDbDriver = $defaultDbDriver == 'mysql' ? 'server' : $defaultDbDriver;
echo str_replace(
[
'name="auth[server]" value="" title="hostname[:port]"',
'value="' . $defaultDbDriver . '"',
'selected="">MySQL',
'name="auth[db]" value=""'
],
[
'name="auth[server]" value="' . $defaultDbHost . '" title="hostname[:port]"',
'value="' . $defaultDbDriver . '" selected="selected"',
'>MySQL',
'name="auth[db]" value="' . $defaultDb . '"'
],
$field,
);
})->call($this->adminer, ...$args);
}
}
$plugins = [];
foreach (glob('plugins-enabled/*.php') as $plugin) {
$plugins[] = require($plugin);
}
$adminer = new \Adminer\Plugins($plugins);
(function () {
$last = &$this->hooks['loginFormField'][\array_key_last($this->hooks['loginFormField'])];
if ($last instanceof \Adminer\Adminer) {
$defaultServerPlugin = new DefaultServerPlugin($last);
$this->plugins[] = $defaultServerPlugin;
$last = $defaultServerPlugin;
}
})->call($adminer);
return $adminer;
}
}
namespace {
if (basename($_SERVER['DOCUMENT_URI'] ?? $_SERVER['REQUEST_URI']) === 'adminer.css' && is_readable('adminer.css')) {
header('Content-Type: text/css');
readfile('adminer.css');
exit;
}
function adminer_object() {
return \docker\adminer_object();
}
require('adminer.php');
}