From 313b4fbe8d2057e6672e0ea479753c5710e85404 Mon Sep 17 00:00:00 2001 From: Thomas Lange Date: Sun, 21 Jan 2018 10:53:59 +0100 Subject: Restructure the BigPipe::render() method --- include/classes/BigPipe/BigPipe.php | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'include/classes/BigPipe/BigPipe.php') diff --git a/include/classes/BigPipe/BigPipe.php b/include/classes/BigPipe/BigPipe.php index 6e4c7f4..b94a6ae 100644 --- a/include/classes/BigPipe/BigPipe.php +++ b/include/classes/BigPipe/BigPipe.php @@ -67,8 +67,6 @@ class BigPipe { public static function render() { self::flushOutputBuffer(); - $i = 0; - $pagelets_ordered = []; foreach(self::$pagelets as $Pagelet) { @@ -80,8 +78,19 @@ class BigPipe { if(!empty($pagelets_ordered)) { $pagelets = call_user_func_array('array_merge', $pagelets_ordered); - foreach($pagelets as $Pagelet) { - if(!self::enabled()) { + if(self::enabled()) { + foreach($pagelets as $Pagelet) { + self::singleResponse($Pagelet); + self::flushOutputBuffer(); + } + } + + # NOTE: If BigPipe is disabled, Pagelet::flush() will NOT call BigPipe::dequeue(). + # This means that (if the pipeline is disabled) $pagelets_ordered contains ALL + # Pagelets regardless of whether if Pagelet::flush() was already called. And then + # we can iterate over them and echo all requiered CSS and JS resources. + else { + foreach($pagelets as $Pagelet) { foreach($Pagelet->getResources()[Resource::TYPE_STYLESHEET] as $Resource) { echo "{$Resource->renderHTML()}\n"; } @@ -94,15 +103,10 @@ class BigPipe { echo "\n"; } } - - else { - self::singleResponse($Pagelet); - self::flushOutputBuffer(); - } } } - if(BigPipe::enabled()) { + if(self::enabled()) { echo "\n"; } } -- cgit v1.2.3