|
@@ -25,7 +25,7 @@ class SimpleRouter implements Router
|
25
|
25
|
|
26
|
26
|
public function __construct(string $basePath, Responder $responder, Cache $cache, int $ttl, bool $debug)
|
27
|
27
|
{
|
28
|
|
- $this->basePath = $basePath;
|
|
28
|
+ $this->basePath = $this->detectBasePath($basePath);
|
29
|
29
|
$this->responder = $responder;
|
30
|
30
|
$this->cache = $cache;
|
31
|
31
|
$this->ttl = $ttl;
|
|
@@ -36,6 +36,21 @@ class SimpleRouter implements Router
|
36
|
36
|
$this->middlewares = array();
|
37
|
37
|
}
|
38
|
38
|
|
|
39
|
+ private function detectBasePath(string $basePath): string
|
|
40
|
+ {
|
|
41
|
+ if ($basePath) {
|
|
42
|
+ return $basePath;
|
|
43
|
+ }
|
|
44
|
+ if (isset($_SERVER['PATH_INFO'])) {
|
|
45
|
+ $fullPath = array_shift(explode('?',$_SERVER['REQUEST_URI']));
|
|
46
|
+ $path = $_SERVER['PATH_INFO'];
|
|
47
|
+ if (substr($fullPath, -1*strlen($path)) == $path) {
|
|
48
|
+ return substr($fullPath, 0, -1*strlen($path));
|
|
49
|
+ }
|
|
50
|
+ }
|
|
51
|
+ return '';
|
|
52
|
+ }
|
|
53
|
+
|
39
|
54
|
private function loadPathTree(): PathTree
|
40
|
55
|
{
|
41
|
56
|
$data = $this->cache->get('PathTree');
|
|
@@ -101,6 +116,11 @@ class SimpleRouter implements Router
|
101
|
116
|
return $request;
|
102
|
117
|
}
|
103
|
118
|
|
|
119
|
+ public function getBasePath(): string
|
|
120
|
+ {
|
|
121
|
+ return $this->basePath;
|
|
122
|
+ }
|
|
123
|
+
|
104
|
124
|
public function handle(ServerRequestInterface $request): ResponseInterface
|
105
|
125
|
{
|
106
|
126
|
$request = $this->removeBasePath($request);
|