Skip to content

Commit 7dc9248

Browse files
committed
Refactor 3party rest
1 parent 23950cb commit 7dc9248

File tree

3 files changed

+17
-20
lines changed

3 files changed

+17
-20
lines changed

thirdParty/REST/Format.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ public function to_json($data = null)
383383
if (empty($callback) === true) {
384384
return json_encode($data, JSON_UNESCAPED_UNICODE);
385385
} // We only honour a jsonp callback which are valid javascript identifiers
386-
elseif (preg_match('/^[a-z_\$][a-z0-9\$_]*(\.[a-z_\$][a-z0-9\$_]*)*$/i', $callback)) {
386+
if (preg_match('/^[a-z_\$][a-z0-9\$_]*(\.[a-z_\$][a-z0-9\$_]*)*$/i', $callback)) {
387387
// Return the data as encoded json with a callback
388388
return $callback . '(' . json_encode($data, JSON_UNESCAPED_UNICODE) . ');';
389389
}

thirdParty/REST/Request.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function getBodyParams()
9696

9797
$contentType = $this->getContentType();
9898

99-
if (strcasecmp($contentType, 'application/json') == 0) {
99+
if (strcasecmp($contentType, 'application/json') === 0) {
100100
// JSON content type
101101
$this->_bodyParams = json_decode($this->getRawBody(), true);
102102
} elseif ($this->getMethod() === 'POST') {
@@ -131,7 +131,7 @@ public function input()
131131
*/
132132
public function getAuthCredentialsWithBasic()
133133
{
134-
if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
134+
if (isset($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])) {
135135

136136
return [$_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']];
137137
}
@@ -166,12 +166,9 @@ public function getAuthCredentialsWithBearer()
166166
{
167167
$b64token = null;
168168

169-
if (isset($_SERVER['HTTP_AUTHORIZATION'])) {
169+
if (isset($_SERVER['HTTP_AUTHORIZATION']) && strpos(bear_str_to_lower($_SERVER['HTTP_AUTHORIZATION']), 'bearer ') === 0) {
170170

171-
if (strpos(bear_str_to_lower($_SERVER['HTTP_AUTHORIZATION']), 'bearer ') === 0) {
172-
173-
$b64token = substr($_SERVER['HTTP_AUTHORIZATION'], 7);
174-
}
171+
$b64token = substr($_SERVER['HTTP_AUTHORIZATION'], 7);
175172
}
176173

177174
return $b64token;

thirdParty/REST/Response.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function __construct()
8787
/**
8888
* Set Response Format into CI_Output
8989
*
90-
* @param string Response format
90+
* @param string $format Response format
9191
*/
9292
public function setFormat($format)
9393
{
@@ -105,7 +105,7 @@ public function setFormat($format)
105105
*
106106
* @todo Format data before send
107107
*
108-
* @param mixed Response data
108+
* @param mixed $data Response data
109109
*
110110
* @return object self
111111
*/
@@ -189,10 +189,10 @@ public function send()
189189
}
190190

191191
/**
192-
* Common format funciton by format types. {FORMAT}Format()
192+
* Common format function by format types. {FORMAT}Format()
193193
*
194-
* @param array Pre-handle array data
195-
* @param string Format
194+
* @param array $data Pre-handle array data
195+
* @param string $format Format
196196
*
197197
* @return string Formatted data by specified formatter
198198
*/
@@ -207,16 +207,16 @@ public function format($data, $format)
207207
$data = $this->{$formatFunc}($data);
208208
} elseif (is_array($data)) {
209209
// Use JSON while the Formatter not found and the data is array
210-
$data = $this->formatJson($data);
210+
$data = self::formatJson($data);
211211
}
212212

213213
return $data;
214214
}
215215

216216
/**
217-
* Common format funciton by format types. {FORMAT}Format()
217+
* Common format function by format types. {FORMAT}Format()
218218
*
219-
* @param array Pre-handle array data
219+
* @param array $data Pre-handle array data
220220
*
221221
* @return string Formatted data
222222
*/
@@ -228,10 +228,10 @@ public static function formatJson($data)
228228
/**
229229
* JSON output shortcut
230230
*
231-
* @param array|mixed Callback data body, false will remove body key
232-
* @param int Callback status code
231+
* @param array|mixed $data Callback data body, false will remove body key
232+
* @param int $statusCode Callback status code
233233
*
234-
* @return string Response body data
234+
* @return string|void Response body data
235235
* @throws \Exception
236236
*/
237237
public function json($data, $statusCode = null)
@@ -241,7 +241,7 @@ public function json($data, $statusCode = null)
241241
$this->setStatusCode($statusCode);
242242
}
243243

244-
$this->setFormat(Response::FORMAT_JSON);
244+
$this->setFormat(self::FORMAT_JSON);
245245

246246
if (!is_null($data)) {
247247
$this->setData($data);

0 commit comments

Comments
 (0)