aboutsummaryrefslogtreecommitdiffstats
path: root/include/classes
diff options
context:
space:
mode:
authorThomas Lange <code@nerdmind.de>2017-10-04 18:00:12 +0200
committerThomas Lange <code@nerdmind.de>2017-10-04 18:00:12 +0200
commit58dbefb69068e074586be4ade67871a81c853233 (patch)
treeff87134d6900c79f8daea3f0c34c228bec5292c0 /include/classes
parent2a1d85fdd1a0fb256e46013bb4c64470ab0ec2fd (diff)
downloadbigpipe-58dbefb69068e074586be4ade67871a81c853233.tar.gz
bigpipe-58dbefb69068e074586be4ade67871a81c853233.tar.xz
bigpipe-58dbefb69068e074586be4ade67871a81c853233.zip
The method "addPagelet" from the BigPipe main class was replaced by the new implemented methods "enqueue" and "dequeue" for the new queueing mechanism. The "dequeue" method is currently unused but will be used in the future. The changes in this commit are partially preparations for further commits.
Diffstat (limited to 'include/classes')
-rwxr-xr-xinclude/classes/BigPipe/BigPipe.php35
-rwxr-xr-xinclude/classes/BigPipe/Pagelet.php2
2 files changed, 25 insertions, 12 deletions
diff --git a/include/classes/BigPipe/BigPipe.php b/include/classes/BigPipe/BigPipe.php
index 9499f2e..2989a75 100755
--- a/include/classes/BigPipe/BigPipe.php
+++ b/include/classes/BigPipe/BigPipe.php
@@ -14,7 +14,6 @@ class BigPipe {
private static $debugging = FALSE;
private static $enabled = TRUE;
private static $pagelets = [];
- private static $count = 0;
#===============================================================================
# Enable or disable the pipeline mode
@@ -39,11 +38,17 @@ class BigPipe {
}
#===============================================================================
- # Add a new pagelet to pipeline
+ # Insert pagelet into queue
#===============================================================================
- public static function addPagelet(Pagelet $Pagelet, $priority) {
- self::$pagelets[$priority][] = $Pagelet;
- return ++self::$count;
+ public static function enqueue(Pagelet $Pagelet) {
+ self::$pagelets[spl_object_hash($Pagelet)] = $Pagelet;
+ }
+
+ #===============================================================================
+ # Remove pagelet from queue
+ #===============================================================================
+ public static function dequeue(Pagelet $Pagelet) {
+ unset(self::$pagelets[spl_object_hash($Pagelet)]);
}
#===============================================================================
@@ -102,24 +107,32 @@ class BigPipe {
}
#===============================================================================
- # Render the pagelets
+ # Renders all remaining pagelets from the queue in the appropriate order
#===============================================================================
public static function render() {
self::flushOutputBuffer();
$i = 0;
- ksort(self::$pagelets);
+ $pagelets_ordered = [];
+
+ foreach(self::$pagelets as $Pagelet) {
+ $pagelets_ordered[$Pagelet->getPriority()][] = $Pagelet;
+ }
+
+ krsort($pagelets_ordered);
+
+ if(!empty($pagelets_ordered)) {
+ $pagelets = call_user_func_array('array_merge', $pagelets_ordered);
- foreach(array_reverse(self::$pagelets) as $priority => $pagelets) {
foreach($pagelets as $Pagelet) {
if(!self::enabled()) {
foreach($Pagelet->getResources()[Resource::TYPE_STYLESHEET] as $Resource) {
- echo $Resource->renderHTML()."\n";
+ echo "{$Resource->renderHTML()}\n";
}
foreach($Pagelet->getResources()[Resource::TYPE_JAVASCRIPT] as $Resource) {
- echo $Resource->renderHTML()."\n";
+ echo "{$Resource->renderHTML()}\n";
}
foreach($Pagelet->getJSCode() as $JSCode) {
@@ -128,7 +141,7 @@ class BigPipe {
}
else {
- self::singleResponse($Pagelet, (self::$count === ++$i));
+ self::singleResponse($Pagelet, (count(self::$pagelets) === ++$i));
self::flushOutputBuffer();
}
}
diff --git a/include/classes/BigPipe/Pagelet.php b/include/classes/BigPipe/Pagelet.php
index 484a6e2..bdab651 100755
--- a/include/classes/BigPipe/Pagelet.php
+++ b/include/classes/BigPipe/Pagelet.php
@@ -43,7 +43,7 @@ class Pagelet extends Item {
$this->resources = array_pad($this->resources, 2, []);
$this->phaseDoneJS = array_pad($this->phaseDoneJS, 5, []);
- BigPipe::addPagelet($this, $priority);
+ BigPipe::enqueue($this);
}
#===============================================================================