1. Go to this page and download the library: Download milon/fuse 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/ */
milon / fuse example snippets
use Milon\Fuse\Fuse;
use Milon\Fuse\CircuitBreakerConfig;
use Milon\Fuse\Stores\ArrayStore;
$fuse = Fuse::for(
name: 'billing-sdk',
store: new ArrayStore(),
config: CircuitBreakerConfig::defaults(),
);
$result = $fuse->run(
execute: fn () => $client->charge($payload),
);
use Milon\Fuse\Events\CallableCircuitEventDispatcher;
use Milon\Fuse\Events\CircuitOpened;
use Milon\Fuse\FuseFactory;
$factory = new FuseFactory(
store: $store,
settings: [
'breakers' => [
'billing-sdk' => ['failure_threshold' => 3],
],
],
events: (new CallableCircuitEventDispatcher)
->listenFor(CircuitOpened::class, fn (CircuitOpened $e) => error_log($e->storageKey)),
);
$factory->for('billing-sdk')->run(fn () => $client->charge($payload));
use Milon\Fuse\Saloon\Traits\HasCircuitBreaker;
use Saloon\Http\Connector;
class ExampleConnector extends Connector
{
use HasCircuitBreaker;
public function resolveBaseUrl(): string
{
return 'https://api.example.com';
}
}
use Milon\Fuse\Testing\FuseMockClient;
use Milon\Fuse\Testing\InteractsWithFuse;
use Saloon\Http\Faking\MockResponse;
FuseMockClient::mock($connector, [MockResponse::make(status: 503)]);
$this->assertCircuitOpen($fuse);
$this->forceCircuitOpenFor($factory, 'billing', operation: 'charge');