Example #1
0
 /**
  * This function get's called via register_shutdown_function when the script finishes or exit is called
  */
 public static function finish()
 {
     if (self::$init) {
         Hook::run('finish', 'pre');
         $_SESSION['error'] = Backend::getError();
         $_SESSION['notice'] = Backend::getNotice();
         $_SESSION['success'] = Backend::getSuccess();
         if (!empty(self::$view)) {
             if (empty($_SESSION['previous_url']) || !is_array($_SESSION['previous_url'])) {
                 $_SESSION['previous_url'] = array();
             }
             if (array_key_exists('REQUEST_URI', $_SERVER)) {
                 $_SESSION['previous_url'][self::$view->mode] = $_SERVER['REQUEST_URI'];
             }
             if (empty($_SESSION['previous_area']) || !is_array($_SESSION['previous_area'])) {
                 $_SESSION['previous_area'] = array();
             }
             $_SESSION['previous_area'][self::$view->mode] = self::$area;
             if (empty($_SESSION['previous_action']) || !is_array($_SESSION['previous_action'])) {
                 $_SESSION['previous_action'] = array();
             }
             $_SESSION['previous_action'][self::$view->mode] = self::$action;
             if (empty($_SESSION['previous_parameters']) || !is_array($_SESSION['previous_parameters'])) {
                 $_SESSION['previous_parameters'] = array();
             }
             $_SESSION['previous_parameters'][self::$view->mode] = self::$parameters;
         }
         //Check if we encountered a fatal error
         if ($last_error = error_get_last()) {
             if ($last_error['type'] === E_ERROR && SITE_STATE == 'production') {
                 $id = send_email(ConfigValue::get('author.Email', ConfigValue::get('Email', 'info@' . SITE_DOMAIN)), 'Fatal PHP Error in ' . ConfigValue::get('Title', 'Application'), 'Error: ' . var_export($last_error, true) . PHP_EOL . 'Query: ' . self::$query_string . PHP_EOL . 'Payload: ' . var_export(self::$payload, true));
             }
         }
         //Clean up
         self::$query_string = false;
         self::$query_vars = array();
         self::$method = null;
         self::$payload = false;
         self::$area = 'home';
         self::$action = 'index';
         self::$parameters = array();
         self::$salt = false;
         self::$view = false;
         self::$started = false;
         self::$init = false;
         self::$firephp = false;
         self::$whoopsed = false;
         Backend::shutdown();
         Hook::run('finish', 'post');
         while (ob_get_level() > self::$ob_level) {
             ob_end_flush();
         }
     }
     self::$init = false;
 }