diff options
author | Thomas Lange <code@nerdmind.de> | 2018-01-21 10:53:59 +0100 |
---|---|---|
committer | Thomas Lange <code@nerdmind.de> | 2018-01-21 10:53:59 +0100 |
commit | 313b4fbe8d2057e6672e0ea479753c5710e85404 (patch) | |
tree | 419c3cc60dbdb38e3b336a26d7bb4870ab92ddec | |
parent | 7d9b548391780db5d590a7148411b6eb59c189fb (diff) | |
download | bigpipe-313b4fbe8d2057e6672e0ea479753c5710e85404.tar.gz bigpipe-313b4fbe8d2057e6672e0ea479753c5710e85404.tar.xz bigpipe-313b4fbe8d2057e6672e0ea479753c5710e85404.zip |
Restructure the BigPipe::render() method
-rw-r--r-- | include/classes/BigPipe/BigPipe.php | 24 |
1 files changed, 14 insertions, 10 deletions
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 "<script>{$JSCode}</script>\n"; } } - - else { - self::singleResponse($Pagelet); - self::flushOutputBuffer(); - } } } - if(BigPipe::enabled()) { + if(self::enabled()) { echo "<script>BigPipe.onLastPageletArrived();</script>\n"; } } |