From da4f78acb9b9d932423bf59a791554cf9552381b Mon Sep 17 00:00:00 2001 From: Thomas Lange Date: Sun, 21 Jan 2018 11:01:08 +0100 Subject: Move BigPipe::singleResponse() to Pagelet::flush() --- include/classes/BigPipe/BigPipe.php | 18 +----------------- include/classes/BigPipe/Pagelet.php | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 17 deletions(-) (limited to 'include/classes') diff --git a/include/classes/BigPipe/BigPipe.php b/include/classes/BigPipe/BigPipe.php index 9bb9fcb..d84083e 100644 --- a/include/classes/BigPipe/BigPipe.php +++ b/include/classes/BigPipe/BigPipe.php @@ -39,21 +39,6 @@ class BigPipe { unset(self::$pagelets[spl_object_hash($Pagelet)]); } - #=============================================================================== - # Prints a single pagelet response - #=============================================================================== - private static function singleResponse(Pagelet $Pagelet) { - $pageletJSON = $Pagelet->getStructure(); - - $pageletHTML = removeLineBreaksAndTabs($Pagelet->getHTML()); - $pageletHTML = str_replace('--', '--', $pageletHTML); - - $pageletJSON = json_encode($pageletJSON); - - echo "\n"; - echo "\n\n"; - } - #=============================================================================== # Sends output buffer so far as possible towards user #=============================================================================== @@ -80,8 +65,7 @@ class BigPipe { if(self::enabled()) { foreach($pagelets as $Pagelet) { - self::singleResponse($Pagelet); - self::flushOutputBuffer(); + $Pagelet->flush(); } } diff --git a/include/classes/BigPipe/Pagelet.php b/include/classes/BigPipe/Pagelet.php index ae465ab..101ec34 100644 --- a/include/classes/BigPipe/Pagelet.php +++ b/include/classes/BigPipe/Pagelet.php @@ -147,6 +147,24 @@ class Pagelet extends Item { ]; } + #=============================================================================== + # Flush pagelet immediately + #=============================================================================== + public function flush() { + if(BigPipe::enabled()) { + $pageletHTML = removeLineBreaksAndTabs($this->getHTML()); + $pageletHTML = str_replace('--', '--', $pageletHTML); + + $pageletJSON = json_encode($this->getStructure()); + + echo "\n"; + echo "\n\n"; + + BigPipe::dequeue($this); + BigPipe::flushOutputBuffer(); + } + } + #=============================================================================== # Magic method: __toString() #=============================================================================== -- cgit v1.2.3