Skip to content
Snippets Groups Projects

Issue #3459986 by kalash: fixed the coding standards.

Open kalash jain requested to merge issue/admin_database-3459986:3459986-PHPCS-errors into main
10 files
+ 476
523
Compare changes
  • Side-by-side
  • Inline
Files
10
+ 270
0
<?php
/**
* @file
* Adminer customization allowing usage of plugins.
*/
/**
* Class AdminDatabaseAdminerPlugin.
*
* Adminer plugin to extend functionality.
*/
class AdminDatabaseAdminerPlugin extends Adminer {
/**
* Array of plugin instances or NULL if no plugins are loaded.
*
* @var array|null
*/
public $plugins;
/**
* Find root class for a given class.
*
* @param string $class
* The class name to find the root for.
*
* @return string
* The root class name.
*/
protected function findRootClass($class) {
do {
$return = $class;
} while ($class = get_parent_class($class));
return $return;
}
/**
* Constructor for AdminerPlugin.
*
* @param array|null $plugins
* (optional) Array of plugin instances or NULL to register all
* classes starting by 'Adminer'.
*/
public function __construct($plugins = NULL) {
if ($plugins === NULL) {
$plugins = [];
foreach (get_declared_classes() as $class) {
if (preg_match('~^Adminer.~i', $class) && strcasecmp($this->findRootClass($class), 'Adminer')) {
$plugins[$class] = new $class();
}
}
}
$this->plugins = $plugins;
}
/**
* Call parent method.
*
* @param string $function
* The function name to call.
* @param array $args
* Array of arguments to pass to the function.
*
* @return mixed
* The return value of the parent method call.
*/
protected function callParent($function, $args) {
return call_user_func_array(['parent', $function], $args);
}
/**
* Apply plugin method.
*
* @param string $function
* The function name to call on plugins.
* @param array $args
* Array of arguments to pass to the function.
*
* @return mixed|null
* The return value from the plugin method.
*/
protected function applyPlugin($function, $args) {
foreach ($this->plugins as $plugin) {
if (method_exists($plugin, $function)) {
switch (count($args)) {
case 0:
$return = $plugin->$function();
break;
case 1:
$return = $plugin->$function($args[0]);
break;
case 2:
$return = $plugin->$function($args[0], $args[1]);
break;
case 3:
$return = $plugin->$function($args[0], $args[1], $args[2]);
break;
case 4:
$return = $plugin->$function($args[0], $args[1], $args[2], $args[3]);
break;
case 5:
$return = $plugin->$function($args[0], $args[1], $args[2], $args[3], $args[4]);
break;
case 6:
$return = $plugin->$function($args[0], $args[1], $args[2], $args[3], $args[4], $args[5]);
break;
default:
trigger_error('Too many parameters.', E_USER_WARNING);
break;
}
if ($return !== NULL) {
return $return;
}
}
}
return $this->callParent($function, $args);
}
/**
* Append plugin method.
*
* @param string $function
* The function name to call on plugins.
* @param array $args
* Array of arguments to pass to the function.
*
* @return mixed
* The combined return value from all plugins.
*/
protected function appendPlugin($function, $args) {
$return = $this->callParent($function, $args);
foreach ($this->plugins as $plugin) {
if (method_exists($plugin, $function)) {
$value = call_user_func_array([$plugin, $function], $args);
if ($value) {
$return += $value;
}
}
}
return $return;
}
/**
* {@inheritdoc}
*/
public function dumpFormat() {
return $this->appendPlugin(__FUNCTION__, func_get_args());
}
/**
* {@inheritdoc}
*/
public function dumpOutput() {
return $this->appendPlugin(__FUNCTION__, func_get_args());
}
/**
* {@inheritdoc}
*/
public function editRowPrint($table, $fields, $row, $update) {
return $this->appendPlugin(__FUNCTION__, func_get_args());
}
/**
* {@inheritdoc}
*/
public function editFunctions($field) {
return $this->appendPlugin(__FUNCTION__, func_get_args());
}
/**
* {@inheritdoc}
*/
public function tableName($tableStatus) {
return $this->applyPlugin(__FUNCTION__, func_get_args());
}
/**
* {@inheritdoc}
*/
public function fieldName($field, $order = 0) {
return $this->applyPlugin(__FUNCTION__, func_get_args());
}
/**
* {@inheritdoc}
*/
public function selectLinks($tableStatus, $set = "") {
return $this->applyPlugin(__FUNCTION__, func_get_args());
}
/**
* {@inheritdoc}
*/
public function dumpDatabase($db) {
return $this->applyPlugin(__FUNCTION__, func_get_args());
}
/**
* {@inheritdoc}
*/
public function dumpTable($table, $style, $is_view = 0) {
return $this->applyPlugin(__FUNCTION__, func_get_args());
}
/**
* {@inheritdoc}
*/
public function dumpData($table, $style, $query) {
return $this->applyPlugin(__FUNCTION__, func_get_args());
}
/**
* {@inheritdoc}
*/
public function dumpFilename($identifier) {
return $this->applyPlugin(__FUNCTION__, func_get_args());
}
/**
* {@inheritdoc}
*/
public function dumpHeaders($identifier, $multi_table = FALSE) {
return $this->applyPlugin(__FUNCTION__, func_get_args());
}
/**
* {@inheritdoc}
*/
public function importServerPath() {
return $this->applyPlugin(__FUNCTION__, func_get_args());
}
/**
* {@inheritdoc}
*/
public function homepage() {
return $this->applyPlugin(__FUNCTION__, func_get_args());
}
/**
* {@inheritdoc}
*/
public function navigation($missing) {
return $this->applyPlugin(__FUNCTION__, func_get_args());
}
/**
* {@inheritdoc}
*/
public function databasesPrint($missing) {
return $this->applyPlugin(__FUNCTION__, func_get_args());
}
/**
* {@inheritdoc}
*/
public function tablesPrint($tables) {
return $this->applyPlugin(__FUNCTION__, func_get_args());
}
}
Loading