Download the PHP package eboreum/exceptional without Composer
On this page you can find all versions of the php package eboreum/exceptional. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download eboreum/exceptional
More information about eboreum/exceptional
Files in eboreum/exceptional
Package exceptional
Short Description Create and format PHP exceptions easily. Automatically unravel method arguments. Ensure that sensitive strings like passwords, tokens, PHPSESSID, etc. are being masked and thus will instead appear as e.g. "******" in the resulting text.
License MIT
Informations about the package exceptional
Eboreum/Exceptional: Create and format PHP exceptions easily
Create and format PHP exceptions easily. Automatically unravel method arguments. Ensure that sensitive strings like passwords, tokens, PHPSESSID, etc. are being masked and thus will instead appear as e.g. "**" in the resulting text.
When a method is called, and somehow that leads to an exception/throwable being raised, wouldn't it be nice knowing all arguments a method was called with? Exceptional can unravel that for you and present these arguments with their respective names in a concise and meaningful way. Additionally, the integration with Eboreum/Caster (https://packagist.org/packages/eboreum/caster) allows revealing of information about the object within which the exception/error occured. This is sometimes valuable and crucial information, and it is superb for debugging.
Requirements
For more information, see the composer.json
file.
Installation
Via Composer (https://packagist.org/packages/eboreum/exceptional):
composer install eboreum/exceptional
Via GitHub:
git clone [email protected]:eboreum/exceptional.git
Fundamentals
Exception message generation
Example 1: The basics
Example:
Output:
Notice how each argument is paired with its respective values from the func_get_args()
function. The argument $c
has even received its default value, which func_get_args()
will not return.
Example 2: Providing more arguments than there are named arguments
Example:
Output:
Notice how $a
and $b
are named, but the unnamed arguments have received their respective indexes, {2}
and {3}
.
Example 3: A constant as default value
Example:
Output:
Argument $a
has received its default value from the class constant Fooc261bae9da674d679de77a943ae57779::SOME_CONSTANT
, $b
has received its default value from the class constant Fooaea91664ed3d4467aeb2dfabb2623b53::SOME_PARENT_CONSTANT
, and $c
has received its default value from the global constant GLOBAL_CONSTANT_25b105757d32443188cca9c7646ccfe6
.
Example 4: Static method call
Example:
Output:
Notice how instead of $this
, static::class
is used.
Example 5: Making object descriptions verbose using caster
Wouldn't it be nice if we, in addition to the method argument snitching, could get additional information about the object within which the method failed? We can do just that using the Eboreum\Caster\Caster
integration.
Example:
Output:
Notice how we now get useful information from the above object, its ID being 42 (and argument $a
is 7).
You must use $this
as the argument in the makeFailureInMethodMessage
call (and not static::class
) for the above to work.
Exception formatters
Example 1: Default formatter
Class: Eboreum\Exceptional\Formatting\DefaultFormatter
A plain text formatter. Contains line breaks and indentation.
Output:
Example 2: HTML5 <table>
formatter
Class: Eboreum\Exceptional\Formatting\HTML5TableFormatter
Formats the throwable as HTML5 <table>
.
Output:
Example 3: JSON formatter
Class: Eboreum\Exceptional\Formatting\JSONFormatter
Formats the throwable as JSON.
Output:
Example 4: Oneline formatter
Class: Eboreum\Exceptional\Formatting\OnelineFormatter
Formats the throwable as string with all its contents on a single line. Great for (improved) output in error logs, which do not allow line breaks.
Output:
Example 5: XML formatter
Class: Eboreum\Exceptional\Formatting\XMLFormatter
Formats the throwable as XML.
Output:
Test/development requirements
Running tests
For all unit tests, first follow these steps:
License & Disclaimer
See LICENSE
file. Basically: Use this library at your own risk.
Contributing
We prefer that you create a ticket and or a pull request at https://github.com/eboreum/exceptional, and have a discussion about a feature or bug here.
Branch rules
main
= 2.x
(not a tag)
Previous branches:
Credits
Authors
- Kasper Søfren (kafoso)
E-mail: https://github.com/kafoso - Carsten Jørgensen (corex)
E-mail: https://github.com/corex