midcom_exception_handler

Class for intercepting PHP errors and unhandled exceptions. Each fault is caught and converted into Exception handled by midcom_exception_handler::show() with code 500 thus can be customized and make user friendly.

package midcom

 Methods

access_denied (string $message)

This is called by throw new midcom_error_forbidden(.

..) if and only if the headers have not yet been sent. It will display the error message and appends the login form below it.

The function will clear any existing output buffer, and the sent page will have the 403 - Forbidden HTTP Status. The login will relocate to the same URL, so it should be mostly transparent.

The login message shown depends on the current state: - If an authentication attempt was done but failed, an appropriated wrong user/password message is shown. - If the user is authenticated, a note that he might have to switch to a user with more privileges is shown. - Otherwise, no message is shown.

This function will exit() unconditionally.

If the style element midcom_services_auth_access_denied is defined, it will be shown instead of the default error page. The following variables will be available in the local scope:

$title contains the localized title of the page, based on the 'access denied' string ID of the main MidCOM L10n DB. $message will contain the notification what went wrong and $login_warning will notify the user of a failed login. The latter will either be empty or enclosed in a paragraph with the CSS ID 'login_warning'.

Parameters

$message

stringThe message to show to the user.

get_function_stack ()

handle_error ($errno, $errstr, $errfile, $errline, $errcontext)

Catch a PHP error and turn it into an Exception to unify error handling

Parameters

$errno

$errstr

$errfile

$errline

$errcontext

handle_exception (\Exception $e)

Catch an Exception and show it as a HTTP error

show (int $httpcode, string $message)

Show an error page.

This function is a small helper, that will display a simple HTML Page reporting the error described by $httpcode and $message. The $httpcode is also used to send an appropriate HTTP Response.

The error pages can be customized by creating style elements named midcom_error_$httpcode.

For a list of the allowed HTTP codes see the MIDCOM_ERR... constants

Note: This function will call _midcom_stop_request() after it is finished.

link Styling MidCOM error pages

Parameters

$httpcode

intThe error code to send.

$message

stringThe message to print.

_generate_http_response ()

_log ($httpcode, $msg)

Parameters

$httpcode

$msg

_send_email ($httpcode, $msg)

Parameters

$httpcode

$msg

send (int $httpcode, string $message)

Send error for processing.

If the given error code has an action configured for it, that action will be performed. This means that system administrators can request email notifications of 500 "Internal Errors" and a special log of 404 "Not Founds".

Parameters

$httpcode

intThe error code to send.

$message

stringThe message to print.

 Properties

 

\Exception $_exception

Holds the current exception