PHP code example of jenky / hades

1. Go to this page and download the library: Download jenky/hades 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/ */

    

jenky / hades example snippets


use Jenky\Hades\Hades;

/**
 * Bootstrap any application services.
 *
 * @return void
 */
public function boot()
{
    Hades::errorFormat([
        'message' => ':message',
        'error_description' => ':error',
    ]);
}

use App\Exceptions\InvalidOrderException;

/**
 * Register the exception handling callbacks for the application.
 *
 * @return void
 */
public function register()
{
    $this->catch(function (InvalidOrderException $e) {
        $this->replace('type', 'order_exception')
            ->replace('code', 1001);
    });
}


use Illuminate\Contracts\Container\Container;

/**
 * {@inheritdoc}
 */
public function __construct(Container $container)
{
    parent::__construct($container);

    $this->register();
}

use App\Exceptions\InvalidOrderException;
use Illuminate\Contracts\Debug\ExceptionHandler;

/**
 * Bootstrap any application services.
 *
 * @return void
 */
public function boot()
{
    $this->app[ExceptionHandler::class]->catch(function (InvalidOrderException $e, $handler) {
        $handler->replace('type', 'order_exception')
            ->replace('code', 1001);
    });
}

use Jenky\Hades\Hades;

/**
 * Bootstrap any application services.
 *
 * @return void
 */
public function boot()
{
    Hades::forceJsonOutput();
}

Hades::forceJsonOutput()
    ->withMimeType('application/vnd.myapp.v1+json');

use Illuminate\Http\Request;

Hades::forceJsonOutput(static function (Request $request) {
    return $request->is('api/v1/*');
});
 php


namespace App\Exceptions;

use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Jenky\Hades\Exception\HandlesExceptionResponse;

class Handler extends ExceptionHandler
{
    use HandlesExceptionResponse;
}