From dc0b1a382b5f980cffe87e9965e659d07107026e Mon Sep 17 00:00:00 2001 From: Thomas Lange Date: Sun, 10 Jul 2016 11:24:33 +0200 Subject: Each resource has now an ID; Code improvements and comment blocks added. --- include/classes/BigPipe/Pagelet.php | 98 +++++++++++++------------------------ 1 file changed, 33 insertions(+), 65 deletions(-) (limited to 'include/classes/BigPipe/Pagelet.php') 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 @@ ] # +#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%# +# # +# [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,10 +54,24 @@ 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 #=============================================================================== @@ -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)); } #=============================================================================== @@ -105,41 +107,6 @@ class Pagelet { return $this->JSCode[] = $code; } - #=============================================================================== - # 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 #=============================================================================== @@ -157,4 +124,5 @@ class Pagelet { return $pageletHTML; } -} \ No newline at end of file +} +?> \ No newline at end of file -- cgit v1.2.3