
An exception that allows for easy l10n, printing, tracing and hooking
1.0.0b8 | Added a missing line of backtrace to formatTrace() 6/28/09 |
---|---|
1.0.0b7 | Updated __construct() to no longer require a message, like the Exception class, and allow for non-integer codes 6/26/09 |
1.0.0b6 | Fixed splitMessage() so that the original message is returned if no list items are found, added reorderMessage() 6/2/09 |
1.0.0b5 | Added splitMessage() to replace fCRUDremoveListItems() and fCRUD::reorderListItems() 5/8/09 |
1.0.0b4 | Added a check to __construct() to ensure that the $code parameter is numeric 5/4/09 |
1.0.0b3 | Fixed a bug with printMessage() messing up some HTML messages 3/27/09 |
1.0.0b2 | compose() more robustly handles $components passed as an array, __construct() now detects stray % characters 2/5/09 |
1.0.0b | The initial implementation 6/14/07 |
Exception | --fException
Composes text using fText if loaded
string compose( string $message, mixed $component [, ... ] )
string | $message | The message to compose |
mixed | $component [, ... ] | A string or number to insert into the message |
The composed and possible translated message
Creates a string representation of any variable using predefined strings for booleans, NULL and empty strings
The string output format of this method is very similar to the output of print_r() except that the following values are represented as special strings:
string dump( mixed $data )
mixed | $data | The value to dump |
The string representation of the value
Adds a callback for when certain types of exceptions are created
The callback will be called when any exception of this class, or any child class, specified is tossed. A single parameter will be passed to the callback, which will be the exception object.
void registerCallback( callback $callback, string $exception_type=NULL )
callback | $callback | The callback |
string | $exception_type | The type of exception to call the callback for |
Sets the message for the exception, allowing for string interpolation and internationalization
The $message can contain any number of formatting placeholders for string and number interpolation via sprintf(). Any % signs that do not appear to be part of a valid formatting placeholder will be automatically escaped with a second %.
The following aspects of valid sprintf() formatting codes are not accepted since they are redundant and restrict the non-formatting use of the % sign in exception messages:
fException __construct( string $message='', mixed $component [, ... ], mixed $code )
string | $message | The message for the exception. This accepts a subset of sprintf() strings - see method description for more details. |
mixed | $component [, ... ] | A string or number to insert into the message |
mixed | $code | The exception code to set |
Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code
All requests that hit this method should be requests for callbacks
callback __get( string $method )
string | $method | The method to create a callback for |
The callback for the method requested
Gets the backtrace to currently called exception
string formatTrace( )
A nicely formatted backtrace to this exception
Returns the CSS class name for printing information about the exception
void getCSSClass( )
Prepares content for output into HTML
string prepare( $content )
$content |
The prepared content
Prints the message inside of a div with the class being 'exception %THIS_EXCEPTION_CLASS_NAME%'
void printMessage( )
Prints the backtrace to currently called exception inside of a pre tag with the class being 'exception %THIS_EXCEPTION_CLASS_NAME% trace'
void printTrace( )
Reorders list items in the message based on simple string matching
fException reorderMessage( string $match [, ... ] )
string | $match [, ... ] | This should be a string to match to one of the list items - whatever the order this is in the parameter list will be the order of the list item in the adjusted message |
The exception object, to allow for method chaining
Allows the message to be overwriten
void setMessage( string $new_message )
string | $new_message | The new message for the exception |
Splits an exception with an HTML list into multiple strings each containing part of the original message
This method should be called with two or more parameters of arrays of string to match. If any of the provided strings are matching in a list item in the exception message, a new copy of the message will be created containing just the matching list items.
Here is an exception message to be split:
The following problems were found:
- First Name: Please enter a value
- Last Name: Please enter a value
- Email: Please enter a value
- Address: Please enter a value
- City: Please enter a value
- State: Please enter a value
- Zip Code: Please enter a value
The following PHP would split the exception into two messages:
list ($name_exception, $address_exception) = $exception->splitMessage(
array('First Name', 'Last Name', 'Email'),
array('Address', 'City', 'State', 'Zip Code')
);
The resulting messages would be:
The following problems were found:
- First Name: Please enter a value
- Last Name: Please enter a value
- Email: Please enter a value
and
The following problems were found:
- Address: Please enter a value
- City: Please enter a value
- State: Please enter a value
- Zip Code: Please enter a value
If no list items match the strings in a parameter, the result will be an empty string, allowing for simple display:
fHTML::show($name_exception, 'error');
An empty string is returned when none of the list items matched the strings in the parameter. If no list items are found, the first value in the returned array will be the existing message and all other array values will be an empty string.
array splitMessage( array $list_item_matches [, ... ] )
array | $list_item_matches [, ... ] | An array of strings to filter the list items by, list items will be ordered in the same order as this array |
This will contain an array of strings corresponding to the parameters passed - see method description for details