aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Lange <code@nerdmind.de>2021-10-24 15:54:43 +0200
committerThomas Lange <code@nerdmind.de>2021-10-24 15:54:43 +0200
commitcbe7e31f68d4ca2bfcd53dffdb130f1f84be3343 (patch)
tree4e285e9a92116c11c2d72245e71af4422b65a961
parent6d69bab4d07cd502d78b565ee9eba3b1e9296931 (diff)
downloadbigpipe-cbe7e31f68d4ca2bfcd53dffdb130f1f84be3343.tar.gz
bigpipe-cbe7e31f68d4ca2bfcd53dffdb130f1f84be3343.tar.xz
bigpipe-cbe7e31f68d4ca2bfcd53dffdb130f1f84be3343.zip
Split up BigPipe "enabled" method into two methods
Split up the "enabled" method of the BigPipe class into two methods, one to check if the pipelining mode is currently enabled ("isEnabled") and another one to enable/disable the pipelining mode ("setEnabled"). This change prevents that a single method has two different jobs, which can be confusing for programmers who didn't wrote the code but only use them. Now there are two clearly named methods for exactly one job.
-rw-r--r--async.php2
-rw-r--r--include/classes/BigPipe/BigPipe.php19
-rw-r--r--include/classes/BigPipe/Pagelet.php4
-rw-r--r--include/pagelets.php2
4 files changed, 15 insertions, 12 deletions
diff --git a/async.php b/async.php
index 3d444c8..a82c91a 100644
--- a/async.php
+++ b/async.php
@@ -29,7 +29,7 @@ require_once 'include/pagelets.php';
<!-- >>> [Additional code for the async function] -->
<script>
var Application = {
- bigPipeEnabled: <?=json_encode(BigPipe\BigPipe::enabled())?>,
+ bigPipeEnabled: <?=json_encode(BigPipe\BigPipe::isEnabled())?>,
placeholderHTML: function(HTML) {
document.getElementById('placeholder_container').innerHTML = HTML;
diff --git a/include/classes/BigPipe/BigPipe.php b/include/classes/BigPipe/BigPipe.php
index 30e3f41..6162388 100644
--- a/include/classes/BigPipe/BigPipe.php
+++ b/include/classes/BigPipe/BigPipe.php
@@ -15,17 +15,20 @@ class BigPipe {
private static $pagelets = [];
#===============================================================================
- # Enable or disable the pipeline mode
+ # Check if pipelining mode is enabled
#===============================================================================
- public static function enabled($change = NULL) {
- if($change !== NULL) {
- self::$enabled = (bool) $change;
- }
-
+ public static function isEnabled(): bool {
return self::$enabled;
}
#===============================================================================
+ # Enable or disable the pipelining mode
+ #===============================================================================
+ public static function setEnabled(bool $enabled): void {
+ self::$enabled = $enabled;
+ }
+
+ #===============================================================================
# Insert pagelet into queue
#===============================================================================
public static function enqueue(Pagelet $Pagelet) {
@@ -63,7 +66,7 @@ class BigPipe {
if(!empty($pagelets_ordered)) {
$pagelets = call_user_func_array('array_merge', $pagelets_ordered);
- if(self::enabled()) {
+ if(self::isEnabled()) {
foreach($pagelets as $Pagelet) {
$Pagelet->flush();
}
@@ -90,7 +93,7 @@ class BigPipe {
}
}
- if(self::enabled()) {
+ if(self::isEnabled()) {
echo "<script>BigPipe.onLastPageletArrived();</script>\n";
}
}
diff --git a/include/classes/BigPipe/Pagelet.php b/include/classes/BigPipe/Pagelet.php
index 0358df6..bd50c4b 100644
--- a/include/classes/BigPipe/Pagelet.php
+++ b/include/classes/BigPipe/Pagelet.php
@@ -150,7 +150,7 @@ class Pagelet extends Item {
# Flush pagelet immediately
#===============================================================================
public function flush() {
- if(BigPipe::enabled()) {
+ if(BigPipe::isEnabled()) {
$pageletHTML = str_replace(["\r", "\n", "\t"], '', $this->getHTML());
$pageletHTML = str_replace('--', '&#45;&#45;', $pageletHTML);
@@ -169,7 +169,7 @@ class Pagelet extends Item {
#===============================================================================
public function __toString() {
$pageletHTML = "<{$this->tagName} id=\"{$this->getID()}\">";
- $pageletHTML .= !BigPipe::enabled() ? $this->getHTML() : $this->tagHTML;
+ $pageletHTML .= !BigPipe::isEnabled() ? $this->getHTML() : $this->tagHTML;
$pageletHTML .= "</{$this->tagName}>";
return $pageletHTML;
diff --git a/include/pagelets.php b/include/pagelets.php
index ed1f8a0..2fc1c9b 100644
--- a/include/pagelets.php
+++ b/include/pagelets.php
@@ -22,7 +22,7 @@ if(isset($_GET['bigpipe']) AND $_GET['bigpipe'] === '0') {
# will be present at the original position within the HTML response (and all
# external stylesheets and javascripts will be displayed as simple <link> or
# <script> elements within the HTML document).
- BigPipe\BigPipe::enabled(FALSE);
+ BigPipe\BigPipe::setEnabled(FALSE);
}
#===============================================================================