aboutsummaryrefslogtreecommitdiffstats
path: root/include/classes/BigPipe/Resource.php
diff options
context:
space:
mode:
authorThomas Lange <code@nerdmind.de>2016-06-25 15:34:34 +0200
committerThomas Lange <code@nerdmind.de>2016-06-25 15:34:34 +0200
commit21824df56bd13d81f10ac0b86c5cad31def51f3e (patch)
tree5d5e8c29a87c82163d55d139680db359bc5cf839 /include/classes/BigPipe/Resource.php
parentc5637489e603c588fca41e2b7bd4345b67914f33 (diff)
downloadbigpipe-21824df56bd13d81f10ac0b86c5cad31def51f3e.tar.gz
bigpipe-21824df56bd13d81f10ac0b86c5cad31def51f3e.tar.xz
bigpipe-21824df56bd13d81f10ac0b86c5cad31def51f3e.zip
Update with new features and code improvements.
+ New classes have been added: "BigPipe\Resource", "BigPipe\Resource\CSS", "BigPipe\Resource\JS". If you wan't to add a resource to a Pagelet, you can now built a new resource object with the "CSS" or "JS" class (the "Resource" class is abstract and the parent class of "CSS" and "JS") and can add PhaseDoneJS callbacks for this resources with "Resource::addPhaseDoneJS()" similar to "Pagelet::addPhaseDoneJS()". To add the resource to your pagelet: "$Pagelet->addResource($Resource)". Of course, you can still use the two SHORT methods "Pagelet::addCSS()" and "Pagelet::addJS()" which needs only one parameter with the resource URL. + Each resource has now PhaseDoneJS callbacks for 3 phases (Object initializied [INIT], Loading started [LOAD], Loading complete [DONE]). + Check your usage of the PhaseDoneJS callback constants of the Pagelet class: These constants have been renamed. + Debugging mode: Just set BigPipe::debugging(TRUE) and each pagelet and resource will be pass through a function which adds PhaseDoneJS callbacks with debug informations (Look now at the Javascript console and enjoy the beautiful colors which makes the debug informations better readable for your eyes. \(o_o)/). + Several code improvements on almost all files.
Diffstat (limited to 'include/classes/BigPipe/Resource.php')
-rwxr-xr-xinclude/classes/BigPipe/Resource.php74
1 files changed, 74 insertions, 0 deletions
diff --git a/include/classes/BigPipe/Resource.php b/include/classes/BigPipe/Resource.php
new file mode 100755
index 0000000..d93ad16
--- /dev/null
+++ b/include/classes/BigPipe/Resource.php
@@ -0,0 +1,74 @@
+<?php
+namespace BigPipe;
+
+abstract class Resource {
+ private $ID = '';
+ private $type = '';
+ private $resourceURL = '';
+ private $phaseDoneJS = [];
+ private static $count = 0;
+
+ #===============================================================================
+ # Render resource HTML for disabled pipeline
+ #===============================================================================
+ abstract public function renderHTML();
+
+ #===============================================================================
+ # Resource types
+ #===============================================================================
+ const TYPE_STYLESHEET = 0;
+ const TYPE_JAVASCRIPT = 1;
+
+ #===============================================================================
+ # Phase numbers for PhaseDoneJS
+ #===============================================================================
+ const PHASE_INIT = 0; # Resource object has been initialized
+ const PHASE_LOAD = 1; # Loading of resource has been started
+ const PHASE_DONE = 2; # Loading of resource is done.
+
+ #===============================================================================
+ # Build resource
+ #===============================================================================
+ public function __construct($type, $resourceURL) {
+ $this->phaseDoneJS = array_pad($this->phaseDoneJS, 3, []);
+ $this->ID = 'R'.++self::$count;
+ $this->type = $type;
+ $this->resourceURL = $resourceURL;
+ }
+
+ #===============================================================================
+ # Return the unique ID
+ #===============================================================================
+ public function getID() {
+ return $this->ID;
+ }
+
+ #===============================================================================
+ # Return the resource type
+ #===============================================================================
+ public function getType() {
+ return $this->type;
+ }
+
+ #===============================================================================
+ # Return the resource URL
+ #===============================================================================
+ 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