aboutsummaryrefslogtreecommitdiffstats
path: root/include/classes/BigPipe/Pagelet.php
diff options
context:
space:
mode:
Diffstat (limited to 'include/classes/BigPipe/Pagelet.php')
-rwxr-xr-xinclude/classes/BigPipe/Pagelet.php98
1 files changed, 33 insertions, 65 deletions
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