diff --git a/plugins/system/debug/debug.php b/plugins/system/debug/debug.php index 48f90565b1d25..89fd0bdada28f 100644 --- a/plugins/system/debug/debug.php +++ b/plugins/system/debug/debug.php @@ -82,6 +82,14 @@ class PlgSystemDebug extends JPlugin */ protected $app; + /** + * Container for callback functions to be triggered when rendering the console. + * + * @var callable[] + * @since __DEPLOY_VERSION__ + */ + private static $displayCallbacks = array(); + /** * Constructor. * @@ -306,11 +314,56 @@ public function onAfterRespond() } } + foreach (self::$displayCallbacks as $name => $callable) + { + $html[] = $this->displayCallback($name, $callable); + } + $html[] = ''; echo str_replace('', implode('', $html) . '', $contents); } + /** + * Add a display callback to be rendered with the debug console. + * + * @param string $name The name of the callable, this is used to generate the section title. + * @param callable $callable The callback function to be added. + * + * @return boolean + * + * @since __DEPLOY_VERSION__ + * @throws InvalidArgumentException + */ + public static function addDisplayCallback($name, $callable) + { + // TODO - When PHP 5.4 is the minimum the parameter should be typehinted "callable" and this check removed + if (!is_callable($callable)) + { + throw new InvalidArgumentException('A valid callback function must be given.'); + } + + self::$displayCallbacks[$name] = $callable; + + return true; + } + + /** + * Remove a registered display callback + * + * @param string $name The name of the callable. + * + * @return boolean + * + * @since __DEPLOY_VERSION__ + */ + public static function removeDisplayCallback($name) + { + unset(self::$displayCallbacks[$name]); + + return true; + } + /** * Method to check if the current user is allowed to see the debug information or not. * @@ -393,6 +446,38 @@ protected function display($item, array $errors = array()) return implode('', $html); } + /** + * Display method for callback functions. + * + * @param string $name The name of the callable. + * @param callable $callable The callable function. + * + * @return string + * + * @since __DEPLOY_VERSION__ + */ + protected function displayCallback($name, $callable) + { + $title = JText::_('PLG_DEBUG_' . strtoupper($name)); + + $html = array(); + + $js = "toggleContainer('dbg_container_" . $name . "');"; + + $class = 'dbg-header'; + + $html[] = '

' . $title . '

'; + + // @todo set with js.. ? + $style = ' style="display: none;"'; + + $html[] = '
'; + $html[] = call_user_func($callable); + $html[] = '
'; + + return implode('', $html); + } + /** * Display session information. *