Skip to content

Mad-Collective/circuit-breaker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
}