/** * @param $model * @param $action * @param $params * * @return string */ public static function run($model, $action, $params) { // Set up an independent AJAX error handler set_error_handler(array('RokCommon_Ajax', 'error_handler')); set_exception_handler(array('RokCommon_Ajax', 'exception_handler')); while (@ob_end_clean()) { } // clean any pending output buffers ob_start(); // start a fresh one $result = null; try { /** @var RokCommon_Ajax_ModelLoader $ajaxModelLoader */ $ajaxModelLoader = RokCommon_ClassLoader::getLoader('AjaxModels'); // get a model class instance $modelInstance = $ajaxModelLoader->getModel($model); $decoded_params = json_decode($params); if (null == $decoded_params && strlen($params) > 0) { throw new RokCommon_Ajax_Exception('Invalid JSON for params'); } // set the result to the run $result = $modelInstance->run($action, $decoded_params); } catch (Exception $ae) { $result = new RokCommon_Ajax_Result(); $result->setAsError(); $result->setMessage($ae->getMessage()); } $encoded_result = json_encode($result); // restore normal error handling; restore_error_handler(); restore_exception_handler(); return $encoded_result; }
/** * @static * @return RokCommon_Loader */ public static function getInstance() { return RokCommon_ClassLoader::getLoader(self::NAME); }