PHP code example of acelaya / ze-content-based-error-handler

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

    

acelaya / ze-content-based-error-handler example snippets



use Acelaya\ExpressiveErrorHandler\ErrorHandler\Factory\PlainTextResponseGeneratorFactory;
use Zend\Expressive\Container\ErrorResponseGeneratorFactory;

return [

    'error_handler' => [
        'default_content_type' => 'text/html',

        'plugins' => [
            'factories' => [
                'text/plain' => PlainTextResponseGeneratorFactory::class,
                'text/html' => ErrorResponseGeneratorFactory::class,
            ],
            'aliases' => [
                'application/xhtml+xml' => 'text/html',
            ],
        ],
    ],

];


return (new Acelaya\ExpressiveErrorHandler\ConfigProvider())->__invoke();

return (new Zend\ConfigAggregator\ConfigAggregator([
    Acelaya\ExpressiveErrorHandler\ConfigProvider::class,
    // [...]
    new Zend\ConfigAggregator\ZendConfigProvider('config/autoload/{{,*.}global,{,*.}local}.php'),
], 'data/cache/app_config.php'))->getMergedConfig();


use Zend\Expressive\Container\WhoopsErrorResponseGeneratorFactory;
use Zend\Expressive\Container\WhoopsFactory;
use Zend\Expressive\Container\WhoopsPageHandlerFactory;

return [

    'dependencies' => [
        'factories' => [
            'Zend\Expressive\Whoops' => WhoopsFactory::class,
            'Zend\Expressive\WhoopsPageHandler' => WhoopsPageHandlerFactory::class,
        ]
    ],

    'error_handler' => [
        'plugins' => [
            'factories' => [
                'text/html' => WhoopsErrorResponseGeneratorFactory::class,
            ],
        ],
    ],

];


use App\ErrorHandler\Factory\XmlErrorResponseGeneratorFactory;
use App\ErrorHandler\JsonErrorResponseGenerator;

return [

    'error_handler' => [
        'plugins' => [
            'invokables' => [
                'application/json' => JsonErrorResponseGenerator::class,
            ],
            'factories' => [
                'text/xml' => XmlErrorResponseGeneratorFactory::class,
            ],
            'aliases' => [
                'application/x-json' => 'application/json',
                'text/json' => 'application/json',
            ],
        ],
    ],

];


return [

    'error_handler' => [
        'default_content_type' => 'application/json',
    ],

];