PHP code example of degraciamathieu / php-easy-breaker
1. Go to this page and download the library: Download degraciamathieu/php-easy-breaker 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/ */
degraciamathieu / php-easy-breaker example snippets
use Exception;
use DeGraciaMathieu\EasyBreaker\Breaker;
use DeGraciaMathieu\EasyBreaker\CircuitBreaker;
$firstBreaker = (new Breaker)
->when(Exception::class)
->do(function(Exception $e){
return "it's broken.";
});
$secondBreaker = (new Breaker)
->when(Exception::class)
->do(function(Exception $e){
return "really broken.";
});
$thirdBreaker = (new Breaker)
->when(AnotherException::class)
->do(function(AnotherException $e){
return "boom.";
});
$results = (new CircuitBreaker())
->addBreaker($firstBreaker)
->addBreaker($secondBreaker)
->addBreaker($thirdBreaker)
->closure(function(){
throw new Exception();
});
var_dump($results);
// array(2) {
// [0]=>
// string(12) "it's broken."
// [1]=>
// string(18) "really broken."
// }
composer