PHP code example of code-distortion / clarity-context
1. Go to this page and download the library: Download code-distortion/clarity-context 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/ */
code-distortion / clarity-context example snippets
php
// in a file in your project
Clarity::context('Performing checkout', ['user-id' => $userId, 'order-id' => $orderId]);
…
php
// app/Exceptions/Handler.php
namespace App\Exceptions;
use CodeDistortion\ClarityContext\Clarity; // <<<
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Throwable;
class Handler extends ExceptionHandler
{
…
/**
* Register the exception handling callbacks for the application.
*/
public function register(): void
{
$this->reportable(function (Throwable $e) {
$context = Clarity::getExceptionContext($e); // <<<
// … perform formatting and logging here
});
}
}
php
$context->getStackTrace()->getMeta(ContextMeta::class); // only ContextMeta objects will be returned