-
Notifications
You must be signed in to change notification settings - Fork 0
/
Router.php
54 lines (45 loc) · 1022 Bytes
/
Router.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
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
/**
* Created by PhpStorm.
* User: sridhav
* Date: 12/2/2014
* Time: 7:59 PM
*/
class Router {
protected $uri=[];
function add($uri,$callback,$get=null,$post=null){
$temp=new URI($uri,$callback,$get,$post);
array_push($this->uri,$temp);
}
function run(){
$req=$_SERVER['REQUEST_URI'];
$req=str_replace("/Router/","",$req);
foreach($this->uri as $temp){
if($temp->getURI()=="/".$req){
echo "ITS HERE $req";
break;
}
}
}
}
class URI{
protected $uri;
protected $callback;
protected $get;
protected $post;
public function getURI(){
return $this->uri;
}
function __construct($uri,$callback,$get,$post){
$this->uri=$uri;
$this->callback=$callback;
}
function run(){
if(is_callable($this->callback)){
call_user_func($this->callback);
}
else{
echo "HELLEEEEE";
}
}
}