1
|
|
|
<?php |
2
|
|
|
class Module { |
|
|
|
|
3
|
|
|
public $name; |
4
|
|
|
public $modules; |
5
|
|
|
public $files; |
6
|
|
|
public $required; |
7
|
|
|
public $data; |
8
|
|
|
public function __construct() { |
9
|
|
|
$this->name = get_class($this); |
10
|
|
|
$this->modules = []; |
11
|
|
|
$this->files = []; |
12
|
|
|
$this->required = []; |
13
|
|
|
$this->data = []; |
14
|
|
|
} |
15
|
|
|
// abstract public function config(); |
|
|
|
|
16
|
|
|
// abstract public function init(); |
|
|
|
|
17
|
|
|
// abstract public function draw(); |
|
|
|
|
18
|
|
|
public function getCss() { |
19
|
|
|
return $this->getRequire("getCss",".css"); |
20
|
|
|
} |
21
|
|
|
public function getJs() { |
22
|
|
|
return $this->getRequire("getJs",".js"); |
23
|
|
|
} |
24
|
|
|
public function getJsVariables() { |
25
|
|
|
$temp = []; |
26
|
|
|
foreach ($this->required as $i) |
27
|
|
|
if (is_array($i)) |
28
|
|
|
array_push($temp,$i); |
29
|
|
|
foreach ($this->modules as $i) |
30
|
|
|
$temp = array_merge( $temp, $i->getJsVariables() ); |
31
|
|
|
foreach ($this->files as $i) |
32
|
|
|
if (is_array($i)) |
33
|
|
|
array_push($temp,$i); |
34
|
|
|
return $temp; |
35
|
|
|
} |
36
|
|
|
public function addModules( $_mods ) { |
37
|
|
|
foreach ($_mods as $value) |
38
|
|
|
$this->addModule($value); |
39
|
|
|
} |
40
|
|
|
public function addModule( $_mod ) { |
41
|
|
|
$this->modules[$_mod->name] = $_mod; |
42
|
|
|
} |
43
|
|
|
public function addFiles( $_files ) { |
44
|
|
|
foreach ($_files as $value) |
45
|
|
|
$this->addFile($value); |
46
|
|
|
} |
47
|
|
|
public function addFile( $_file ) { |
48
|
|
|
array_push($this->files, $_file); |
49
|
|
|
} |
50
|
|
|
public function addFilesRequired( $_files ) { |
51
|
|
|
foreach ($_files as $value) |
52
|
|
|
$this->addFileRequired($value); |
53
|
|
|
} |
54
|
|
|
public function addFileRequired( $_file ) { |
55
|
|
|
array_push($this->required, $_file); |
56
|
|
|
} |
57
|
|
|
protected function addDipendences() { |
58
|
|
|
$this->data["css"] = $this->getCss(); |
59
|
|
|
$this->data["js"] = $this->getJs(); |
60
|
|
|
$this->data["jsVariables"] = $this->getJsVariables(); |
61
|
|
|
} |
62
|
|
|
protected function getRequire( $_function, $_extenction) { |
63
|
|
|
$temp = []; |
64
|
|
View Code Duplication |
foreach ($this->required as $i) |
|
|
|
|
65
|
|
|
if (!is_array($i) && strpos($i, $_extenction) !== FALSE) |
66
|
|
|
array_push($temp,$i); |
67
|
|
|
foreach ($this->modules as $i) |
68
|
|
|
$temp = array_merge( $temp, $i->$_function() ); |
69
|
|
View Code Duplication |
foreach ($this->files as $i) |
|
|
|
|
70
|
|
|
if (!is_array($i) && strpos($i, $_extenction) !== FALSE) |
71
|
|
|
array_push($temp,$i); |
72
|
|
|
return $temp; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
?> |
|
|
|
|
76
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.