This repository has been archived by the owner on Jan 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFrontController.php
76 lines (76 loc) · 2.04 KB
/
FrontController.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
namespace RedCat\Route;
use RedCat\Strategy\Di;
class FrontController implements \ArrayAccess{
protected $router;
protected $request;
protected $di;
protected $uri;
function __construct(Router $router, Request $request, Di $di=null){
$this->router = $router;
$this->request = $request;
$this->di = $di;
}
function getRoutes(){
return $this->router->getRoutes();
}
function getGroups(){
return $this->router->getGroups();
}
function find($uri,$server=null){
return $this->router->find($uri,$server);
}
function map($map,$index=0,$prepend=false,$group=null,$continue=false){
return $this->router->map($map,$index,$prepend,$group,$continue);
}
function append($match,$route=null,$index=0,$group=null,$continue=false){
return $this->router->append($match,$route,$index,$group,$continue);
}
function prepend($match,$route=null,$index=0,$group=null,$continue=false){
return $this->router->prepend($match,$route,$index,$group,$continue);
}
function group($group=null,$callback=null,$prepend=false){
return $this->router->group($group,$callback,$prepend);
}
function getUri(){
return $this->uri;
}
function run($uri,$domain=null){
$uri = ltrim($uri,'/');
$this->uri = $uri;
if($this->router->find($uri,$domain)){
$this->router->display();
return true;
}
}
function offsetSet($k,$v){
$this->router->offsetSet($k,$v);
}
function offsetGet($k){
$this->router->offsetGet($k);
}
function offsetExists($k){
$this->router->offsetExists($k);
}
function offsetUnset($k){
$this->router->offsetUnset($k);
}
function runFromGlobals(){
if(isset($_SERVER['REDCAT_URI'])){
$s = strlen($_SERVER['REDCAT_URI'])-1;
$p = strpos($_SERVER['REQUEST_URI'],'?');
if($p===false)
$path = substr($_SERVER['REQUEST_URI'],$s);
else
$path = substr($_SERVER['REQUEST_URI'],$s,$p-$s);
$path = urldecode($path);
}
else{
$path = isset($_SERVER['PATH_INFO'])?$_SERVER['PATH_INFO']:'';
}
return $this->run($path,$_SERVER['SERVER_NAME']);
}
function __invoke($uri,$domain=null){
return $this->run($uri,$domain);
}
}