aboutsummaryrefslogtreecommitdiffstats
path: root/include/classes/Document.php
diff options
context:
space:
mode:
authorThomas Lange <code@nerdmind.de>2018-12-31 00:23:06 +0100
committerThomas Lange <code@nerdmind.de>2018-12-31 00:23:06 +0100
commita0725d0bf159283e278168e3bd1dc0fe3e6da7ab (patch)
treea7788e618b82c7957cc56e2be3967fcfa8f03df0 /include/classes/Document.php
parentdf4865e7bcc3857be2f4b57d565a501a097b0daa (diff)
downloadbigpipe-a0725d0bf159283e278168e3bd1dc0fe3e6da7ab.tar.gz
bigpipe-a0725d0bf159283e278168e3bd1dc0fe3e6da7ab.tar.xz
bigpipe-a0725d0bf159283e278168e3bd1dc0fe3e6da7ab.zip
Temporary branch: last-pagelet-event-optimizationlast-pagelet-event-optimization
Diffstat (limited to 'include/classes/Document.php')
-rw-r--r--include/classes/Document.php34
1 files changed, 34 insertions, 0 deletions
diff --git a/include/classes/Document.php b/include/classes/Document.php
new file mode 100644
index 0000000..9b9893a
--- /dev/null
+++ b/include/classes/Document.php
@@ -0,0 +1,34 @@
+<?php
+use BigPipe\BigPipe;
+use BigPipe\Pagelet;
+
+class Document {
+ private $contentCallbacks = [];
+ private $pagelets = [];
+
+ public function addPagelet(Pagelet $Pagelet, callable $callback) {
+ $this->pagelets[] = $Pagelet;
+
+ $this->contentCallbacks[$Pagelet->getID()] = $callback;
+
+ if(!BigPipe::enabled()) {
+ $Pagelet->addHTML($callback($Pagelet));
+ }
+ }
+
+ public function render($content_html, $sidebar_html) {
+ require 'template/document.php';
+ BigPipe::flushOutputBuffer();
+
+ if(BigPipe::enabled()) {
+ foreach($this->pagelets as $Pagelet) {
+ $Pagelet->addHTML($this->contentCallbacks[$Pagelet->getID()]($Pagelet));
+ $Pagelet->flush();
+ }
+ }
+
+ BigPipe::completeResponse();
+ echo "</body>\n</html>";
+ }
+}
+?> \ No newline at end of file