PHP code example of leafs / exception

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

    

leafs / exception example snippets


use Leaf\Crash\Hub;

$hub = new Hub();

$hub->context([
    'appRoot' => __DIR__,
    'user' => ['id' => auth()->id()],
    'request' => ['method' => 'POST', 'url' => '/checkout'],
]);

try {
    checkout($cart);
} catch (Throwable $error) {
    $report = $hub->capture($error);

    echo (new Leaf\Crash\Renderer\HtmlRenderer())->render($report);
}

$hub->leaveCrumb('POST /checkout', Breadcrumbs::TYPE_REQUEST);
$hub->leaveCrumb('coupon applied', Breadcrumbs::TYPE_ACTION, ['total_after' => $total]);

if ($order['total'] <= 0 && count($order['items']) > 0) {
    $hub->capture('order total is 0 but cart has items', [
        'level' => 'warning',
        'peeks' => ['order' => $order],
    ]);
}

$cart = $hub->span('db: load cart', fn () => Cart::for($userId));

$hub->reportTo(new MyLogReporter());
$hub->countWith(new MyOccurrenceStore()); // "seen 12 times" counts, when a store exists