degraciamathieu / php-easy-breaker
PHP implementation of circuit breaker pattern.
v1.0.1
2019-12-15 21:17 UTC
Requires
- php: ^7.4
- illuminate/support: 6.*
Requires (Dev)
- mockery/mockery: ^0.9.9
- phpunit/phpunit: ^6.5
This package is auto-updated.
Last update: 2024-11-29 06:03:36 UTC
README
degraciamathieu/php-easy-breaker
PHP implementation of circuit breaker pattern.
Installation
Run in console below command to download package to your project:
composer require degraciamathieu/php-easy-breaker
usage
require __DIR__.'/vendor/autoload.php'; 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." // }