1111 * @author Phil Sturgeon
1212 * @license http://philsturgeon.co.uk/code/dbad-license
1313 * @link https://github.com/philsturgeon/codeigniter-restserver
14- * @version 2.6
14+ * @version 2.6.0
1515 */
16- class REST_Controller extends MY_Controller
16+ abstract class REST_Controller extends CI_Controller
1717{
1818 /**
1919 * This defines the rest format.
@@ -94,7 +94,13 @@ class REST_Controller extends MY_Controller
9494 * @var boolean
9595 */
9696 protected $ _allow = TRUE ;
97- protected $ _zlib_oc = FALSE ; // Determines if output compression is enabled
97+
98+ /**
99+ * Determines if output compression is enabled
100+ *
101+ * @var boolean
102+ */
103+ protected $ _zlib_oc = FALSE ;
98104
99105 /**
100106 * List all supported methods, the first will be the default format
@@ -103,7 +109,6 @@ class REST_Controller extends MY_Controller
103109 */
104110 protected $ _supported_formats = array (
105111 'xml ' => 'application/xml ' ,
106- 'rawxml ' => 'application/xml ' ,
107112 'json ' => 'application/json ' ,
108113 'jsonp ' => 'application/javascript ' ,
109114 'serialized ' => 'application/vnd.php.serialized ' ,
@@ -248,7 +253,7 @@ public function __construct()
248253 }
249254
250255 // only allow ajax requests
251- if (! $ this ->input ->is_ajax_request () AND config_item ('rest_ajax_only ' ))
256+ if ( ! $ this ->input ->is_ajax_request () AND config_item ('rest_ajax_only ' ))
252257 {
253258 $ this ->response (array ('status ' => false , 'error ' => 'Only AJAX requests are accepted. ' ), 505 );
254259 }
@@ -292,7 +297,7 @@ public function _remap($object_called, $arguments)
292297 }
293298
294299 // Sure it exists, but can they do anything with it?
295- if (! method_exists ($ this , $ controller_method ))
300+ if ( ! method_exists ($ this , $ controller_method ))
296301 {
297302 $ this ->response (array ('status ' => false , 'error ' => 'Unknown method. ' ), 404 );
298303 }
@@ -558,7 +563,6 @@ protected function _detect_method()
558563 */
559564 protected function _detect_api_key ()
560565 {
561-
562566 // Get the api key name variable set in the rest config file
563567 $ api_key_variable = config_item ('rest_key_name ' );
564568
@@ -567,12 +571,13 @@ protected function _detect_api_key()
567571
568572 $ this ->rest ->key = NULL ;
569573 $ this ->rest ->level = NULL ;
574+ $ this ->rest ->user_id = NULL ;
570575 $ this ->rest ->ignore_limits = FALSE ;
571576
572577 // Find the key from server or arguments
573578 if (($ key = isset ($ this ->_args [$ api_key_variable ]) ? $ this ->_args [$ api_key_variable ] : $ this ->input ->server ($ key_name )))
574579 {
575- if (! ($ row = $ this ->rest ->db ->where ('key ' , $ key )->get (config_item ('rest_keys_table ' ))->row ()))
580+ if ( ! ($ row = $ this ->rest ->db ->where ('key ' , $ key )->get (config_item ('rest_keys_table ' ))->row ()))
576581 {
577582 return FALSE ;
578583 }
@@ -599,7 +604,7 @@ protected function _detect_api_key()
599604 */
600605 protected function _detect_lang ()
601606 {
602- if (! $ lang = $ this ->input ->server ('HTTP_ACCEPT_LANGUAGE ' ))
607+ if ( ! $ lang = $ this ->input ->server ('HTTP_ACCEPT_LANGUAGE ' ))
603608 {
604609 return NULL ;
605610 }
@@ -657,7 +662,7 @@ protected function _log_request($authorized = FALSE)
657662 protected function _check_limit ($ controller_method )
658663 {
659664 // They are special, or it might not even have a limit
660- if (! empty ($ this ->rest ->ignore_limits ) OR !isset ($ this ->methods [$ controller_method ]['limit ' ]))
665+ if ( ! empty ($ this ->rest ->ignore_limits ) OR !isset ($ this ->methods [$ controller_method ]['limit ' ]))
661666 {
662667 // On your way sonny-jim.
663668 return TRUE ;
@@ -674,7 +679,7 @@ protected function _check_limit($controller_method)
674679 ->row ();
675680
676681 // No calls yet, or been an hour since they called
677- if (! $ result OR $ result ->hour_started < time () - (60 * 60 ))
682+ if ( ! $ result OR $ result ->hour_started < time () - (60 * 60 ))
678683 {
679684 // Right, set one up from scratch
680685 $ this ->rest ->db ->insert (config_item ('rest_limits_table ' ), array (
@@ -879,7 +884,7 @@ protected function _check_login($username = '', $password = NULL)
879884
880885 $ valid_logins = & $ this ->config ->item ('rest_valid_logins ' );
881886
882- if (! array_key_exists ($ username , $ valid_logins ))
887+ if ( ! array_key_exists ($ username , $ valid_logins ))
883888 {
884889 return FALSE ;
885890 }
@@ -923,7 +928,7 @@ protected function _prepare_basic_auth()
923928 }
924929 }
925930
926- if (! $ this ->_check_login ($ username , $ password ))
931+ if ( ! $ this ->_check_login ($ username , $ password ))
927932 {
928933 $ this ->_force_login ();
929934 }
@@ -967,7 +972,7 @@ protected function _prepare_digest_auth()
967972 preg_match_all ('@(username|nonce|uri|nc|cnonce|qop|response)=[ \'"]?([^ \'",]+)@ ' , $ digest_string , $ matches );
968973 $ digest = array_combine ($ matches [1 ], $ matches [2 ]);
969974
970- if (! array_key_exists ('username ' , $ digest ) OR !$ this ->_check_login ($ digest ['username ' ]))
975+ if ( ! array_key_exists ('username ' , $ digest ) OR !$ this ->_check_login ($ digest ['username ' ]))
971976 {
972977 $ this ->_force_login ($ uniqid );
973978 }
@@ -1002,7 +1007,7 @@ protected function _check_whitelist_auth()
10021007 $ ip = trim ($ ip );
10031008 }
10041009
1005- if (! in_array ($ this ->input ->ip_address (), $ whitelist ))
1010+ if ( ! in_array ($ this ->input ->ip_address (), $ whitelist ))
10061011 {
10071012 $ this ->response (array ('status ' => false , 'error ' => 'Not authorized ' ), 401 );
10081013 }
@@ -1036,7 +1041,7 @@ protected function _force_login($nonce = '')
10361041 protected function _force_loopable ($ data )
10371042 {
10381043 // Force it to be something useful
1039- if (! is_array ($ data ) AND !is_object ($ data ))
1044+ if ( ! is_array ($ data ) AND !is_object ($ data ))
10401045 {
10411046 $ data = (array ) $ data ;
10421047 }
0 commit comments