$controller_file = ucfirst(strtolower($params->controller)); //check if the controller exists. if not, throw an exception if (file_exists(dirname(__FILE__) . "/controllers/{$controller_file}.php")) { require dirname(__FILE__) . "/controllers/{$controller_file}.php"; } else { $Response->throw_exception(400, 'invalid controller'); } //create a new instance of the controller, and pass //it the parameters from the request and Database object $controller = new $controller($Database, $Tools, $params, $Response); //check if the action exists in the controller. if not, throw an exception. if (method_exists($controller, strtolower($_SERVER['REQUEST_METHOD'])) === false) { $Response->throw_exception(501, $Response->errors[501]); } //execute the action $result = $controller->{$_SERVER}['REQUEST_METHOD'](); } catch (Exception $e) { //catch any exceptions and report the problem $result = $e->getMessage(); //set flag if it came from Result, just to be sure if ($Response->exception !== true) { $Response->exception = true; $Response->result['success'] = false; $Response->result['code'] = 500; $Response->result['message'] = $result; } } //output result echo $Response->formulate_result($result); // exit exit;
$controller->remove_transaction_lock(); } } } catch (Exception $e) { // catch any exceptions and report the problem $result = $e->getMessage(); $Response->result['success'] = 0; // set flag if it came from Result, just to be sure if ($Response->exception !== true) { $Response->exception = true; $Response->result['success'] = 0; $Response->result['code'] = 500; $Response->result['message'] = $result; } // remove transaction lock if (is_object($controller) && $app->app_lock == 1 && strtoupper($_SERVER['REQUEST_METHOD']) == "POST") { if ($controller->is_transaction_locked()) { $controller->remove_transaction_lock(); } } } // stop measuring $stop = microtime(true); // add stop time if ($time_response) { $time = $stop - $start; } //output result echo $Response->formulate_result($result, $time); // exit exit;