@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | |
26 | 26 | private function getUserFromSession() |
27 | 27 | { |
28 | - if(FlipSession::isLoggedIn()) |
|
28 | + if (FlipSession::isLoggedIn()) |
|
29 | 29 | { |
30 | 30 | return FlipSession::getUser(); |
31 | 31 | } |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | $auth = \AuthProvider::getInstance(); |
42 | 42 | $auth->login($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']); |
43 | 43 | $user = FlipSession::getUser(); |
44 | - if($user === false) |
|
44 | + if ($user === false) |
|
45 | 45 | { |
46 | 46 | $data = substr($header['Authorization'], 6); |
47 | 47 | $userpass = explode(':', base64_decode($data)); |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | |
63 | 63 | private function getUserFromHeader($header) |
64 | 64 | { |
65 | - if(strncmp($header, 'Basic', 5) == 0) |
|
65 | + if (strncmp($header, 'Basic', 5) == 0) |
|
66 | 66 | { |
67 | 67 | return $this->getUserFromBasicAuth($header); |
68 | 68 | } |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | public function call() |
73 | 73 | { |
74 | 74 | // no auth header |
75 | - if(!isset($this->headers['Authorization'])) |
|
75 | + if (!isset($this->headers['Authorization'])) |
|
76 | 76 | { |
77 | 77 | $this->app->user = $this->getUserFromSession(); |
78 | 78 | } |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | $this->app->user = $this->getUserFromHeader($header); |
83 | 83 | } |
84 | 84 | |
85 | - if($this->app->user === false) |
|
85 | + if ($this->app->user === false) |
|
86 | 86 | { |
87 | 87 | $this->app->getLog()->error("No user found for call"); |
88 | 88 | } |
@@ -96,19 +96,19 @@ discard block |
||
96 | 96 | { |
97 | 97 | private function fix_encoded_element($key, $value, &$array, $prefix = '') |
98 | 98 | { |
99 | - if(is_array($value)) |
|
99 | + if (is_array($value)) |
|
100 | 100 | { |
101 | 101 | $array[$key] = implode(';', $value); |
102 | 102 | } |
103 | - else if($key === '_id' && is_object($value)) |
|
103 | + else if ($key === '_id' && is_object($value)) |
|
104 | 104 | { |
105 | 105 | $array[$key] = $value->{'$id'}; |
106 | 106 | } |
107 | - else if(is_object($value)) |
|
107 | + else if (is_object($value)) |
|
108 | 108 | { |
109 | 109 | $array[$key] = $this->app->request->getUrl().$this->app->request->getPath().$prefix.'/'.$key; |
110 | 110 | } |
111 | - else if(strncmp($value, 'data:', 5) === 0) |
|
111 | + else if (strncmp($value, 'data:', 5) === 0) |
|
112 | 112 | { |
113 | 113 | $array[$key] = $this->app->request->getUrl().$this->app->request->getPath().$prefix.'/'.$key; |
114 | 114 | } |
@@ -122,40 +122,40 @@ discard block |
||
122 | 122 | } |
123 | 123 | ob_start(); |
124 | 124 | $df = fopen("php://output", 'w'); |
125 | - if(is_array($array)) |
|
125 | + if (is_array($array)) |
|
126 | 126 | { |
127 | 127 | $first = reset($array); |
128 | 128 | $keys = FALSE; |
129 | - if(is_array($first)) |
|
129 | + if (is_array($first)) |
|
130 | 130 | { |
131 | 131 | $keys = array_keys($first); |
132 | 132 | } |
133 | - else if(is_object($first)) |
|
133 | + else if (is_object($first)) |
|
134 | 134 | { |
135 | 135 | $keys = array_keys(get_object_vars($first)); |
136 | 136 | } |
137 | 137 | fputcsv($df, $keys); |
138 | 138 | foreach ($array as $row) |
139 | 139 | { |
140 | - if(is_array($row)) |
|
140 | + if (is_array($row)) |
|
141 | 141 | { |
142 | 142 | $id = $row[$keys[0]]; |
143 | - foreach($row as $key=>$value) |
|
143 | + foreach ($row as $key=>$value) |
|
144 | 144 | { |
145 | 145 | $this->fix_encoded_element($key, $value, $row, '/'.$id); |
146 | 146 | } |
147 | 147 | fputcsv($df, $row); |
148 | 148 | } |
149 | - else if(is_object($row)) |
|
149 | + else if (is_object($row)) |
|
150 | 150 | { |
151 | 151 | $keyName = $keys[0]; |
152 | 152 | $id = $row->$keyName; |
153 | - if(is_object($id)) |
|
153 | + if (is_object($id)) |
|
154 | 154 | { |
155 | 155 | $id = $id->{'$id'}; |
156 | 156 | } |
157 | 157 | $values = get_object_vars($row); |
158 | - foreach($values as $key=>$value) |
|
158 | + foreach ($values as $key=>$value) |
|
159 | 159 | { |
160 | 160 | $this->fix_encoded_element($key, $value, $values, '/'.$id); |
161 | 161 | } |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | { |
168 | 168 | $array = get_object_vars($array); |
169 | 169 | fputcsv($df, array_keys($array)); |
170 | - foreach($array as $key=>$value) |
|
170 | + foreach ($array as $key=>$value) |
|
171 | 171 | { |
172 | 172 | $this->fix_encoded_element($key, $value, $array); |
173 | 173 | } |
@@ -185,34 +185,34 @@ discard block |
||
185 | 185 | |
186 | 186 | public function call() |
187 | 187 | { |
188 | - if($this->app->request->isOptions()) |
|
188 | + if ($this->app->request->isOptions()) |
|
189 | 189 | { |
190 | 190 | return; |
191 | 191 | } |
192 | 192 | $params = $this->app->request->params(); |
193 | 193 | $fmt = null; |
194 | - if(isset($params['fmt'])) |
|
194 | + if (isset($params['fmt'])) |
|
195 | 195 | { |
196 | 196 | $fmt = $params['fmt']; |
197 | 197 | } |
198 | - if($fmt === null && isset($params['$format'])) |
|
198 | + if ($fmt === null && isset($params['$format'])) |
|
199 | 199 | { |
200 | 200 | $fmt = $params['$format']; |
201 | - if(strstr($fmt, 'odata.streaming=true')) |
|
201 | + if (strstr($fmt, 'odata.streaming=true')) |
|
202 | 202 | { |
203 | 203 | $this->app->response->setStatus(406); |
204 | 204 | return; |
205 | 205 | } |
206 | 206 | } |
207 | - if($fmt === null) |
|
207 | + if ($fmt === null) |
|
208 | 208 | { |
209 | 209 | $mimeType = $this->app->request->headers->get('Accept'); |
210 | - if(strstr($mimeType, 'odata.streaming=true')) |
|
210 | + if (strstr($mimeType, 'odata.streaming=true')) |
|
211 | 211 | { |
212 | 212 | $this->app->response->setStatus(406); |
213 | 213 | return; |
214 | 214 | } |
215 | - switch($mimeType) |
|
215 | + switch ($mimeType) |
|
216 | 216 | { |
217 | 217 | case 'text/csv': |
218 | 218 | $fmt = 'csv'; |
@@ -232,11 +232,11 @@ discard block |
||
232 | 232 | |
233 | 233 | $this->next->call(); |
234 | 234 | |
235 | - if($this->app->response->getStatus() == 200 && $this->app->fmt !== 'json') |
|
235 | + if ($this->app->response->getStatus() == 200 && $this->app->fmt !== 'json') |
|
236 | 236 | { |
237 | 237 | $data = json_decode($this->app->response->getBody()); |
238 | 238 | $text = false; |
239 | - switch($this->app->fmt) |
|
239 | + switch ($this->app->fmt) |
|
240 | 240 | { |
241 | 241 | case 'data-table': |
242 | 242 | $this->app->response->headers->set('Content-Type', 'application/json'); |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | } |
264 | 264 | $this->app->response->setBody($text); |
265 | 265 | } |
266 | - else if($this->app->response->getStatus() == 200) |
|
266 | + else if ($this->app->response->getStatus() == 200) |
|
267 | 267 | { |
268 | 268 | $this->app->response->headers->set('Content-Type', 'application/json;odata.metadata=none'); |
269 | 269 | } |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | parent::__construct(); |
278 | 278 | $this->config('debug', false); |
279 | 279 | $headers = array(); |
280 | - if(php_sapi_name() !== "cli") |
|
280 | + if (php_sapi_name() !== "cli") |
|
281 | 281 | { |
282 | 282 | $headers = apache_request_headers(); |
283 | 283 | } |
@@ -297,12 +297,12 @@ discard block |
||
297 | 297 | return $this->post($uri, $handler); |
298 | 298 | } |
299 | 299 | |
300 | - function get_json_body($array=false) |
|
300 | + function get_json_body($array = false) |
|
301 | 301 | { |
302 | 302 | return $this->getJsonBody($array); |
303 | 303 | } |
304 | 304 | |
305 | - function getJsonBody($array=false) |
|
305 | + function getJsonBody($array = false) |
|
306 | 306 | { |
307 | 307 | $body = $this->request->getBody(); |
308 | 308 | return json_decode($body, $array); |