PHP code example of freshwaveonline / janitor

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

    

freshwaveonline / janitor example snippets


'message_number' => [
    'prefix' => env('JANITOR_PREFIX', 'ERR'),  // ERR-3F9A2C
    'length' => 6,
    'alphabet' => MessageNumberAlphabet::Hex,      // Hex | Numeric | Base36
    'origin' => OriginStrategy::Application,       // Application | Thrown | RootCause
    'salt' => env('JANITOR_SALT'),
],

'actions' => [
    401 => ['login', 'home'],
    404 => ['back', 'home', [
        'label' => 'Browse the catalogue',
        'url' => '/products',
        'icon' => 'magnifying-glass',
        'style' => 'ghost',
    ]],
    429 => ['retry', 'home'],
    'default' => ['back', 'home'],
],

'details' => [
    'visibility' => DetailVisibility::Auto,   // Auto | Always | Never
    'environments' => ['local', 'development', 'testing', 'staging'],
    'replace_debug_page' => false,
],

'livewire' => [
    'mode' => LivewireErrorMode::Modal,        // Modal | Page | Disabled
    'position' => ModalPosition::BottomRight,
    'inject_assets' => true,
    'dismissible' => true,
    'auto_dismiss' => 0,
],

'filament' => [
    'enabled' => true,
    'only_on_panel_routes' => true,
    'inherit' => [
        'brand_name' => true,
        'brand_logo' => true,
        'primary_color' => true,
        'home_url' => true,
        'login_url' => true,
    ],
],

'colors' => [
    'primary' => env('JANITOR_PRIMARY', '#4f46e5'),
    'light' => env('JANITOR_PRIMARY_LIGHT'),   // optional override
    'dark' => env('JANITOR_PRIMARY_DARK'),     // optional override
    'auto_contrast' => true,
],

'theme' => Theme::Auto,   // Auto | Light | Dark

'views' => ['layout' => 'layouts.app'],

use FreshwaveOnline\Janitor\Contracts\BrandingResolver;
use FreshwaveOnline\Janitor\Data\Branding;

class TenantBranding implements BrandingResolver
{
    public function resolve(Request $request, int $statusCode): Branding
    {
        $tenant = Tenant::forHost($request->getHost());

        return new Branding(
            name: $tenant?->name,
            logo: $tenant?->logo_url,
            primaryColor: $tenant?->brand_colour,
            homeUrl: $tenant?->url,
            supportEmail: $statusCode >= 500 ? $tenant?->support_email : null,
        );
    }
}

// AppServiceProvider::register()
$this->app->bind(BrandingResolver::class, TenantBranding::class);

$this->app->bind(BrandingResolver::class, fn ($app) => new class ($app->make(ConfigBranding::class)) implements BrandingResolver {
    public function __construct(private ConfigBranding $inner) {}

    public function resolve(Request $request, int $status): Branding
    {
        return $this->inner->resolve($request, $status)->with(primaryColor: tenant()->colour);
    }
});

class CopyFromCms extends ErrorContextFactory
{
    protected function optionalLine(int $status, string $key, ?string $number, Branding $branding): ?string
    {
        return Cms::line($status, $key) ?? parent::optionalLine($status, $key, $number, $branding);
    }
}

// AppServiceProvider::boot()
Icons::register('acme-mark', 'M12 2 2 22h20L12 2z');
Icons::useForStatus(404, 'acme-mark');

'except_codes' => [422],
'except_exceptions' => [
    Illuminate\Validation\ValidationException::class,
    Illuminate\Http\Exceptions\HttpResponseException::class,
    Illuminate\Auth\AuthenticationException::class,
],

abort(403, 'You may not edit a published post.');

'messages' => [
    'use_exception_message' => true,
    'use_exception_message_codes' => [400, 402, 403, 409, 410, 423, 429],
],
bash
php artisan janitor:install
bash
php artisan vendor:publish --tag=janitor-config
php artisan vendor:publish --tag=janitor-views
php artisan vendor:publish --tag=janitor-lang

php artisan serve
open http://localhost:8000/_janitor
bash
php artisan vendor:publish --tag=janitor-lang
bash
php artisan vendor:publish --tag=janitor-views

resources/views/vendor/janitor/
├── error.blade.php               ← the standalone page
├── embedded.blade.php            ← the card inside your own layout
├── preview.blade.php
├── preview-modal.blade.php
└── partials/
    ├── card.blade.php            ← header, blocks, actions, meta, details
    ├── styles.blade.php          ← the entire inline stylesheet
    ├── brand.blade.php
    ├── brand-mark.blade.php
    ├── actions.blade.php         ← the CTA buttons
    ├── meta.blade.php            ← message number / request ID chips
    ├── retry.blade.php           ← the countdown block
    ├── details.blade.php         ← the 5xx exception block
    ├── scripts.blade.php         ← copy buttons + countdown
    └── livewire-script.blade.php ← the pop-up handler
blade
<!DOCTYPE html>
<html>
<body>
    <h1>{{ $error->statusCode }} — {{ $error->title }}</h1>
    <p>{{ $error->message }}</p>

    @foreach ($error->actions() as $action)
        <a href="{{ $action->url }}">{{ $action->label }}</a>
    @endforeach
</body>
</html>
blade
{{-- resources/views/vendor/janitor/errors/404.blade.php --}}
<h1>Bespoke 404 — {{ $error->title }}</h1>