From 7c02cc7dee9d3b0440c4ccabc18762e8b87d1e24 Mon Sep 17 00:00:00 2001 From: Thomas Lange Date: Tue, 16 Jan 2018 17:03:22 +0100 Subject: Use seperate classes for debugging The debug mechanism has been changed. Instead of keeping the debug mechanism hardcoded within the core classes, it's now possible and recommended to use the seperate debugging classes which you can modify like you want. Those classes inherit their associated core classes and can add some debugging stuff. This has the advantage of having a clean core code without any debugging stuff. If the debug classes are not used then they shall not be included and their code will not be initialized. --- include/classes/BigPipe/BigPipe.php | 56 ++----------------------------------- 1 file changed, 3 insertions(+), 53 deletions(-) (limited to 'include/classes') diff --git a/include/classes/BigPipe/BigPipe.php b/include/classes/BigPipe/BigPipe.php index ab8c8f7..c5f33e3 100644 --- a/include/classes/BigPipe/BigPipe.php +++ b/include/classes/BigPipe/BigPipe.php @@ -11,9 +11,8 @@ namespace BigPipe; class BigPipe { - private static $debugging = FALSE; - private static $enabled = TRUE; - private static $pagelets = []; + private static $enabled = TRUE; + private static $pagelets = []; #=============================================================================== # Enable or disable the pipeline mode @@ -26,17 +25,6 @@ class BigPipe { return self::$enabled; } - #=============================================================================== - # Return if debugging is enabled or change - #=============================================================================== - public static function debugging($change = NULL): bool { - if($change !== NULL) { - self::$debugging = (bool) $change; - } - - return self::$debugging; - } - #=============================================================================== # Insert pagelet into queue #=============================================================================== @@ -55,15 +43,6 @@ class BigPipe { # Prints a single pagelet response #=============================================================================== private static function singleResponse(Pagelet $Pagelet, $last = FALSE) { - if(self::debugging()) { - self::addDebugPhaseDoneJS($Pagelet); - - array_map('self::addDebugPhaseDoneJS', $Pagelet->getResources()[Resource::TYPE_STYLESHEET]); - array_map('self::addDebugPhaseDoneJS', $Pagelet->getResources()[Resource::TYPE_JAVASCRIPT]); - - usleep(rand(125, 175) * 2000); - } - $pageletJSON = $Pagelet->getStructure(); if($last) { @@ -73,7 +52,7 @@ class BigPipe { $pageletHTML = removeLineBreaksAndTabs($Pagelet->getHTML()); $pageletHTML = str_replace('--', '--', $pageletHTML); - $pageletJSON = json_encode($pageletJSON, (self::debugging() ? JSON_PRETTY_PRINT : NULL)); + $pageletJSON = json_encode($pageletJSON); echo "\n"; echo "\n\n"; @@ -127,34 +106,5 @@ class BigPipe { } } } - - #=============================================================================== - # Add PhaseDoneJS for debugging Pagelet and Resource - #=============================================================================== - private static function addDebugPhaseDoneJS($Instance) { - $objpath = str_replace('\\', '|', get_class($Instance)); - - if($Instance instanceof Pagelet) { - $message = "console.log(\"%%c[{$objpath}]%%c#(%%c%s%%c): PhaseDoneJS for phase: %s\", \"font-weight:bold\", \"color:#666\", \"color:#008B45\", \"color:#666\")"; - - $Instance->addPhaseDoneJS($Instance::PHASE_INIT, sprintf($message, $Instance->getID(), 'INIT')); - $Instance->addPhaseDoneJS($Instance::PHASE_LOADCSS, sprintf($message, $Instance->getID(), 'LOADCSS')); - $Instance->addPhaseDoneJS($Instance::PHASE_HTML, sprintf($message, $Instance->getID(), 'HTML')); - $Instance->addPhaseDoneJS($Instance::PHASE_LOADJS, sprintf($message, $Instance->getID(), 'LOADJS')); - $Instance->addPhaseDoneJS($Instance::PHASE_DONE, sprintf($message, $Instance->getID(), 'DONE')); - - return $Instance; - } - - if($Instance instanceof Resource) { - $message = "console.log(\"[{$objpath}]%%c#(%%c%s%%c): PhaseDoneJS for phase: %s\", \"color:#666\", \"color:#008B45\", \"color:#666\")"; - - $Instance->addPhaseDoneJS($Instance::PHASE_INIT, sprintf($message, $Instance->getID(), 'INIT')); - $Instance->addPhaseDoneJS($Instance::PHASE_LOAD, sprintf($message, $Instance->getID(), 'LOAD')); - $Instance->addPhaseDoneJS($Instance::PHASE_DONE, sprintf($message, $Instance->getID(), 'DONE')); - - return $Instance; - } - } } ?> \ No newline at end of file -- cgit v1.2.3