Skip to content

Repository files navigation

Actions for Failback

Actions for Failback is a lightweight wrapper that empowers you to handle unavailability gracefully.

Installation

To install the package, you can use Composer. Simply run the following command:

$ composer require tabuna/failback

Usage

Setting a Default Value:

You can create an action with a default value using the following code:

useTabuna\FailBack\Action;
// $result = 'default';$result = Action::make(function () {
thrownew \Exception();
}, 'default')->run();
// Alternatively, you can use the short helper$result = failBack(function () {
thrownew \Exception();
}, 'default')();

Adding Fallback Actions:

You can define multiple fallback actions using the fail method:

// $result = true;$result = failBack(function () {
thrownew \Exception();
})->fail(function () {
thrownew \Error();
})->fail(function () {
returntrue;
})();

Utilizing Classes:

To specify a fallback action using a class, create an anonymous class with an __invoke method:

$class = newclass {
/** * @return bool */publicfunction__invoke(): bool
{
returntrue;
}
};
// $result = true;$result = failBack(function () {
thrownewException();
})->fail($class)->run();

License

The MIT License (MIT). Please see License File for more information.

About

Wrapper for creating a branch of inaccessibility.

Topics

Resources

Stars

4 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages