1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Saltwater\App\Provider; |
4
|
|
|
|
5
|
|
|
use Saltwater\Server as S; |
6
|
|
|
use Saltwater\Utils as U; |
7
|
|
|
use Saltwater\App\Common\Route as AbstractRoute; |
8
|
|
|
|
9
|
|
|
class Route extends AbstractRoute |
10
|
|
|
{ |
11
|
|
|
public function __construct() |
12
|
|
|
{ |
13
|
|
|
$this->uri = $this->getURI(); |
14
|
|
|
|
15
|
|
|
$this->http = $this->getHTTP(); |
16
|
|
|
|
17
|
|
|
$context = S::$n->modules->finder->masterContext(); |
18
|
|
|
|
19
|
|
|
if (empty($context)) { |
20
|
|
|
return; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
$this->explode($context, $this->http, explode('/', $this->uri)); |
|
|
|
|
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Get the URI from $_SERVER |
28
|
|
|
* |
29
|
|
|
* @return string |
30
|
|
|
*/ |
31
|
|
|
protected function getURI() |
32
|
|
|
{ |
33
|
|
|
return $this->filterURI( |
34
|
|
|
$_SERVER['REQUEST_URI'], |
35
|
|
|
$_SERVER['SCRIPT_NAME'] |
36
|
|
|
); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
private function filterURI($uri, $path) |
40
|
|
|
{ |
41
|
|
|
if (strpos($uri, $path) === false) { |
42
|
|
|
$path = str_replace('\\', '', dirname($path)); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
$path = substr_replace($uri, '', 0, strlen($path)); |
46
|
|
|
|
47
|
|
|
if (isset($_SERVER['REQUEST_URI'])) { |
48
|
|
|
$path = str_replace('?' . $_SERVER['REQUEST_URI'], '', $path); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$path = preg_replace('`[^a-z0-9/._-]+`', '', strtolower($path)); |
52
|
|
|
|
53
|
|
|
// TODO: Temp measure, should be possible to achieve in routing (?) |
54
|
|
|
if (strpos($path, '.zip')) { |
55
|
|
|
$path = str_replace('.zip', '', $path); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
return $path; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
protected function getHTTP() |
62
|
|
|
{ |
63
|
|
|
return strtolower($_SERVER['REQUEST_METHOD']); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param Response $response |
68
|
|
|
* @param ServiceChain $serviceChain |
69
|
|
|
*/ |
70
|
|
|
public function go($response, $serviceChain) |
71
|
|
|
{ |
72
|
|
|
echo $response->response( |
73
|
|
|
$serviceChain->resolve($this->getInput()) |
74
|
|
|
); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
protected function getInput() |
78
|
|
|
{ |
79
|
|
|
$input = @file_get_contents('php://input'); |
80
|
|
|
|
81
|
|
|
return empty($input) ? null : json_decode($input); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
} |
85
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.