phaseDoneJS = array_pad($this->phaseDoneJS, 5, []); $this->dependencies = $dependencies; $this->ID = is_string($customID) ? $customID : 'P'.++self::$count; BigPipe::addPagelet($this, $priority); } #=============================================================================== # Return the unique ID #=============================================================================== public function getID() { return $this->ID; } #=============================================================================== # Return the HTML content #=============================================================================== public function getHTML() { return $this->HTML; } #=============================================================================== # Return the main JS code #=============================================================================== public function getJSCode() { return $this->JSCode; } #=============================================================================== # Add HTML or attach more #=============================================================================== public function addHTML($HTML) { return $this->HTML .= $HTML; } #=============================================================================== # 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; } } #=============================================================================== # Short: Add CSS resource by URL #=============================================================================== public function addCSS($resourceURL): Resource { return $this->addResource(new Resource\CSS($resourceURL)); } #=============================================================================== # Short: Add JS resource by URL #=============================================================================== public function addJS($resourceURL): Resource { return $this->addResource(new Resource\JS($resourceURL)); } #=============================================================================== # Attach a main JS code part #=============================================================================== public function addJSCode($code) { 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 #=============================================================================== public function setTagname($tagname) { return $this->tagname = $tagname; } #=============================================================================== # Magic method: __toString() #=============================================================================== public function __toString() { $pageletHTML = "<{$this->tagname} id=\"{$this->getID()}\">"; $pageletHTML .= !BigPipe::enabled() ? $this->getHTML() : NULL; $pageletHTML .= "tagname}>"; return $pageletHTML; } }