1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-07 07:06:45 +02:00

Plugins: Allow providing description

This commit is contained in:
Jakub Vrana
2025-04-07 15:54:31 +02:00
parent 121b77e866
commit 95f14bca56
2 changed files with 17 additions and 3 deletions

View File

@@ -93,8 +93,14 @@ if (
echo "<div class='plugins'>\n"; echo "<div class='plugins'>\n";
echo "<h3>" . lang('Loaded plugins') . "</h3>\n<ul>\n"; echo "<h3>" . lang('Loaded plugins') . "</h3>\n<ul>\n";
foreach (adminer()->plugins as $plugin) { foreach (adminer()->plugins as $plugin) {
$reflection = new \ReflectionObject($plugin); $description = (method_exists($plugin, 'description') ? $plugin->description() : "");
echo "<li><b>" . get_class($plugin) . "</b>" . h(preg_match('~^/[\s*]+(.+)~', $reflection->getDocComment(), $match) ? ": $match[1]" : "") . "\n"; if (!$description) {
$reflection = new \ReflectionObject($plugin);
if (preg_match('~^/[\s*]+(.+)~', $reflection->getDocComment(), $match)) {
$description = $match[1];
}
}
echo "<li><b>" . get_class($plugin) . "</b>" . h($description ? ": $description" : "") . "\n";
} }
echo "</ul>\n"; echo "</ul>\n";
echo "</div>\n"; echo "</div>\n";

View File

@@ -1,14 +1,22 @@
<?php <?php
namespace Adminer; namespace Adminer;
// the overridable methods don't use return type declarations so that plugins can be compatible with PHP 5
abstract class Plugin { abstract class Plugin {
/** @var array<literal-string, string|list<string>>[] */ protected static $translations = array(); // key is language code /** @var array<literal-string, string|list<string>>[] */ protected static $translations = array(); // key is language code
/** Get plain text plugin description; empty string means to use the first line of class doc-comment
* @return string
*/
function description() {
return '';
}
/** Translate a string from static::$translations; use Adminer\lang() for strings used by Adminer /** Translate a string from static::$translations; use Adminer\lang() for strings used by Adminer
* @param literal-string $idf * @param literal-string $idf
* @param float|string $number * @param float|string $number
*/ */
protected function lang(string $idf, $number = null) { protected function lang(string $idf, $number = null): string {
$args = func_get_args(); $args = func_get_args();
$args[0] = idx(static::$translations[LANG], $idf) ?: $idf; $args[0] = idx(static::$translations[LANG], $idf) ?: $idf;
return call_user_func_array('Adminer\lang_format', $args); return call_user_func_array('Adminer\lang_format', $args);