Skip to content
PHP implementations of circuit breaker pattern.
PHP
Branch: master
Clone or download
This branch is 29 commits ahead of DeGraciaMathieu:master.

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
config.core
src
tests
.gitignore
.travis.yml
README.md
composer.json
config.xml
phpunit.xml

README.md

webfan3/php-easy-breaker

PHP implementation of circuit breaker pattern forked from degraciamathieu/php-easy-breaker.

  • Wants to support php<7.4
  • Scripts for the use as frdl-module [@ToDo]

Installation

  1. Add the frdl/webfan respository to your root-package composer.json file:
{
 "repositories": [{
   "type": "composer",
   "url": "https://packages.frdl.de"
 }]
}
  1. Run in console below command to download package to your project:
composer require webfan3/php-easy-breaker
  1. OPTIONAL: Install via the Webfan Development UI

usage

require __DIR__.'/vendor/autoload.php';

use Exception;
use Webfan\DeGraciaMathieu\EasyBreaker\Breaker;
use Webfan\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 "realy 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) "realy broken."
// }
You can’t perform that action at this time.