From: Roland Haeder Date: Fri, 21 Feb 2014 20:23:59 +0000 (+0100) Subject: Tried to make debugger instance more singleton. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=564914ca84745209c1628027e923666dac9c8b2d;p=core.git Tried to make debugger instance more singleton. Signed-off-by: Roland Häder --- diff --git a/inc/classes/main/class_BaseFrameworkSystem.php b/inc/classes/main/class_BaseFrameworkSystem.php index 78ee47fd..abb48a93 100644 --- a/inc/classes/main/class_BaseFrameworkSystem.php +++ b/inc/classes/main/class_BaseFrameworkSystem.php @@ -1446,20 +1446,29 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { * @return $debugInstance An instance of a debugger class */ public final static function createDebugInstance ($className) { - // Init debug instance - $debugInstance = NULL; + // Is the instance set? + if (!Registry::getRegistry()->instanceExists('debug')) { + // Init debug instance + $debugInstance = NULL; + + // Try it + try { + // Get a debugger instance + $debugInstance = DebugMiddleware::createDebugMiddleware(FrameworkConfiguration::getSelfInstance()->getConfigEntry('debug_class')); + } catch (NullPointerException $e) { + // Didn't work, no instance there + exit('Cannot create debugInstance! Exception=' . $e->__toString() . ', message=' . $e->getMessage()); + } - // Try it - try { - // Get a debugger instance - $debugInstance = DebugMiddleware::createDebugMiddleware(FrameworkConfiguration::getSelfInstance()->getConfigEntry('debug_class')); - } catch (NullPointerException $e) { - // Didn't work, no instance there - exit('Cannot create debugInstance! Exception=' . $e->__toString() . ', message=' . $e->getMessage()); - } + // Empty string should be ignored and used for testing the middleware + DebugMiddleware::getSelfInstance()->output(''); - // Empty string should be ignored and used for testing the middleware - DebugMiddleware::getSelfInstance()->output(''); + // Set it in its own class. This will set it in the registry + $debugInstance->setDebugInstance($debugInstance); + } else { + // Get instance from registry + $debugInstance = Registry::getRegistry()->getDebugInstance(); + } // Return it return $debugInstance;