For most use cases this library requires no configuration and little effort to integrate into non-complex environments:
For most use cases this library requires no configuration and little effort to integrate into non-complex environments:
```php
```php
use MensBeam\Foundation\Catcher;
use MensBeam\Catcher;
$catcher = new Catcher();
$catcher = new Catcher();
```
```
@ -38,9 +38,9 @@ $catcher = new Catcher();
That's it. It will automatically register Catcher as an exception, error, and shutdown handler and use `PlainTextHandler` as its sole handler. Catcher can be configured to use one or multiple _handlers_. Imagine a situation where it is necessary to both output text for logging and JSON for an API endpoint. This is easily done using Catcher:
That's it. It will automatically register Catcher as an exception, error, and shutdown handler and use `PlainTextHandler` as its sole handler. Catcher can be configured to use one or multiple _handlers_. Imagine a situation where it is necessary to both output text for logging and JSON for an API endpoint. This is easily done using Catcher:
```php
```php
use MensBeam\Foundation\Catcher,
use MensBeam\Catcher,
Monolog\Logger;
Monolog\Logger;
use MensBeam\Foundation\Catcher\{
use MensBeam\Catcher\{
JSONHandler,
JSONHandler,
PlainTextHandler
PlainTextHandler
};
};
@ -89,13 +89,13 @@ PHP by default won't allow fatal errors to be handled by error handlers. It will
## Documentation ##
## Documentation ##
### MensBeam\Foundation\Catcher ###
### MensBeam\Catcher ###
This is the main class in the library. Unless you have a need to configure a handler or use multiple handlers there usually isn't a need to interact with the rest of the library at all.
This is the main class in the library. Unless you have a need to configure a handler or use multiple handlers there usually isn't a need to interact with the rest of the library at all.
```php
```php
namespace MensBeam\Foundation;
namespace MensBeam;
use Mensbeam\Foundation\Catcher\Handler;
use MensBeam\Catcher\Handler;
class Catcher {
class Catcher {
public bool $forking = true;
public bool $forking = true;
@ -123,53 +123,53 @@ _forking_: When set to true Catcher will throw converted notices, warnings, etc.
_preventExit_: When set to true Catcher won't exit at all even after fatal errors or exceptions
_preventExit_: When set to true Catcher won't exit at all even after fatal errors or exceptions
_throwErrors_: When set to true Catcher will convert errors to throwables
_throwErrors_: When set to true Catcher will convert errors to throwables
Registers the Catcher instance as an error, exception, and shutdown handler. By default the constructor does this automatically, but this method exists in case `unregister` has been called.
Registers the Catcher instance as an error, exception, and shutdown handler. By default the constructor does this automatically, but this method exists in case `unregister` has been called.
Unshifts the specified handler(s) onto the beginning of the stack
Unshifts the specified handler(s) onto the beginning of the stack
### MensBeam\Foundation\Catcher\Handler ###
### MensBeam\Catcher\Handler ###
All handlers inherit from this abstract class. Since it is an abstract class meant for constructing handlers protected methods and properties will be documented here as well.
All handlers inherit from this abstract class. Since it is an abstract class meant for constructing handlers protected methods and properties will be documented here as well.
```php
```php
namespace MensBeam\Foundation\Catcher;
namespace MensBeam\Catcher;
abstract class Handler {
abstract class Handler {
public const CONTENT_TYPE = null;
public const CONTENT_TYPE = null;
@ -253,48 +253,48 @@ _timeFormat_: The PHP-standard date format which to use for times in output. Def
_varExporter_: A user-defined closure to use when printing arguments in backtraces. Defaults to _null_.
_varExporter_: A user-defined closure to use when printing arguments in backtraces. Defaults to _null_.
"Cleans" an output throwable -- an individual item in the output array -- by removing information that's unnecessary in the output; useful for structured data output such as JSON.
"Cleans" an output throwable -- an individual item in the output array -- by removing information that's unnecessary in the output; useful for structured data output such as JSON.
We cannot require all throwables to be converted to our own classes, so this class exists as a controller to add new features to throwables for use with Catcher.
We cannot require all throwables to be converted to our own classes, so this class exists as a controller to add new features to throwables for use with Catcher.
```php
```php
namespace MensBeam\Foundation\Catcher;
namespace MensBeam\Catcher;
class ThrowableController {
class ThrowableController {
public function __construct(\Throwable $throwable);
public function __construct(\Throwable $throwable);
Returns the error type of a `MensBeam\Foundation\Catcher\Error`, meaning a human-friendly representation of the error code (eg: _"Fatal Error"_, _"Warning"_, _"Notice"_) or null if the throwable isn't an `Error`.
Returns the error type of a `MensBeam\Catcher\Error`, meaning a human-friendly representation of the error code (eg: _"Fatal Error"_, _"Warning"_, _"Notice"_) or null if the throwable isn't an `Error`.