aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rwxr-xr-xinclude/classes/BigPipe/BigPipe.php33
-rw-r--r--include/classes/BigPipe/Item.php38
-rwxr-xr-xinclude/classes/BigPipe/Pagelet.php98
-rwxr-xr-xinclude/classes/BigPipe/Resource.php37
-rw-r--r--include/classes/BigPipe/Resource/CSS.php11
-rw-r--r--include/classes/BigPipe/Resource/JS.php11
6 files changed, 121 insertions, 107 deletions
diff --git a/include/classes/BigPipe/BigPipe.php b/include/classes/BigPipe/BigPipe.php
index 082ca14..8d95779 100755
--- a/include/classes/BigPipe/BigPipe.php
+++ b/include/classes/BigPipe/BigPipe.php
@@ -1,4 +1,13 @@
<?php
+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#
+# BigPipe main class [Thomas Lange <tl@nerdmind.de>] #
+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#
+# #
+# The BigPipe main class is responsible for sorting and rendering the pagelets #
+# and their associated resources. This class also provides methods to turn off #
+# the pipelining mode or turn on the debugging mode. #
+# #
+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#
namespace BigPipe;
class BigPipe {
@@ -44,8 +53,8 @@ class BigPipe {
if(self::debugging()) {
self::addDebugPhaseDoneJS($Pagelet);
- array_map('self::addDebugPhaseDoneJS', $Pagelet->getCSSResources());
- array_map('self::addDebugPhaseDoneJS', $Pagelet->getJSResources());
+ array_map('self::addDebugPhaseDoneJS', $Pagelet->getResources()[Resource::TYPE_STYLESHEET]);
+ array_map('self::addDebugPhaseDoneJS', $Pagelet->getResources()[Resource::TYPE_JAVASCRIPT]);
usleep(rand(125, 175) * 2000);
}
@@ -53,20 +62,20 @@ class BigPipe {
$stylesheets = [];
$javascripts = [];
- foreach($Pagelet->getCSSResources() as $Resource) {
- $stylesheets[$Resource->getURL()] = $Resource->getPhaseDoneJS();
+ foreach($Pagelet->getResources()[Resource::TYPE_STYLESHEET] as $Resource) {
+ $stylesheets[] = ['ID' => $Resource->getID(), 'HREF' => $Resource->getURL(), 'PHASE' => $Resource->getPhaseDoneJS()];
}
- foreach($Pagelet->getJSResources() as $Resource) {
- $javascripts[$Resource->getURL()] = $Resource->getPhaseDoneJS();
+ foreach($Pagelet->getResources()[Resource::TYPE_JAVASCRIPT] as $Resource) {
+ $javascripts[] = ['ID' => $Resource->getID(), 'HREF' => $Resource->getURL(), 'PHASE' => $Resource->getPhaseDoneJS()];
}
$pageletJSON = [
- 'ID' => $Pagelet->getID(),
+ 'ID' => $Pagelet->getID(),
'NEED' => $Pagelet->getDependencies(),
- 'RSRC' => (object) [
- Resource::TYPE_STYLESHEET => (object) $stylesheets,
- Resource::TYPE_JAVASCRIPT => (object) $javascripts,
+ 'RSRC' => [
+ Resource::TYPE_STYLESHEET => $stylesheets,
+ Resource::TYPE_JAVASCRIPT => $javascripts,
],
'CODE' => removeLineBreaksAndTabs($Pagelet->getJSCode()),
'PHASE' => $Pagelet->getPhaseDoneJS()
@@ -105,11 +114,11 @@ class BigPipe {
foreach(array_reverse(self::$pagelets) as $priority => $pagelets) {
foreach($pagelets as $Pagelet) {
if(!self::enabled()) {
- foreach($Pagelet->getCSSResources() as $Resource) {
+ foreach($Pagelet->getResources()[Resource::TYPE_STYLESHEET] as $Resource) {
echo $Resource->renderHTML()."\n";
}
- foreach($Pagelet->getJSResources() as $Resource) {
+ foreach($Pagelet->getResources()[Resource::TYPE_JAVASCRIPT] as $Resource) {
echo $Resource->renderHTML()."\n";
}
diff --git a/include/classes/BigPipe/Item.php b/include/classes/BigPipe/Item.php
new file mode 100644
index 0000000..a4c739c
--- /dev/null
+++ b/include/classes/BigPipe/Item.php
@@ -0,0 +1,38 @@
+<?php
+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#
+# Abstract item class [Thomas Lange <tl@nerdmind.de>] #
+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#
+# #
+# The item class abstracts the properties and methods that are required by the #
+# Pagelet and Resource class both. Each one can have PhaseDoneJS callbacks for #
+# several phases numbers which are defined as constants of the specific class. #
+# #
+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#
+namespace BigPipe;
+
+abstract class Item {
+ protected $ID = '';
+ protected $phaseDoneJS = [];
+
+ #===============================================================================
+ # Return the unique ID
+ #===============================================================================
+ public function getID() {
+ return $this->ID;
+ }
+
+ #===============================================================================
+ # Return all registered PhaseDoneJS callbacks
+ #===============================================================================
+ public function getPhaseDoneJS(): array {
+ return $this->phaseDoneJS;
+ }
+
+ #===============================================================================
+ # Attach a PhaseDoneJS callback
+ #===============================================================================
+ public function addPhaseDoneJS($phase, $callback) {
+ return $this->phaseDoneJS[$phase][] = removeLineBreaksAndTabs($callback);
+ }
+}
+?> \ No newline at end of file
diff --git a/include/classes/BigPipe/Pagelet.php b/include/classes/BigPipe/Pagelet.php
index 7502a02..c81460f 100755
--- a/include/classes/BigPipe/Pagelet.php
+++ b/include/classes/BigPipe/Pagelet.php
@@ -1,13 +1,17 @@
<?php
+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#
+# Pagelet representation class [Thomas Lange <tl@nerdmind.de>] #
+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#
+# #
+# [More information coming soon] #
+# #
+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#
namespace BigPipe;
-class Pagelet {
- private $ID = '';
+class Pagelet extends Item {
private $HTML = '';
private $JSCode = [];
- private $JSResources = [];
- private $CSSResources = [];
- private $phaseDoneJS = [];
+ private $resources = [];
private $dependencies = [];
private $tagname = 'div';
private static $count = 0;
@@ -31,18 +35,13 @@ class Pagelet {
const PHASE_DONE = 4; # After the static JS code has been executed
public function __construct($customID = NULL, $priority = self::PRIORITY_NORMAL, array $dependencies = []) {
- $this->phaseDoneJS = array_pad($this->phaseDoneJS, 5, []);
+ $this->ID = $customID ?? 'P'.++self::$count;
$this->dependencies = $dependencies;
- $this->ID = is_string($customID) ? $customID : 'P'.++self::$count;
- BigPipe::addPagelet($this, $priority);
- }
+ $this->resources = array_pad($this->resources, 2, []);
+ $this->phaseDoneJS = array_pad($this->phaseDoneJS, 5, []);
- #===============================================================================
- # Return the unique ID
- #===============================================================================
- public function getID() {
- return $this->ID;
+ BigPipe::addPagelet($this, $priority);
}
#===============================================================================
@@ -55,11 +54,25 @@ class Pagelet {
#===============================================================================
# Return the main JS code
#===============================================================================
- public function getJSCode() {
+ public function getJSCode(): array {
return $this->JSCode;
}
#===============================================================================
+ # Return attached resources
+ #===============================================================================
+ public function getResources(): array {
+ return $this->resources;
+ }
+
+ #===============================================================================
+ # Return all display dependencies
+ #===============================================================================
+ public function getDependencies(): array {
+ return $this->dependencies;
+ }
+
+ #===============================================================================
# Add HTML or attach more
#===============================================================================
public function addHTML($HTML) {
@@ -70,32 +83,21 @@ class Pagelet {
# Add resource
#===============================================================================
public function addResource(Resource $Resource): Resource {
- switch($Resource->getType()) {
- case Resource::TYPE_STYLESHEET:
- return $this->CSSResources[] = $Resource;
- break;
-
- case Resource::TYPE_JAVASCRIPT:
- return $this->JSResources[] = $Resource;
- break;
-
- default:
- return $Resource;
- }
+ return $this->resources[$Resource->getType()][] = $Resource;
}
#===============================================================================
# Short: Add CSS resource by URL
#===============================================================================
public function addCSS($resourceURL): Resource {
- return $this->addResource(new Resource\CSS($resourceURL));
+ return $this->addResource(new Resource\CSS(NULL, $resourceURL));
}
#===============================================================================
# Short: Add JS resource by URL
#===============================================================================
public function addJS($resourceURL): Resource {
- return $this->addResource(new Resource\JS($resourceURL));
+ return $this->addResource(new Resource\JS(NULL, $resourceURL));
}
#===============================================================================
@@ -106,41 +108,6 @@ class Pagelet {
}
#===============================================================================
- # Attach a PhaseDoneJS callback
- #===============================================================================
- public function addPhaseDoneJS($phase, $callback) {
- return $this->phaseDoneJS[$phase][] = removeLineBreaksAndTabs($callback);
- }
-
- #===============================================================================
- # Return all registered PhaseDoneJS callbacks
- #===============================================================================
- public function getPhaseDoneJS(): array {
- return $this->phaseDoneJS;
- }
-
- #===============================================================================
- # Return the attached CSS resources
- #===============================================================================
- public function getCSSResources(): array {
- return $this->CSSResources;
- }
-
- #===============================================================================
- # Return the attached JS resources
- #===============================================================================
- public function getJSResources(): array {
- return $this->JSResources;
- }
-
- #===============================================================================
- # Return all display dependencies
- #===============================================================================
- public function getDependencies(): array {
- return $this->dependencies;
- }
-
- #===============================================================================
# Set custom placeholder tagname
#===============================================================================
public function setTagname($tagname) {
@@ -157,4 +124,5 @@ class Pagelet {
return $pageletHTML;
}
-} \ No newline at end of file
+}
+?> \ No newline at end of file
diff --git a/include/classes/BigPipe/Resource.php b/include/classes/BigPipe/Resource.php
index d93ad16..1aaeb35 100755
--- a/include/classes/BigPipe/Resource.php
+++ b/include/classes/BigPipe/Resource.php
@@ -1,11 +1,16 @@
<?php
+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#
+# Abstract Resource representation class [Thomas Lange <tl@nerdmind.de>] #
+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#
+# #
+# [More information coming soon] #
+# #
+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#
namespace BigPipe;
-abstract class Resource {
- private $ID = '';
+abstract class Resource extends Item {
private $type = '';
private $resourceURL = '';
- private $phaseDoneJS = [];
private static $count = 0;
#===============================================================================
@@ -29,18 +34,12 @@ abstract class Resource {
#===============================================================================
# Build resource
#===============================================================================
- public function __construct($type, $resourceURL) {
- $this->phaseDoneJS = array_pad($this->phaseDoneJS, 3, []);
- $this->ID = 'R'.++self::$count;
+ public function __construct($customID = NULL, $type, $resourceURL) {
+ $this->ID = $customID ?? 'R'.++self::$count;
$this->type = $type;
$this->resourceURL = $resourceURL;
- }
- #===============================================================================
- # Return the unique ID
- #===============================================================================
- public function getID() {
- return $this->ID;
+ $this->phaseDoneJS = array_pad($this->phaseDoneJS, 3, []);
}
#===============================================================================
@@ -56,19 +55,5 @@ abstract class Resource {
public function getURL() {
return $this->resourceURL;
}
-
- #===============================================================================
- # Attach a PhaseDoneJS callback
- #===============================================================================
- public function addPhaseDoneJS($phase, $callback) {
- return $this->phaseDoneJS[$phase][] = removeLineBreaksAndTabs($callback);
- }
-
- #===============================================================================
- # Return all registered PhaseDoneJS callbacks
- #===============================================================================
- public function getPhaseDoneJS() {
- return $this->phaseDoneJS;
- }
}
?> \ No newline at end of file
diff --git a/include/classes/BigPipe/Resource/CSS.php b/include/classes/BigPipe/Resource/CSS.php
index 71d2244..b02f1cb 100644
--- a/include/classes/BigPipe/Resource/CSS.php
+++ b/include/classes/BigPipe/Resource/CSS.php
@@ -1,4 +1,11 @@
<?php
+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#
+# Resource representation class [CSS] [Thomas Lange <tl@nerdmind.de>] #
+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#
+# #
+# [More information coming soon] #
+# #
+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#
namespace BigPipe\Resource;
class CSS extends \BigPipe\Resource {
@@ -6,8 +13,8 @@ class CSS extends \BigPipe\Resource {
#===============================================================================
# Build resource
#===============================================================================
- public function __construct($resourceURL) {
- parent::__construct(parent::TYPE_STYLESHEET, $resourceURL);
+ public function __construct($customID = NULL, $resourceURL) {
+ parent::__construct($customID, parent::TYPE_STYLESHEET, $resourceURL);
}
#===============================================================================
diff --git a/include/classes/BigPipe/Resource/JS.php b/include/classes/BigPipe/Resource/JS.php
index f9e109b..e79bd8b 100644
--- a/include/classes/BigPipe/Resource/JS.php
+++ b/include/classes/BigPipe/Resource/JS.php
@@ -1,4 +1,11 @@
<?php
+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#
+# Resource representation class [JS] [Thomas Lange <tl@nerdmind.de>] #
+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#
+# #
+# [More information coming soon] #
+# #
+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#
namespace BigPipe\Resource;
class JS extends \BigPipe\Resource {
@@ -6,8 +13,8 @@ class JS extends \BigPipe\Resource {
#===============================================================================
# Build resource
#===============================================================================
- public function __construct($resourceURL) {
- parent::__construct(parent::TYPE_JAVASCRIPT, $resourceURL);
+ public function __construct($customID = NULL, $resourceURL) {
+ parent::__construct($customID, parent::TYPE_JAVASCRIPT, $resourceURL);
}
#===============================================================================