1
|
|
|
<?php |
2
|
|
|
class WebApp extends Module { |
|
|
|
|
3
|
|
|
protected $pages; |
4
|
|
|
protected $defaultPage; |
5
|
|
|
public $currentPage; |
6
|
|
|
public $jConfig; |
7
|
|
|
public function __construct() { |
8
|
|
|
parent::__construct(); |
9
|
|
|
$this->pages = []; |
10
|
|
|
$this->defaultPage = ["Page404",[]]; |
11
|
|
|
$this->currentPage = null; |
12
|
|
|
$this->$jConfig = null; |
|
|
|
|
13
|
|
|
} |
14
|
|
|
public function addPage( $_page ) { |
15
|
|
|
$path = ""; |
|
|
|
|
16
|
|
|
$class = ""; |
|
|
|
|
17
|
|
|
$param = []; |
18
|
|
|
if(is_array($_page)) { |
19
|
|
|
$path = $_page[0]; |
20
|
|
|
$class = $_page[1]; |
21
|
|
|
if(isset($_page[2])) |
22
|
|
|
$param = $_page[2]; |
23
|
|
|
} else { |
24
|
|
|
$path = $_page; |
25
|
|
|
$class = $_page; |
26
|
|
|
} |
27
|
|
|
$this->pages[$path] = [$class,$param]; |
28
|
|
|
} |
29
|
|
|
public function addPages( $_pages ) { |
30
|
|
|
foreach ($_pages as $i) |
31
|
|
|
$this->addPage($i); |
32
|
|
|
} |
33
|
|
|
public function fetchPage( $_stack ) { |
34
|
|
|
$parameters = []; |
35
|
|
|
$temp = $this->defaultPage; |
36
|
|
|
$variables = null; |
|
|
|
|
37
|
|
|
foreach ($this->pages as $key => $value) { |
38
|
|
|
$variables = $this->pathSeeker(explode("/", $key), $_stack); |
39
|
|
|
if(is_array($variables)) { |
40
|
|
|
$temp = $value; |
41
|
|
|
$parameters = $variables; |
42
|
|
|
break; |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
if( isset($temp[1]) && is_array($temp[1]) ) |
46
|
|
|
$temp[1] = array_merge($temp[1], $parameters); |
47
|
|
|
else |
48
|
|
|
$temp[1] = $parameters; |
49
|
|
|
$this->currentPage = new $temp[0](["app" => $this->jConfig, "page" => $temp[1]]); |
50
|
|
|
return $this->currentPage; |
51
|
|
|
} |
52
|
|
|
public function setDefaultPage( $_page ) { |
53
|
|
|
$this->defaultPage = $_page; |
54
|
|
|
} |
55
|
|
|
public function draw() { |
56
|
|
|
$this->currentPage->uniforma(); |
57
|
|
|
$gui = new GUI(); |
58
|
|
|
$gui->init($this->currentPage); |
59
|
|
|
$gui->draw($this->currentPage->data["template"]); |
60
|
|
|
} |
61
|
|
|
public function pathSeeker( $_path, $_url ) { |
62
|
|
|
$urlLength = count($_url); |
63
|
|
|
$cont = 0; |
64
|
|
|
$variables = []; |
65
|
|
|
$pathLength = count($_path); |
66
|
|
|
if($urlLength == $pathLength) { |
67
|
|
|
while($cont < $urlLength) { |
68
|
|
|
if( $_path[$cont] == $_url[$cont] ) |
69
|
|
|
$cont++; |
70
|
|
|
else if( strpos($_path[$cont], "\$") !== false ) { |
71
|
|
|
$variables[str_replace('$', "", $_path[$cont])] = $_url[$cont]; |
72
|
|
|
$cont++; |
73
|
|
|
} else break; |
74
|
|
|
} |
75
|
|
|
if($cont == $urlLength) |
76
|
|
|
return $variables; |
77
|
|
|
} |
78
|
|
|
return null; |
79
|
|
|
} |
80
|
|
|
public function newConfig( $_path = "config/") { |
81
|
|
|
$this->jConfig = new JConfig(); |
82
|
|
|
$this->jConfig->import("${_path}connection.json","connection"); |
83
|
|
|
$this->jConfig->import("${_path}misc.json"); |
84
|
|
|
$this->jConfig->import("${_path}router.json"); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
?> |
|
|
|
|
88
|
|
|
|
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.