fValidationExceptionclassv1.0.0b2

An exception caused by a data not matching a rule or set of rules

Changes:
1.0.0b2Added a custom __construct() to handle arrays of messages 9/17/09
1.0.0bThe initial implementation 6/14/07

Genealogy

Class Tree

Exception
   |
   --fException
      |
      --fExpectedException
         |
         --fValidationException

Inherited Variables

Exception::$code
The exception code
Exception::$file
The file the exception was thrown in
Exception::$line
The line the exception was thrown on
Exception::$message
The exception message

Inherited Methods

fException::__construct()
Sets the message for the exception, allowing for string interpolation and internationalization
fException::__get()
All requests that hit this method should be requests for callbacks
fException::compose()
Composes text using fText if loaded
fException::dump()
Creates a string representation of any variable using predefined strings for booleans, NULL and empty strings
fException::formatTrace()
Gets the backtrace to currently called exception
fException::getCSSClass()
Returns the CSS class name for printing information about the exception
fException::prepare()
Prepares content for output into HTML
fException::printMessage()
Prints the message inside of a div with the class being 'exception %THIS_EXCEPTION_CLASS_NAME%'
fException::printTrace()
Prints the backtrace to currently called exception inside of a pre tag with the class being 'exception %THIS_EXCEPTION_CLASS_NAME% trace'
fException::registerCallback()
Adds a callback for when certain types of exceptions are created
fException::reorderMessage()
Reorders list items in the message based on simple string matching
fException::setMessage()
Allows the message to be overwriten
fException::splitMessage()
Splits an exception with an HTML list into multiple strings each containing part of the original message
Exception::__construct()
Creates the exception
Exception::__toString()
Converts the exception to a string
Exception::getCode()
Returns the exception code
Exception::getFile()
Returns the file the exception was thrown in
Exception::getLine()
Returns the line the exception was thrown on
Exception::getMessage()
Returns the exception message
Exception::getTrace()
Returns the backtrace leading up to the exception
Exception::getTraceAsString()
Returns the backtrace leading up to the exception as a string

Static Variables

::$field_formatprotected

The formatting string to use for field names

Type

string

Static Methods

::formatField() public

Accepts a field name and formats it based on the formatting string set via setFieldFormat()

Signature

string formatField( string $field )

Parameters

string $field The name of the field to format

Returns

The formatted field name

::setFieldFormat() public

Set the format to be applied to all field names used in fValidationExceptions

The format should contain exactly one %s sprintf() conversion specification, which will be replaced with the field name. Any literal % characters should be written as %%.

The default format is just %s: , which simply inserts a : and space after the field name.

Signature

void setFieldFormat( string $format )

Parameters

string $format A string to format the field name with - %s will be replaced with the field name

Methods

->__construct() public

Sets the message for the exception, allowing for custom formatting beyond fException

If this method receives exactly two parameters, a string and an array, the string will be used as a message in a HTML <p> tag and the array will be turned into an unorder list <ul> tag with each element in the array being an <li> tag. It is possible to pass an optional exception code as a third parameter.

The following PHP:

throw new fValidationException(
    'The following problems were found:',
    array(
        'Please provide your name',
        'Please provide your email address'
    )
);

Would create the message:

<p>The following problems were found:</p>
<ul>
    <li>Please provide your name</li>
    <li>Please provide your email address</li>
</ul>

If the parameters are anything else, they will be passed to fException::__construct().

Signature

fException __construct( string $message='', array $sub_messages, mixed $code )

Parameters

string $message The beginning message for the exception. This will be placed in a &lt;p&gt; tag.
array $sub_messages An array of strings to place in a &lt;ul&gt; tag
mixed $code The optional exception code

Overrides

fException::__construct()
Sets the message for the exception, allowing for string interpolation and internationalization