Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tabuna/failback
Wrapper for creating a branch of inaccessibility.
https://github.com/tabuna/failback
failback fallback
Last synced: 25 days ago
JSON representation
Wrapper for creating a branch of inaccessibility.
- Host: GitHub
- URL: https://github.com/tabuna/failback
- Owner: tabuna
- License: mit
- Created: 2019-10-07T14:34:56.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-07-22T02:18:38.000Z (over 1 year ago)
- Last Synced: 2024-04-01T08:48:31.817Z (7 months ago)
- Topics: failback, fallback
- Language: PHP
- Homepage:
- Size: 16.6 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# 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:
``` bash
$ composer require tabuna/failback
```## Usage
#### Setting a Default Value:
You can create an action with a default value using the following code:
```php
use Tabuna\FailBack\Action;// $result = 'default';
$result = Action::make(function () {
throw new \Exception();
}, 'default')->run();// Alternatively, you can use the short helper
$result = failBack(function () {
throw new \Exception();
}, 'default')();
```#### Adding Fallback Actions:
You can define multiple fallback actions using the `fail` method:
```php
// $result = true;
$result = failBack(function () {
throw new \Exception();
})->fail(function () {
throw new \Error();
})->fail(function () {
return true;
})();
```#### Utilizing Classes:
To specify a fallback action using a class, create an anonymous class with an `__invoke` method:
```php
$class = new class {/**
* @return bool
*/
public function __invoke(): bool
{
return true;
}
};// $result = true;
$result = failBack(function () {
throw new Exception();
})->fail($class)->run();
```## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.