-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathrouter.php
More file actions
46 lines (43 loc) · 1.21 KB
/
router.php
File metadata and controls
46 lines (43 loc) · 1.21 KB
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
<?php
class Router {
private $urlData;
private $controller;
private $action;
public function __construct($urlData) {
$this->urlData = $urlData;
if(isset($urlData['admin'])){
echo "isset";
}
if (isset ( $urlData ['p'] )) {
$this->controller = $urlData ['p'];
} else {
$this->controller = "home";
}
if (isset ( $urlData ['action'] )) {
$this->action = $urlData ['action'];
} else {
$this->action = "index";
}
}
public function getController() {
if (class_exists ( $this->controller )) {
$parents = class_parents ( $this->controller );
if (in_array ( "BaseController", $parents )) {
if (method_exists ( $this->controller, $this->action )) {
$controllerObj = new $this->controller ( $this->action, $this->urlData );
$reflectionObj = new ReflectionObject($controllerObj);
if($reflectionObj->getMethod($this->action)->isProtected() || $reflectionObj->getMethod($this->action)->isPublic()){
return $controllerObj;
}
}
}
}
// Use the homepage as default
$this->controller = "home";
$this->action = "index";
return new $this->controller ( $this->action, $this->urlData );
}
public function getControllerName() {
return $this->controller;
}
}