PHP code example of code-distortion / clarity-control

1. Go to this page and download the library: Download code-distortion/clarity-control 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-control example snippets

 bash
php artisan vendor:publish --provider="CodeDistortion\ClarityControl\ServiceProvider" --tag="config"
 php
Control::prepare($callable)->channel('slack')->execute();
 php
Control::prepare($callable)->channel(['stack', 'slack'])->execute();
 php
$result = Control::prepare($callable)->default($default)->execute();
 php
Control::prepare($callable)
    ->match('Undefined variable $a')       // exact string match of $e->getMessage()
    ->matchRegex('/^Undefined variable /') // regex string match of $e->getMessage()
    ->execute();
 php
Control::prepare($callable)
    ->known('https://company.atlassian.net/browse/ISSUE-1234')
    ->execute();
 php
Control::prepare($callable)->rethrow()->execute();
 php
$closure = fn(Throwable $e) => new MyException('Something happened', 0, $e);
Control::prepare($callable)->rethrow($closure)->execute();
 php
Control::globalCallback($callable);
 php
namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use CodeDistortion\ClarityControl\Control;

class MyServiceProvider extends ServiceProvider
{
    public function boot()
    {
        $callback = function () { … }; // do something
        Control::globalCallback($callback); // <<<
    }
}
 php
$finally = fn() => …; // do something

Control::run($callable, 'default', $finally);
// or
Control::prepare($callable, 'default', $finally)->execute();
 php
Control::prepare($callable)->finally($finally)->execute();
 php
Control::prepare($callable)->getException($e)->execute();

dump($e); // will contain the exception, or null