From abee7825186ebbd37e7d7267e0255a3d0233b321 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Mon, 19 Jan 2009 15:23:43 +0000 Subject: This may be an interesting approach for internal functionality and trying to be consistent git-svn-id: file:///svn/phpbb/trunk@9278 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/plugins/bootstrap.php | 80 +++++++++++++++++++++++++++++++-------------- 1 file changed, 55 insertions(+), 25 deletions(-) (limited to 'phpBB/plugins/bootstrap.php') diff --git a/phpBB/plugins/bootstrap.php b/phpBB/plugins/bootstrap.php index dd10d420ca..443624bbf9 100644 --- a/phpBB/plugins/bootstrap.php +++ b/phpBB/plugins/bootstrap.php @@ -132,6 +132,16 @@ class phpbb_plugins */ private $current_plugin = false; + /** + * Plugins/Functions already set up + */ + private $already_parsed_plugins = array(); + + /** + * @var array Collection of assigned functions and their params (merged from plugins and custom additions) + */ + private $functions = array(); + /** * Init plugins * @@ -159,6 +169,8 @@ class phpbb_plugins } closedir($dh); } + + $this->already_parsed_plugins = array('plugin' => array(), 'hook' => array()); } /** @@ -196,13 +208,13 @@ class phpbb_plugins */ public function setup() { - if (empty($this->plugins)) - { - return false; - } - foreach ($this->plugins as $name => $plugin) { + if (isset($this->already_parsed_plugins['plugin'][$name])) + { + continue; + } + // Add includes foreach ($plugin->includes as $file) { @@ -244,29 +256,45 @@ class phpbb_plugins // Setup/Register plugin... $object->setup_plugin($instance); } + } - // Now setup hooks... this is a special case... - foreach ($plugin->functions as $params) + // Now setup hooks... this is a special case... + foreach ($this->functions as $key => $params) + { + if (isset($this->already_parsed_plugins['hook'][$key])) { - $function = array_shift($params); - $hook = array_shift($params); - $mode = (!empty($params)) ? array_shift($params) : phpbb::FUNCTION_INJECT; - $action = (!empty($params)) ? array_shift($params) : 'default'; + continue; + } - // Check if the function is already overridden. - if ($mode == phpbb::FUNCTION_OVERRIDE && isset($this->hooks[$function][$mode])) - { - trigger_error('Function ' . $function . ' is already overridden by ' . $this->hooks[$function][$mode] . '.', E_USER_ERROR); - } + $function = array_shift($params); + $hook = array_shift($params); + $mode = (!empty($params)) ? array_shift($params) : phpbb::FUNCTION_INJECT; + $action = (!empty($params)) ? array_shift($params) : 'default'; - if ($mode == phpbb::FUNCTION_OVERRIDE) - { - $this->hooks[$function][$mode] = $hook; - } - else - { - $this->hooks[$function][$mode][$action][] = $hook; - } + // Check if the function is already overridden. + if ($mode == phpbb::FUNCTION_OVERRIDE && isset($this->hooks[$function][$mode])) + { + trigger_error('Function ' . $function . ' is already overridden by ' . $this->hooks[$function][$mode] . '.', E_USER_ERROR); + } + + if ($mode == phpbb::FUNCTION_OVERRIDE) + { + $this->hooks[$function][$mode] = $hook; + } + else + { + $this->hooks[$function][$mode][$action][] = $hook; + } + + $this->already_parsed_plugins['hook'][$key] = true; + } + + // Init method call and setting as finished + foreach ($this->plugins as $name => $plugin) + { + if (isset($this->already_parsed_plugins['plugin'][$name])) + { + continue; } // Call plugins init method? @@ -274,6 +302,8 @@ class phpbb_plugins { $plugin->setup->init(); } + + $this->already_parsed_plugins['plugin'][$name] = true; } } @@ -332,7 +362,7 @@ class phpbb_plugins public function register_function() { $arguments = func_get_args(); - $this->current_plugin->functions[] = $arguments; + $this->current_plugin->functions[] = $this->functions[] = $arguments; } /** -- cgit v1.2.1