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',
    ]);
}

// configs/hades.php

return [

    'transformers' => [
        App\Exceptions\Transformers\MyCustomTransformer::class,
    ],

];

use App\Exceptions\Transformers\MyCustomTransformer;
use Illuminate\Contracts\Debug\ExceptionHandler;

public function register(): void
{
    $this->app->bind(MyCustomTransformer::class, static fn () => 'your binding logic');

    $this->app->tag('api_error.exception_transformer', MyCustomTransformer::class);
}

use Jenky\Hades\Hades;

public function boot(): void
{
    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/*');
});

use Illuminate\Http\Request;

Hades::forceJsonOutput(static fn () => true);