aboutsummaryrefslogtreecommitdiffstats
path: root/include/classes/BigPipe/Resource.php
blob: d93ad168d6eae8c5f48e055cb87d6827c9659a16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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;
	}
}
?>