PHP code example of visualweber / error-handler-custom

1. Go to this page and download the library: Download visualweber/error-handler-custom 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/ */

    

visualweber / error-handler-custom example snippets



// config/autoload/local.php
return [
    'db' => [
        'username' => 'mysqluser',
        'password' => 'mysqlpassword',
        'driver'   => 'pdo_mysql',
        'database' => 'mysqldbname',
        'host'     => 'mysqlhost',
        'driver_options' => [
            \PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\'',
        ],
    ],
];


// config/autoload/local.php
return [
    'doctrine' => [
        'connection' => [
            'orm_default' => [
                'driverClass' =>'Doctrine\DBAL\Driver\PDOMySql\Driver',
                'params' => [
                    'user'     => 'mysqluser',
                    'password' => 'mysqlpassword',
                    'dbname'   => 'mysqldbname',
                    'host'     => 'mysqlhost',
                    'port'     => '3306',
                    'driverOptions' => [
                        \PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\'',
                    ],
                ],
            ],
        ],
    ]
];


// config/autoload/error-handler-custom.local.php or config/autoload/expressive-error-handler-custom.local.php
return [

    'log' => [
        'ErrorHandlerCustomLogger' => [
            'writers' => [

                [
                    'name' => 'db',
                    'options' => [
                        'db'     => 'Zend\Db\Adapter\Adapter',
                        'table'  => 'log',
                        'column' => [
                            'timestamp' => 'date',
                            'priority'  => 'type',
                            'message'   => 'event',
                            'extra'     => [
                                'url'          => 'url',
                                'file'         => 'file',
                                'line'         => 'line',
                                'error_type'   => 'error_type',
                                'trace'        => 'trace',
                                'request_data' => 'request_data'
                            ],
                        ],
                    ],
                ],

            ],
        ],
    ],

    'error-handler-custom' => [
	// it's for the enable/disable the logger functionality
        'enable' => true,

        // default to true, if set to true, then you can see sample:
        // 1. /error-preview page ( ErrorHandlerCustom\Controller\ErrorPreviewController )
        // 2. error-preview command (ErrorHandlerCustom\Controller\ErrorPreviewConsoleController) via
        //       php public/index.php error-preview
        //
        // for zf-expressive ^1.0, the disable error-preview page is by unregister 'error-preview' from this config under "routes",
        // for zf-expressive ^2.0, the disable error-preview page is by unregister 'error-preview' from config/routes
        //
        //
        // otherwise(false), you can't see them, eg: on production env.
        'enable-error-preview-page' => true,

        'display-settings' => [

            // excluded php errors ( http://www.php.net/manual/en/errorfunc.constants.php )
            'exclude-php-errors' => [
                \E_USER_DEPRECATED,
            ],

            // excluded exceptions
            'exclude-exceptions' => [
                \App\Exception\MyException::class, // can be an Exception class or class extends Exception class
            ],

            // show or not error
            'display_errors'  => 0,

            // if enable and display_errors = 0, the page will bring layout and view
            'template' => [
                'layout' => 'layout/layout',
                'view'   => 'error-handler-custom/error-default'
            ],

            // if enable and display_errors = 0, the console will bring message
            'console' => [
                'message' => 'We have encountered a problem and we can not fulfill your request. An error report has been generated and sent to the support team and someone will attend to this problem urgently. Please try again later. Thank you for your patience.',
            ],
            // if enable, display_errors = 0, and request XMLHttpRequest
            // on this case, the "template" key will be ignored.
            'ajax' => [
                'message' => <<<json
{
    "type": "http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html",
    "title": "Internal Server Error",
    "status": 500,
    "detail": "We have encountered a problem and we can not fulfill your request. An error report has been generated and sent to the support team and someone will attend to this problem urgently. Please try again later. Thank you for your patience."
}
json
            ],
        ],

        'logging-settings' => [
            // time range for same error, file, line, url, message to be re-logged
	        // in seconds range, 86400 means 1 day
            'same-error-log-time-range' => 86400,
        ],

        'email-notification-settings' => [
            // set to true to activate email notification on log error event
            'enable' => false,

            // Zend\Mail\Message instance registered at service manager
            'mail-message'   => 'YourMailMessageService',

            // Zend\Mail\Transport\TransportInterface instance registered at service manager
            'mail-transport' => 'YourMailTransportService',

            // email sender
            'email-from'    => 'Sender Name <[email protected]>',

            'email-to-send' => [
                '[email protected]',
                '[email protected]',
            ],
        ],
    ],
    // ...
];

// config/modules.config.php or config/application.config.php
return [
    'Application',
    'ErrorHandlerCustom', // <-- register here
],

$app->pipe(ErrorHandler::class);
$app->pipe(ErrorHandlerCustom\Middleware\Expressive::class); // here

$app->get('/error-preview[/:action]', ErrorHandlerCustom\Middleware\Routed\Preview\ErrorPreviewAction::class, 'error-preview');
sh
cp vendor/visualweber/error-handler-custom/config/error-handler-custom.local.php.dist config/autoload/error-handler-custom.local.php
sh
cp vendor/visualweber/error-handler-custom/config/expressive-error-handler-custom.local.php.dist config/autoload/expressive-error-handler-custom.local.php