Skip to content

Commit 3a39061

Browse files
author
Phil Sturgeon
committed
Uniformed some code and chsnges statuc => 0 to status => false (XML can handle boolean nicely now).
1 parent 2fdb704 commit 3a39061

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

application/libraries/REST_Controller.php

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ public function __construct()
3737
$this->request->method = $this->_detect_method();
3838

3939
$this->load->library('security');
40-
41-
// Check if there is a specific auth type for the current class/method
40+
41+
// Check if there is a specific auth type for the current class/method
4242
$this->auth_override = $this->_auth_override_check();
43-
43+
4444
// When there is no specific override for the current class/method, use the default auth value set in the config
4545
if ( $this->auth_override !== TRUE )
46-
{
46+
{
4747
if ($this->config->item('rest_auth') == 'basic')
4848
{
4949
$this->_prepare_basic_auth();
@@ -132,14 +132,14 @@ public function _remap($object_called)
132132
// Get that useless shitty key out of here
133133
if (config_item('rest_enable_keys') AND $use_key AND $this->_allow === FALSE)
134134
{
135-
$this->response(array('status' => 0, 'error' => 'Invalid API Key.'), 403);
135+
$this->response(array('status' => false, 'error' => 'Invalid API Key.'), 403);
136136
return;
137137
}
138138

139139
// Sure it exists, but can they do anything with it?
140140
if (!method_exists($this, $controller_method))
141141
{
142-
$this->response(array('status' => 0, 'error' => 'Unknown method.'), 404);
142+
$this->response(array('status' => false, 'error' => 'Unknown method.'), 404);
143143
return;
144144
}
145145

@@ -149,7 +149,7 @@ public function _remap($object_called)
149149
// Check the limit
150150
if (config_item('rest_enable_limits') AND !$this->_check_limit($controller_method))
151151
{
152-
$this->response(array('status' => 0, 'error' => 'This API key has reached the hourly limit for this method.'), 401);
152+
$this->response(array('status' => false, 'error' => 'This API key has reached the hourly limit for this method.'), 401);
153153
return;
154154
}
155155

@@ -168,7 +168,7 @@ public function _remap($object_called)
168168
// They don't have good enough perms
169169
if (!$authorized)
170170
{
171-
$this->response(array('status' => 0, 'error' => 'This API key does not have enough permissions.'), 401);
171+
$this->response(array('status' => false, 'error' => 'This API key does not have enough permissions.'), 401);
172172
return;
173173
}
174174
}
@@ -339,7 +339,7 @@ private function _detect_api_key()
339339
// Find the key from server or arguments
340340
if ($key = isset($this->_args['API-Key']) ? $this->_args['API-Key'] : $this->input->server($key_name))
341341
{
342-
if (!$row = $this->rest->db->where('key', $key)->get(config_item('rest_keys_table'))->row())
342+
if ( ! $row = $this->rest->db->where('key', $key)->get(config_item('rest_keys_table'))->row())
343343
{
344344
return FALSE;
345345
}
@@ -363,7 +363,7 @@ private function _detect_api_key()
363363

364364
private function _detect_lang()
365365
{
366-
if (!$lang = $this->input->server('HTTP_ACCEPT_LANGUAGE'))
366+
if ( ! $lang = $this->input->server('HTTP_ACCEPT_LANGUAGE'))
367367
{
368368
return NULL;
369369
}
@@ -467,31 +467,31 @@ private function _check_limit($controller_method)
467467
* Auth override check
468468
*
469469
* Check if there is a specific auth type set for the current class/method being called
470-
*/
471-
472-
private function _auth_override_check()
470+
*/
471+
472+
private function _auth_override_check()
473473
{
474-
474+
475475
// Assign the class/method auth type override array from the config
476-
$this->overrides_array = $this->config->item('auth_override_class_method');
477-
476+
$this->overrides_array = $this->config->item('auth_override_class_method');
477+
478478
// Check to see if the override array is even populated, otherwise return false
479-
if ( empty($this->overrides_array) )
480-
{
479+
if ( empty($this->overrides_array) )
480+
{
481481
return false;
482482
}
483-
484-
// Check to see if there's an override value set for the current class/method being called
483+
484+
// Check to see if there's an override value set for the current class/method being called
485485
if ( empty($this->overrides_array[$this->router->class][$this->router->method]) )
486486
{
487487
return false;
488488
}
489489

490-
// None auth override found, prepare nothing but send back a true override flag
490+
// None auth override found, prepare nothing but send back a true override flag
491491
if ($this->overrides_array[$this->router->class][$this->router->method] == 'none')
492492
{
493493
return true;
494-
}
494+
}
495495

496496
// Basic auth override found, prepare basic
497497
if ($this->overrides_array[$this->router->class][$this->router->method] == 'basic')
@@ -509,9 +509,9 @@ private function _auth_override_check()
509509

510510
// Return false when there is an override value set but it doesn't match 'basic', 'digest', or 'none'. (the value was misspelled)
511511
return false;
512-
512+
513513
}
514-
514+
515515

516516
// INPUT FUNCTION --------------------------------------------------------------
517517

@@ -891,5 +891,4 @@ private function _format_php($data = array())
891891
{
892892
return var_export($data, TRUE);
893893
}
894-
895894
}

0 commit comments

Comments
 (0)