1
|
|
|
<?php |
2
|
|
|
namespace core; |
3
|
|
|
|
4
|
|
|
|
5
|
|
|
class RouterController { |
6
|
|
|
private $page; |
7
|
|
|
private $controller; |
8
|
|
|
private $part; |
9
|
|
|
private $erreur; |
10
|
|
|
|
11
|
|
|
//-------------------------- BUILDER ----------------------------------------------------------------------------// |
12
|
|
|
public function __construct($page, $admin = null) { |
13
|
|
|
if (strpos($page, "controller") !== false) { |
14
|
|
|
$this->part = "app"; |
15
|
|
|
if ($admin !== null) { |
16
|
|
|
$this->part = "admin"; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
$this->page = $page; |
20
|
|
|
|
21
|
|
|
$this->getLinkController(); |
22
|
|
|
$this->getTestControllerExist(); |
23
|
|
|
$this->erreur = false; |
24
|
|
|
} |
25
|
|
|
} |
26
|
|
|
//-------------------------- END BUILDER ----------------------------------------------------------------------------// |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
//-------------------------- GETTER ----------------------------------------------------------------------------// |
30
|
|
|
public function getController() { |
31
|
|
|
return $this->controller; |
32
|
|
|
} |
33
|
|
|
public function getErreur() { |
34
|
|
|
return $this->erreur; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* function that get link of a controller |
39
|
|
|
*/ |
40
|
|
|
private function getLinkController() { |
41
|
|
|
if (($this->getTestCoreController() === false) && ($this->getTestModuleController() === false)) { |
42
|
|
|
$this->controller = $this->part."/".$this->page.".php"; |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @return bool |
48
|
|
|
* this function set if is a controller core the link to the controller |
49
|
|
|
*/ |
50
|
|
|
private function getTestCoreController() { |
51
|
|
|
if (strpos($this->page, "controller/core") !== false) { |
52
|
|
|
$this->controller = $this->getBaseLink().".php"; |
53
|
|
|
return true; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return false; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @return bool |
61
|
|
|
* this function set if is a controller module the link to the controller |
62
|
|
|
*/ |
63
|
|
|
private function getTestModuleController() { |
64
|
|
|
if (strpos($this->page, "controller/modules") !== false) { |
65
|
|
|
$explode = explode("/", $this->getBaseLink(), 3); |
66
|
|
|
$this->controller = $explode[0]."/".$explode[1]."/".$this->part."/controller/".$explode[2].".php"; |
67
|
|
|
return true; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
return false; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return mixed |
75
|
|
|
* this function return link and delete controller at the begining of the link |
76
|
|
|
*/ |
77
|
|
|
private function getBaseLink() { |
78
|
|
|
$explode = explode("/", $this->page, 2); |
79
|
|
|
return end($explode); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* redirect on 404 if controller doesn't exist |
84
|
|
|
*/ |
85
|
|
|
private function getTestControllerExist() { |
86
|
|
|
if (!file_exists($this->controller)) { |
87
|
|
|
RedirectError::Redirect(404); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
//-------------------------- END GETTER ----------------------------------------------------------------------------// |
91
|
|
|
|
92
|
|
|
|
93
|
|
|
//-------------------------- SETTER ----------------------------------------------------------------------------// |
94
|
|
|
//-------------------------- END SETTER ----------------------------------------------------------------------------// |
95
|
|
|
} |