|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Jaeger |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright Copyright (c) 2015-2016, mithra62 |
|
6
|
|
|
* @link http://jaeger-app.com |
|
7
|
|
|
* @version 1.0 |
|
8
|
|
|
* @filesource ./Rest/Platforms/Controllers/Rest.php |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace JaegerApp\Platforms\Controllers; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Jaeger - REST Base Controller |
|
15
|
|
|
* |
|
16
|
|
|
* Contains the global REST methods |
|
17
|
|
|
* |
|
18
|
|
|
* @package Rest\Authentication |
|
19
|
|
|
* @author Eric Lamb <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
class Rest |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* The JSON body payload sent with requests |
|
25
|
|
|
* @var array |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $body_data = null; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* The Rest object |
|
31
|
|
|
* @var \JaegerApp\Rest |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $rest = null; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* The abstracted platform object |
|
37
|
|
|
* |
|
38
|
|
|
* @var \JaegerApp\Platforms\Eecms |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $platform = null; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Sets the Rest object |
|
44
|
|
|
* @param \JaegerApp\Rest $rest |
|
45
|
|
|
* @return \JaegerApp\Platforms\Controllers\Rest |
|
46
|
|
|
*/ |
|
47
|
|
|
public function setRest(\JaegerApp\Rest $rest) |
|
48
|
|
|
{ |
|
49
|
|
|
$this->rest = $rest; |
|
50
|
|
|
return $this; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Returns the Rest object |
|
55
|
|
|
* @return \JaegerApp\Rest |
|
56
|
|
|
*/ |
|
57
|
|
|
public function getRest() |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->rest; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Sets the Platform object |
|
64
|
|
|
* @param \JaegerApp\Platforms\AbstractPlatform $platform |
|
65
|
|
|
* @return \JaegerApp\Platforms\Controllers\Rest |
|
66
|
|
|
*/ |
|
67
|
|
|
public function setPlatform(\JaegerApp\Platforms\AbstractPlatform $platform) |
|
68
|
|
|
{ |
|
69
|
|
|
$this->platform = $platform; |
|
|
|
|
|
|
70
|
|
|
return $this; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Returns the Platform object |
|
75
|
|
|
* @return \JaegerApp\Platforms\Eecms |
|
76
|
|
|
*/ |
|
77
|
|
|
public function getPlatform() |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->platform; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Authenticates the request |
|
84
|
|
|
* @return boolean |
|
85
|
|
|
*/ |
|
86
|
|
|
public function authenticate() |
|
|
|
|
|
|
87
|
|
|
{ |
|
88
|
|
|
$hmac = $this->getRest()->getServer()->getHmac(); |
|
89
|
|
|
$data = array_merge($this->getRequestHeaders(true), $this->getBodyData()); |
|
90
|
|
|
$auth = $hmac->setData($data) |
|
91
|
|
|
->setRoute($this->getPlatform()->getPost('api_method')) |
|
92
|
|
|
->setMethod($_SERVER['REQUEST_METHOD']) |
|
93
|
|
|
->auth($this->settings['api_key'], $this->settings['api_secret']); |
|
|
|
|
|
|
94
|
|
|
|
|
95
|
|
|
if(!$auth) { |
|
96
|
|
|
return false; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
return true; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Returns the input data as an array |
|
104
|
|
|
* @return array |
|
105
|
|
|
*/ |
|
106
|
|
|
public function getBodyData() |
|
107
|
|
|
{ |
|
108
|
|
|
if(is_null($this->body_data)) |
|
109
|
|
|
{ |
|
110
|
|
|
$data = json_decode(file_get_contents("php://input"), true); |
|
111
|
|
|
if(!$data) |
|
112
|
|
|
{ |
|
113
|
|
|
$data = array(); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
$this->body_data = $data; |
|
|
|
|
|
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
return $this->body_data; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* Returns an associative array of the request headers |
|
124
|
|
|
* @return multitype:unknown |
|
|
|
|
|
|
125
|
|
|
*/ |
|
126
|
|
|
public function getRequestHeaders($auth = true) |
|
127
|
|
|
{ |
|
128
|
|
|
$headers = \getallheaders(); |
|
129
|
|
|
if($auth) { |
|
130
|
|
|
$hmac = $this->getRest()->getServer()->getHmac(); |
|
131
|
|
|
$return = array( |
|
132
|
|
|
$hmac->getPrefix().'timestamp' => (isset($headers[$hmac->getPrefix().'timestamp']) ? $headers[$hmac->getPrefix().'timestamp'] : ''), |
|
133
|
|
|
$hmac->getPrefix().'signature' => (isset($headers[$hmac->getPrefix().'signature']) ? $headers[$hmac->getPrefix().'signature'] : ''), |
|
134
|
|
|
$hmac->getPrefix().'key' => (isset($headers[$hmac->getPrefix().'key']) ? $headers[$hmac->getPrefix().'key'] : ''), |
|
135
|
|
|
$hmac->getPrefix().'version' => (isset($headers[$hmac->getPrefix().'version']) ? $headers[$hmac->getPrefix().'version'] : ''), |
|
136
|
|
|
); |
|
137
|
|
|
$headers = $return; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
return $headers; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* Handy little method to disable unused HTTP verb methods |
|
145
|
|
|
* |
|
146
|
|
|
* @return ApiProblem |
|
147
|
|
|
*/ |
|
148
|
|
|
protected function methodNotAllowed() |
|
149
|
|
|
{ |
|
150
|
|
|
return $this->view_helper->renderError(405, 'method_not_allowed'); |
|
|
|
|
|
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
public function options($id = false) |
|
|
|
|
|
|
154
|
|
|
{ |
|
155
|
|
|
return; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
public function post() |
|
159
|
|
|
{ |
|
160
|
|
|
return $this->methodNotAllowed(); |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
public function create() |
|
164
|
|
|
{ |
|
165
|
|
|
return $this->methodNotAllowed(); |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
public function delete($id = false) |
|
|
|
|
|
|
169
|
|
|
{ |
|
170
|
|
|
return $this->methodNotAllowed(); |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
public function get($id = false) |
|
|
|
|
|
|
174
|
|
|
{ |
|
175
|
|
|
return $this->methodNotAllowed(); |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
public function head($id = null) |
|
|
|
|
|
|
179
|
|
|
{ |
|
180
|
|
|
return $this->methodNotAllowed(); |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
public function patch($id) |
|
|
|
|
|
|
184
|
|
|
{ |
|
185
|
|
|
return $this->methodNotAllowed(); |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
public function put($id = false) |
|
|
|
|
|
|
189
|
|
|
{ |
|
190
|
|
|
return $this->methodNotAllowed(); |
|
191
|
|
|
} |
|
192
|
|
|
} |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..