/** * This would process error message sent from frontend */ public function action_index() { $input = request::input(); if (!empty($input['token'])) { $crypt = new crypt(); $token_data = $crypt->token_validate($input['token'], ['skip_time_validation' => true]); if (!($token_data === false || $token_data['id'] !== 'general')) { $input['data'] = json_decode($input['data'], true); error_base::error_handler('javascript', $input['data']['message'], $input['data']['file'], $input['data']['line']); } } // rendering layout::render_as(file_get_contents(__DIR__ . '/error.png'), 'image/png'); }
/** * Destroy everything */ public static function destroy() { $__run_only_bootstrap = application::get(['flag', 'global', '__run_only_bootstrap']); // we need to set working directory again chdir(application::get(['application', 'path_full'])); // error processing if (empty(error_base::$flag_error_already)) { $last_error = error_get_last(); $flag_render = false; if (in_array($last_error['type'], [E_COMPILE_ERROR, E_PARSE, E_ERROR])) { error_base::error_handler($last_error['type'], $last_error['message'], $last_error['file'], $last_error['line']); error_base::$flag_error_already = true; $flag_render = true; } if ($flag_render || error_base::$flag_exception) { error_base::$flag_error_already = true; if ($__run_only_bootstrap) { helper_ob::clean_all(); print_r(error_base::$errors); } else { // set mvc + process application::set_mvc('/error/_error/500'); application::process(); } } } // write sessions session_write_close(); // final benchmark if (debug::$debug) { debug::benchmark('application end'); } // debugging toolbar last if (debug::$toolbar && !$__run_only_bootstrap) { echo str_replace('<!-- [numbers: debug toolbar] -->', debug::render(), helper_ob::clean()); } // flush data to client flush(); // closing caches before db $cache = factory::get(['cache']); if (!empty($cache)) { foreach ($cache as $k => $v) { $object = $v['object']; if (!empty(cache::$reset_caches[$k])) { $object->gc(1, cache::$reset_caches[$k]); } $object->close(); } } // destroy i18n if (i18n::$initialized) { i18n::destroy(); } // close db connections $dbs = factory::get(['db']); if (!empty($dbs)) { foreach ($dbs as $k => $v) { $object = $v['object']; $object->close(); } } // emails with erros if (debug::$debug && !empty(debug::$email)) { debug::send_errors_to_admin(); } }