aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorThomas Lange <code@nerdmind.de>2016-04-22 21:17:53 +0200
committerThomas Lange <code@nerdmind.de>2016-04-22 21:17:53 +0200
commit7a49346f8069d814c51af2e0cefcc6e66fe9826e (patch)
tree1de48b8be3e12ec4ea8d6695f99217d39de26ebf /include
parent74d01962a6f77eb2b8138864f18ed53eb136c432 (diff)
downloadbigpipe-7a49346f8069d814c51af2e0cefcc6e66fe9826e.tar.gz
bigpipe-7a49346f8069d814c51af2e0cefcc6e66fe9826e.tar.xz
bigpipe-7a49346f8069d814c51af2e0cefcc6e66fe9826e.zip
Multiple updates with async demo.
Diffstat (limited to 'include')
-rwxr-xr-xinclude/classes/BigPipe/BigPipe.php26
-rwxr-xr-xinclude/classes/BigPipe/Pagelet.php56
-rwxr-xr-xinclude/functions.php22
3 files changed, 52 insertions, 52 deletions
diff --git a/include/classes/BigPipe/BigPipe.php b/include/classes/BigPipe/BigPipe.php
index 740d047..63cb711 100755
--- a/include/classes/BigPipe/BigPipe.php
+++ b/include/classes/BigPipe/BigPipe.php
@@ -7,31 +7,31 @@ class BigPipe {
private static $pagelets = [];
private static $count = 0;
- #====================================================================================================
+ #===============================================================================
# Return TRUE if the pipeline is enabled
- #====================================================================================================
+ #===============================================================================
public static function isEnabled() {
return self::$enabled;
}
- #====================================================================================================
+ #===============================================================================
# Enable or disable the pipeline mode
- #====================================================================================================
+ #===============================================================================
public static function enablePipeline($enabled = TRUE) {
return self::$enabled = (bool) $enabled;
}
- #====================================================================================================
+ #===============================================================================
# Add a new pagelet to pipeline
- #====================================================================================================
+ #===============================================================================
public static function addPagelet(Pagelet $Pagelet, $priority) {
self::$pagelets[$priority][] = $Pagelet;
return ++self::$count;
}
- #====================================================================================================
+ #===============================================================================
# Prints a single pagelet response
- #====================================================================================================
+ #===============================================================================
private static function singleResponse(Pagelet $Pagelet, $last = FALSE) {
$data = [
'ID' => $Pagelet->getID(),
@@ -47,19 +47,19 @@ class BigPipe {
$pageletJSON = json_encode($data, (self::$debug ? JSON_PRETTY_PRINT : FALSE));
echo "<code class=\"hidden\" id=\"_{$Pagelet->getID()}\"><!-- {$pageletHTML} --></code>\n";
- echo "<script>BigPipe.onPageletArrive({$pageletJSON});</script>\n\n";
+ echo "<script>BigPipe.onPageletArrive({$pageletJSON}, (document.getElementById(\"_{$Pagelet->getID()}\")));</script>\n\n";
}
- #====================================================================================================
+ #===============================================================================
# Sends output buffer so far as possible towards user
- #====================================================================================================
+ #===============================================================================
public static function flushOutputBuffer() {
ob_flush(); flush();
}
- #====================================================================================================
+ #===============================================================================
# Render the pagelets
- #====================================================================================================
+ #===============================================================================
public static function render() {
self::flushOutputBuffer();
diff --git a/include/classes/BigPipe/Pagelet.php b/include/classes/BigPipe/Pagelet.php
index 3b5530c..3a6c64e 100755
--- a/include/classes/BigPipe/Pagelet.php
+++ b/include/classes/BigPipe/Pagelet.php
@@ -10,18 +10,18 @@ class Pagelet {
private $phaseDoneJS = [];
private static $count = 0;
- #====================================================================================================
+ #===============================================================================
# Priorities for sorting the pagelets
- #====================================================================================================
+ #===============================================================================
const PRIORITY_HIGHEST = 100;
const PRIORITY_HIGH = 75;
const PRIORITY_NORMAL = 50;
const PRIORITY_LOW = 25;
const PRIORITY_LOWEST = 0;
- #====================================================================================================
+ #===============================================================================
# Callback phase numbers for PhaseDoneJS
- #====================================================================================================
+ #===============================================================================
const PHASE_ARRIVE = 0; # After the pagelet reached BigPipe
const PHASE_LOADCSS = 1; # After all the CSS resources have been loaded
const PHASE_PUTHTML = 2; # After the HTML content has been injected into the placeholders
@@ -35,86 +35,86 @@ class Pagelet {
BigPipe::addPagelet($this, $priority);
}
- #====================================================================================================
+ #===============================================================================
# Return the unique ID
- #====================================================================================================
+ #===============================================================================
public function getID() {
return $this->ID;
}
- #====================================================================================================
+ #===============================================================================
# Return the HTML content
- #====================================================================================================
+ #===============================================================================
public function getHTML() {
return $this->HTML;
}
- #====================================================================================================
+ #===============================================================================
# Return the CSS resources
- #====================================================================================================
+ #===============================================================================
public function getCSSFiles() {
return $this->CSSFiles;
}
- #====================================================================================================
+ #===============================================================================
# Return the JS resources
- #====================================================================================================
+ #===============================================================================
public function getJSFiles() {
return $this->JSFiles;
}
- #====================================================================================================
+ #===============================================================================
# Return the main JS code
- #====================================================================================================
+ #===============================================================================
public function getJSCode() {
return $this->JSCode;
}
- #====================================================================================================
+ #===============================================================================
# Add HTML or attach more
- #====================================================================================================
+ #===============================================================================
public function addHTML($HTML) {
return $this->HTML .= $HTML;
}
- #====================================================================================================
+ #===============================================================================
# Attach a CSS resource
- #====================================================================================================
+ #===============================================================================
public function addCSS($file) {
return $this->CSSFiles[] = $file;
}
- #====================================================================================================
+ #===============================================================================
# Attach a JS resource
- #====================================================================================================
+ #===============================================================================
public function addJS($file) {
return $this->JSFiles[] = $file;
}
- #====================================================================================================
+ #===============================================================================
# Add JS code or attach more
- #====================================================================================================
+ #===============================================================================
public function addJSCode($code) {
return $this->JSCode .= $code;
}
- #====================================================================================================
+ #===============================================================================
# Attach a PhaseDoneJS callback
- #====================================================================================================
+ #===============================================================================
public function addPhaseDoneJS($phase, $callback) {
return $this->phaseDoneJS[$phase][] = removeLineBreaksAndTabs($callback);
}
- #====================================================================================================
+ #===============================================================================
# Return all registered PhaseDoneJS callbacks
- #====================================================================================================
+ #===============================================================================
public function getPhaseDoneJS() {
return $this->phaseDoneJS;
}
- #====================================================================================================
+ #===============================================================================
# Magic method: __toString()
- #====================================================================================================
+ #===============================================================================
public function __toString() {
return '<div id="'.$this->getID().'">'.((!BigPipe::isEnabled()) ? $this->getHTML() : NULL).'</div>';
}
diff --git a/include/functions.php b/include/functions.php
index 21eb3f0..d06823d 100755
--- a/include/functions.php
+++ b/include/functions.php
@@ -1,12 +1,12 @@
-<?php
-#====================================================================================================
-# FUNCTION: Removes all line breaks and tabs from a string or an array with strings
-#====================================================================================================
-function removeLineBreaksAndTabs($mixed, $replace = NULL) {
- if(is_array($mixed)) {
- return array_map(__FUNCTION__, $mixed);
- }
-
- return is_string($mixed) ? str_replace(["\r\n", "\r", "\n", "\t"], $replace, $mixed) : $mixed;
-}
+<?php
+#===============================================================================
+# FUNCTION: Removes all line breaks and tabs from a string or an array with strings
+#===============================================================================
+function removeLineBreaksAndTabs($mixed, $replace = NULL) {
+ if(is_array($mixed)) {
+ return array_map(__FUNCTION__, $mixed);
+ }
+
+ return is_string($mixed) ? str_replace(["\r\n", "\r", "\n", "\t"], $replace, $mixed) : $mixed;
+}
?> \ No newline at end of file