mirror of
https://github.com/vrana/adminer.git
synced 2025-08-15 19:13:59 +02:00
Plugins: Handle autoloading errors
This commit is contained in:
@@ -170,6 +170,7 @@ function get_nonce() {
|
||||
* @return null
|
||||
*/
|
||||
function page_messages($error) {
|
||||
global $adminer;
|
||||
$uri = preg_replace('~^[^?]*~', '', $_SERVER["REQUEST_URI"]);
|
||||
$messages = $_SESSION["messages"][$uri];
|
||||
if ($messages) {
|
||||
@@ -179,6 +180,9 @@ function page_messages($error) {
|
||||
if ($error) {
|
||||
echo "<div class='error'>$error</div>\n";
|
||||
}
|
||||
if ($adminer->error) { // separate <div>
|
||||
echo "<div class='error'>$adminer->error</div>\n";
|
||||
}
|
||||
}
|
||||
|
||||
/** Print HTML footer
|
||||
|
@@ -3,6 +3,7 @@ namespace Adminer;
|
||||
|
||||
class Plugins extends Adminer {
|
||||
public $plugins; ///< @var protected(set)
|
||||
public $error = ''; ///< @var protected(set)
|
||||
|
||||
/** Register plugins
|
||||
* @param array object instances or null to autoload plugins from adminer-plugins/
|
||||
@@ -18,13 +19,23 @@ class Plugins extends Adminer {
|
||||
}
|
||||
if (file_exists("$basename.php")) {
|
||||
$include = include_once "./$basename.php"; // example: return array(new AdminerLoginOtp($secret))
|
||||
foreach ($include as $plugin) {
|
||||
$plugins[get_class($plugin)] = $plugin;
|
||||
if (is_array($include)) {
|
||||
foreach ($include as $plugin) {
|
||||
$plugins[get_class($plugin)] = $plugin;
|
||||
}
|
||||
} else {
|
||||
$this->error .= lang('<b>%s</b> must return an array.', "$basename.php") . "<br>";
|
||||
}
|
||||
}
|
||||
foreach (get_declared_classes() as $class) {
|
||||
if (!$plugins[$class] && preg_match('~^Adminer\w~i', $class)) {
|
||||
$plugins[$class] = new $class; // if the constructor have some required parameters then PHP triggers an error here
|
||||
$reflection = new \ReflectionClass($class);
|
||||
$constructor = $reflection->getConstructor();
|
||||
if ($constructor && $constructor->getNumberOfRequiredParameters()) {
|
||||
$this->error .= lang('Configure <b>%s</b> in <b>%s</b>.', $class, "$basename.php") . "<br>";
|
||||
} else {
|
||||
$plugins[$class] = new $class;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user