-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouting.php
41 lines (30 loc) · 828 Bytes
/
routing.php
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
<?php
/**
* Created by PhpStorm.
* User: menakafernando
* Date: 8/31/18
* Time: 12:43 PM
*/
class Route{
private $_uri = [];
private $_method = [];
public function add($uri, $method = null) {
$this->_uri[] = '/' .trim($uri, '/') ;
if($method != null) {
$this->_method[] = $method;
}
}
public function submit(){
$uriParam = isset( $_GET['uri']) ? '/' .$_GET['uri'] : '/';
foreach ($this->_uri as $key => $value) {
if(preg_match("#^$value$#", $uriParam)) {
if(is_string( $this->_method[$key])){
$method = $this->_method[$key];
new $method();
} else{
call_user_func($this->_method[$key]);
}
}
}
}
}