_controller = $controller; $this->_ci = $ci; } /** * Steps: * 1.Get authorization header * 2.Validate it * 3.Check if it matches role * 4.Return error if not match * * @return void */ public function run() { $condition = in_array($this->_controller->get_role_id(), $this->_controller->get_valid_role()); if (!$condition) { $this->unauthorize_resource_error_message(); return FALSE; } return TRUE; } private function unauthorize_resource_error_message() { http_response_code(406); echo json_encode([ 'code' => 406, 'success' => FALSE, 'message' => 'cannot access resource' ]); stop_execution(); } }