aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/classes/BigPipe/BigPipe.php56
-rw-r--r--include/pagelets.php29
2 files changed, 21 insertions, 64 deletions
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
@@ -27,17 +26,6 @@ class BigPipe {
}
#===============================================================================
- # 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
#===============================================================================
public static function enqueue(Pagelet $Pagelet) {
@@ -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 "<code hidden id=\"_{$Pagelet->getID()}\"><!-- {$pageletHTML} --></code>\n";
echo "<script>BigPipe.onPageletArrive({$pageletJSON}, document.getElementById(\"_{$Pagelet->getID()}\"));</script>\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
diff --git a/include/pagelets.php b/include/pagelets.php
index cdb1a14..43d1992 100644
--- a/include/pagelets.php
+++ b/include/pagelets.php
@@ -2,30 +2,37 @@
#===============================================================================
# Enable debugging mode
#===============================================================================
-BigPipe\BigPipe::debugging(TRUE);
+$DEBUGGING = TRUE;
+
+#===============================================================================
+# Namespace paths based on whether the debugging mode is enabled
+#===============================================================================
+$pagelet = ($DEBUGGING ? 'Debugging' : 'BigPipe').'\Pagelet';
+$stylesheet = ($DEBUGGING ? 'Debugging' : 'BigPipe').'\Resource\Stylesheet';
+$javascript = ($DEBUGGING ? 'Debugging' : 'BigPipe').'\Resource\Javascript';
#===============================================================================
# Pagelet with red background color
#===============================================================================
-$PageletRed = new BigPipe\Pagelet('redPL');
+$PageletRed = new $pagelet('redPL');
$PageletRed->addHTML('<section id="red" class="text">I AM A PAGELET WITH RED BACKGROUND</section>');
-$PageletRed->addResource(new BigPipe\Resource\Stylesheet(NULL, 'static/red.php'));
-$PageletRed->addResource(new BigPipe\Resource\Javascript(NULL, 'static/delayJS.php'));
+$PageletRed->addResource(new $stylesheet(NULL, 'static/red.php'));
+$PageletRed->addResource(new $javascript(NULL, 'static/delayJS.php'));
$PageletRed->addJSCode("document.getElementById('red').innerHTML += ' [JS executed]';document.getElementById('red').style.borderRadius = '30px';");
#===============================================================================
# Pagelet with blue background color
#===============================================================================
-$PageletBlue = new BigPipe\Pagelet('bluePL', BigPipe\Pagelet::PRIORITY_HIGH);
+$PageletBlue = new $pagelet('bluePL', BigPipe\Pagelet::PRIORITY_HIGH);
$PageletBlue->addHTML('<section id="blue" class="text">I AM A PAGELET WITH BLUE BACKGROUND</section>');
-$PageletBlue->addResource(new BigPipe\Resource\Stylesheet(NULL, 'static/blue.php'));
-$PageletBlue->addResource(new BigPipe\Resource\Javascript(NULL, 'static/delayJS.php'));
+$PageletBlue->addResource(new $stylesheet(NULL, 'static/blue.php'));
+$PageletBlue->addResource(new $javascript(NULL, 'static/delayJS.php'));
$PageletBlue->addJSCode("document.getElementById('blue').innerHTML += ' [JS executed]';document.getElementById('blue').style.borderRadius = '30px';");
#===============================================================================
# Pagelet with green background color
#===============================================================================
-$PageletGreen = new BigPipe\Pagelet('greenPL');
+$PageletGreen = new $pagelet('greenPL');
{
#===============================================================================
@@ -42,7 +49,7 @@ $PageletGreen = new BigPipe\Pagelet('greenPL');
// the first which arrives, but it will first be displayed if his dependency
// pagelets are already displayed.
- $InnerPagelet = new BigPipe\Pagelet('innerPL', BigPipe\Pagelet::PRIORITY_HIGHEST);
+ $InnerPagelet = new $pagelet('innerPL', BigPipe\Pagelet::PRIORITY_HIGHEST);
// NOTICE: You can also use the Pagelet ID (as string) as argument. May be helpful
// if a dependency Pagelet object is not accessible within the current scope.
@@ -52,7 +59,7 @@ $PageletGreen = new BigPipe\Pagelet('greenPL');
}
$PageletGreen->addHTML('<section id="green" class="text">I AM A PAGELET WITH GREEN BACKGROUND'.$InnerPagelet.'</section>');
-$PageletGreen->addResource(new BigPipe\Resource\Stylesheet(NULL, 'static/green.php'));
-$PageletGreen->addResource(new BigPipe\Resource\Javascript(NULL, 'static/delayJS.php'));
+$PageletGreen->addResource(new $stylesheet(NULL, 'static/green.php'));
+$PageletGreen->addResource(new $javascript(NULL, 'static/delayJS.php'));
$PageletGreen->addJSCode("document.getElementById('green').innerHTML += ' [JS executed]';document.getElementById('green').style.borderRadius = '30px';");
?> \ No newline at end of file