PHP code example of josegonzalez / php-error-handlers

1. Go to this page and download the library: Download josegonzalez/php-error-handlers library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

josegonzalez / php-error-handlers example snippets


// Create an array of configuration data to pass to the handler class
$config = [
    'handlers' => [
        // *Can* be the class name, not-namespaced
        // The namespace will be "interpolated" in such cases
        'NewrelicHandler' => [
        ],
        // Can also rs\Handler($config))->register();

// Enjoy throwing exceptions and reporting them upstream
throw new \Exception('Test Exception');

$config = [
    'handlers' => [
        'BugsnagHandler' => [
            'clientCallback' => function ($client) {
                // do something interesting to the client
                $client->setAppVersion('1.0.0');
                return $client;
            },
        ],
    ],
];

$config = [
    'handlers' => [
        'BugsnagHandler' => [
            'exceptionCallback' => function ($exception) {
                // return null to skip reporting errors
                if ($exception instanceof \Error) {
                    return null;
                }
                return $exception;
            },
        ],
    ],
];

public function handle($exception);

// around line 100
$isCli = PHP_SAPI === 'cli';
if ($isCli) {
    (new \Josegonzalez\ErrorHandlers\Cake\ConsoleErrorHandler(Configure::read('Error')))->register();
} else {
    (new \Josegonzalez\ErrorHandlers\Cake\ErrorHandler(Configure::read('Error')))->register();
}
shell
# install it
composer