Skip to content

Latest commit

 

History

History
45 lines (32 loc) · 1.44 KB

README.md

File metadata and controls

45 lines (32 loc) · 1.44 KB

Pluggit Circuit Breaker

Build Status Scrutinizer Code Quality Code Coverage

Circuit Breaker is a service that gives you the control of your external dependencies

Installation

Require the library as usual:

composer require "pluggit/circuit-breaker"

Cache

In order for this library to work you need to install a cache library, you can use any PSR-16 simple cache but we encourage you to use the pluggit one. You can do so requiring it via composer:

composer require "pluggit/cache"

Usage

<?php

$circuitBreaker = new \Cmp\CircuitBreaker\CircuitBreaker($mySimpleCache);
$circuitBreaker->trackService(new \Cmp\CircuitBreaker\Service('payment.gateway'));

...

if ( $circuitBreaker->isAvailable('payment.gateway') ) {
    try {
        $paymentGatewayService->charge();
        $circuitBreaker->reportSuccess('payment.gateway');
    } catch (Exception $e) {
        $circuitBreaker->reportFailure('payment.gateway');
    }
} else {
    // Do something else
}