]> git.joonet.de Git - adminer.git/commitdiff
Fix plugin extending
authorJakub Vrana <jakub@vrana.cz>
Thu, 24 Mar 2011 15:23:26 +0000 (16:23 +0100)
committerJakub Vrana <jakub@vrana.cz>
Thu, 24 Mar 2011 15:23:26 +0000 (16:23 +0100)
http://forum.zdrojak.root.cz/index.php?topic=366.0

adminer/plugin.php
plugins/plugin.php

index 3afcf12fd9488a08095a2455768c8d3772ddd70d..0ac2093fb4992dd825804232465bfaabc79d99cd 100644 (file)
@@ -8,13 +8,7 @@ function adminer_object() {
                include_once $filename;
        }
        
-       /* It is possible to combine customization and plugins:
-       class AdminerCustomization extends AdminerPlugin {
-       }
-       return new AdminerCustomization($plugins);
-       */
-       
-       return new AdminerPlugin(array(
+       $plugins = array(
                // specify enabled plugins here
                new AdminerDumpZip,
                new AdminerDumpXml,
@@ -25,7 +19,15 @@ function adminer_object() {
                new AdminerTranslation,
                new AdminerForeignSystem,
                new AdminerEnumOption,
-       ));
+       );
+       
+       /* It is possible to combine customization and plugins:
+       class AdminerCustomization extends AdminerPlugin {
+       }
+       return new AdminerCustomization($plugins);
+       */
+       
+       return new AdminerPlugin($plugins);
 }
 
 // include original Adminer or Adminer Editor (usually named adminer.php)
index 3d365d55e4552ec5e2af0d20875ea59f95604100..35d9c93116657ccbd79715fce33eb991471ecba8 100644 (file)
@@ -16,6 +16,17 @@ class AdminerPlugin extends Adminer {
                // it is possible to use ReflectionObject in PHP 5 to find out which plugins defines which methods at once
        }
        
+       function _callParent($function, $args) {
+               switch (count($args)) { // call_user_func_array(array('parent', $function), $args) works since PHP 5
+                       case 0: return parent::$function();
+                       case 1: return parent::$function($args[0]);
+                       case 2: return parent::$function($args[0], $args[1]);
+                       case 3: return parent::$function($args[0], $args[1], $args[2]);
+                       case 4: return parent::$function($args[0], $args[1], $args[2], $args[3]);
+                       default: trigger_error('Too many parameters.', E_USER_WARNING);
+               }
+       }
+       
        function _applyPlugin($function, $args) {
                foreach ($this->plugins as $plugin) {
                        if (method_exists($plugin, $function)) {
@@ -32,11 +43,11 @@ class AdminerPlugin extends Adminer {
                                }
                        }
                }
-               return call_user_func_array(array($this, "parent::$function"), $args);
+               return $this->_callParent($function, $args);
        }
        
        function _appendPlugin($function, $args) {
-               $return = call_user_func_array(array($this, "parent::$function"), $args);
+               $return = $this->_callParent($function, $args);
                foreach ($this->plugins as $plugin) {
                        if (method_exists($plugin, $function)) {
                                $return += call_user_func_array(array($plugin, $function), $args);