|
1 | 1 | <?php |
2 | 2 | namespace docker { |
3 | | - final class DefaultServerPlugin { |
4 | | - public function __construct( |
5 | | - private \AdminerPlugin $adminer |
6 | | - ) { } |
7 | | - |
8 | | - public function loginFormField(...$args) { |
9 | | - return (function (...$args) { |
10 | | - $field = \Adminer\Adminer::loginFormField(...$args); |
11 | | - |
12 | | - return \str_replace( |
13 | | - 'name="auth[server]" value="" title="hostname[:port]"', |
14 | | - \sprintf('name="auth[server]" value="%s" title="hostname[:port]"', ($_ENV['ADMINER_DEFAULT_SERVER'] ?: 'db')), |
15 | | - $field, |
16 | | - ); |
17 | | - })->call($this->adminer, ...$args); |
18 | | - } |
19 | | - } |
20 | | - |
21 | 3 | function adminer_object() { |
22 | | - require_once('plugins/plugin.php'); |
| 4 | + /** |
| 5 | + * Prefills the “Server” field with the ADMINER_DEFAULT_SERVER environment variable. |
| 6 | + */ |
| 7 | + final class DefaultServerPlugin extends \Adminer\Plugin { |
| 8 | + public function __construct( |
| 9 | + private \Adminer\Adminer $adminer |
| 10 | + ) { } |
| 11 | + |
| 12 | + public function loginFormField(...$args) { |
| 13 | + return (function (...$args) { |
| 14 | + $field = $this->loginFormField(...$args); |
| 15 | + |
| 16 | + return \str_replace( |
| 17 | + 'name="auth[server]" value="" title="hostname[:port]"', |
| 18 | + \sprintf('name="auth[server]" value="%s" title="hostname[:port]"', ($_ENV['ADMINER_DEFAULT_SERVER'] ?: 'db')), |
| 19 | + $field, |
| 20 | + ); |
| 21 | + })->call($this->adminer, ...$args); |
| 22 | + } |
| 23 | + } |
23 | 24 |
|
24 | 25 | $plugins = []; |
25 | 26 | foreach (glob('plugins-enabled/*.php') as $plugin) { |
26 | 27 | $plugins[] = require($plugin); |
27 | 28 | } |
28 | 29 |
|
29 | | - // Load the DefaultServerPlugin last to give other plugins a chance to |
30 | | - // override loginFormField() if they wish to. |
31 | | - $plugins[] = &$loginFormPlugin; |
32 | | - |
33 | | - $adminer = new \AdminerPlugin($plugins); |
| 30 | + $adminer = new \Adminer\Plugins($plugins); |
34 | 31 |
|
35 | | - $loginFormPlugin = new DefaultServerPlugin($adminer); |
| 32 | + (function () { |
| 33 | + $last = &$this->hooks['loginFormField'][\array_key_last($this->hooks['loginFormField'])]; |
| 34 | + if ($last instanceof \Adminer\Adminer) { |
| 35 | + $defaultServerPlugin = new DefaultServerPlugin($last); |
| 36 | + $this->plugins[] = $defaultServerPlugin; |
| 37 | + $last = $defaultServerPlugin; |
| 38 | + } |
| 39 | + })->call($adminer); |
36 | 40 |
|
37 | 41 | return $adminer; |
38 | 42 | } |
|
0 commit comments