Example #1
0
 /**
  *  Constructor - Called on each request.
  */
 public static function construct($class = null, $method = null)
 {
     // Get full urls to current controller and its method
     $site_url = Router::siteUrl();
     self::$method_url = $site_url . Router::$method_url . '/';
     self::$controller_url = dirname(self::$method_url) . '/';
     self::$module_url = dirname(self::$controller_url) . '/';
     // Pass these to the view, too
     Load::$config['view_data']['module_url'] = self::$module_url;
     Load::$config['view_data']['controller_url'] = self::$controller_url;
     Load::$config['view_data']['method_url'] = self::$method_url;
     // Add Router's preferences
     Load::$config['view_data']['module'] = Router::$module;
     Load::$config['view_data']['controller'] = Router::$controller;
     Load::$config['view_data']['class'] = Router::$class;
     Load::$config['view_data']['method'] = Router::$method;
 }
Example #2
0
/**
 * StaticPHP's exception handler.
 *
 * If debug mode is on, sends formatted error to browser, otherwise sends error email, if debug email is provided in <i>Config/Config.php</i> file.
 *
 * @access public
 * @param Exception|ErrorException|mixed $exception
 * @return void
 */
function sp_exception_handler($exception)
{
    if ($exception instanceof RouterException) {
        if (!empty(Load::$config['debug'])) {
            Router::error('500', 'Internal Server Error', $exception->getMessage());
        } else {
            Router::error('404', 'Not Found');
        }
    }
    if (function_exists('http_response_code') && headers_sent() === false) {
        http_response_code(500);
    }
    if (!empty(Load::$config['debug'])) {
        echo sp_format_exception($exception);
    } else {
        sp_send_error_email($exception);
    }
}