@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | * @param string $apiKey [description] |
95 | 95 | * @return array [description] |
96 | 96 | */ |
97 | - public function getAPIKeyData(string $apiKey):?array { |
|
97 | + public function getAPIKeyData(string $apiKey): ?array { |
|
98 | 98 | // Preliminary Check. |
99 | 99 | if ($this->api_key_table == null || $this->api_key_column == null) return null; |
100 | 100 | // Query. |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | * @param string $group [description] |
121 | 121 | * @return [type] [description] |
122 | 122 | */ |
123 | - public function getLimitData(string $client, string $group):?array { |
|
123 | + public function getLimitData(string $client, string $group): ?array { |
|
124 | 124 | $sql = 'SELECT count, start, (`start` + INTERVAL (1 - TIMESTAMPDIFF(HOUR, UTC_TIMESTAMP(), NOW())) HOUR) AS reset_epoch FROM rest_api_rate_limit WHERE client = ? AND _group = ?'; |
125 | 125 | $query = $this->db->query($sql, [$client, $group]); |
126 | 126 | if ($query->num_rows() > 0) return $query->result_array()[0]; |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | * [PACKAGE description] |
79 | 79 | * @var string |
80 | 80 | */ |
81 | - const PACKAGE = "francis94c/ci-rest"; |
|
81 | + const PACKAGE = "francis94c/ci-rest"; |
|
82 | 82 | /** |
83 | 83 | * [RATE_LIMIT description] |
84 | 84 | * @var string |
@@ -89,15 +89,15 @@ discard block |
||
89 | 89 | * [__construct description] |
90 | 90 | * @param [type] $params [description] |
91 | 91 | */ |
92 | - function __construct($params=null) { |
|
93 | - $this->ci =& get_instance(); |
|
92 | + function __construct($params = null) { |
|
93 | + $this->ci = & get_instance(); |
|
94 | 94 | // Load Config If Exists. |
95 | 95 | $this->ci->config->load('rest', true, true); |
96 | 96 | // Load Database. |
97 | 97 | $this->ci->load->database(); |
98 | 98 | // Load Model. |
99 | 99 | $this->ci->load->splint(self::PACKAGE, '*RESTModel', 'rest_model'); |
100 | - $this->rest_model =& $this->ci->rest_model; |
|
100 | + $this->rest_model = & $this->ci->rest_model; |
|
101 | 101 | $config = [ |
102 | 102 | 'users_table' => $this->ci->config->item('rest')['basic_auth']['users_table'] ?? null, |
103 | 103 | 'users_id_column' => $this->ci->config->item('rest')['basic_auth']['id_column'] ?? null, |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | /** |
177 | 177 | * [bearer_auth description] |
178 | 178 | */ |
179 | - private function bearer_auth($auth=RESTAuth::BEARER):void { |
|
179 | + private function bearer_auth($auth = RESTAuth::BEARER):void { |
|
180 | 180 | $authorization = $this->get_authorization_header(); |
181 | 181 | if ($authorization == null || substr_count($authorization, " ") != 1) { |
182 | 182 | $this->handle_response(RESTResponse::BAD_REQUEST, $auth); // Exits. |
@@ -209,11 +209,11 @@ discard block |
||
209 | 209 | * [api_key_auth description] |
210 | 210 | */ |
211 | 211 | private function api_key_auth():void { |
212 | - if (!isset($_SERVER['HTTP_' . str_replace("-", "_", $this->apiKeyHeader)])) { |
|
212 | + if (!isset($_SERVER['HTTP_'.str_replace("-", "_", $this->apiKeyHeader)])) { |
|
213 | 213 | $this->handle_response(RESTResponse::BAD_REQUEST, RESTAuth::API_KEY); // Exits. |
214 | 214 | } |
215 | 215 | $apiKey = $this->rest_model->getAPIKeyData( |
216 | - $_SERVER['HTTP_' . str_replace("-", "_", $this->apiKeyHeader)] |
|
216 | + $_SERVER['HTTP_'.str_replace("-", "_", $this->apiKeyHeader)] |
|
217 | 217 | ); |
218 | 218 | if ($apiKey == null) { |
219 | 219 | $this->handle_response(RESTResponse::UN_AUTHORIZED, RESTAuth::API_KEY); // Exits. |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | } |
230 | 230 | // Should we acyually Limit? |
231 | 231 | if ($this->per_hour > 0) { |
232 | - $client = hash('md5', $this->ci->input->ip_address() . "%" . $apiKey[$this->api_key_column]); |
|
232 | + $client = hash('md5', $this->ci->input->ip_address()."%".$apiKey[$this->api_key_column]); |
|
233 | 233 | $limitData = $this->rest_model->getLimitData($client, '_api_keyed_user'); |
234 | 234 | if ($limitData == null) { |
235 | 235 | $limitData = []; |
@@ -312,7 +312,7 @@ discard block |
||
312 | 312 | * [get_authorization_header description] |
313 | 313 | * @return [type] [description] |
314 | 314 | */ |
315 | - private function get_authorization_header():?string { |
|
315 | + private function get_authorization_header(): ?string { |
|
316 | 316 | if (isset($_SERVER['Authorization'])) { |
317 | 317 | return trim($_SERVER["Authorization"]); |
318 | 318 | } else if (isset($_SERVER['HTTP_AUTHORIZATION'])) { //Nginx or fast CGI |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | * [handle_response description] |
334 | 334 | * @param int $code [description] |
335 | 335 | */ |
336 | - private function handle_response(int $code, $auth=null):void { |
|
336 | + private function handle_response(int $code, $auth = null):void { |
|
337 | 337 | http_response_code($code); |
338 | 338 | header("Content-Type: application/json"); |
339 | 339 | if (isset($this->ci->config->item('rest')['response_callbacks'][$code])) { |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * [BasicAuth description] |
7 | 7 | * @var string |
8 | 8 | */ |
9 | - const BASIC = "Basic"; |
|
9 | + const BASIC = "Basic"; |
|
10 | 10 | /** |
11 | 11 | * [API_KEY description] |
12 | 12 | * @var string |
@@ -16,12 +16,12 @@ discard block |
||
16 | 16 | * [BEARER description] |
17 | 17 | * @var string |
18 | 18 | */ |
19 | - const BEARER = "Bearer"; |
|
19 | + const BEARER = "Bearer"; |
|
20 | 20 | /** |
21 | 21 | * [OAUTH2 description] |
22 | 22 | * @var string |
23 | 23 | */ |
24 | - const OAUTH2 = "OAUTH2"; |
|
24 | + const OAUTH2 = "OAUTH2"; |
|
25 | 25 | /** |
26 | 26 | * [CUSTOM description] |
27 | 27 | * @param string $header [description] |