-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
60f3cec
commit 7df379a
Showing
7 changed files
with
89 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace Stfn\CircuitBreaker; | ||
|
||
use Stfn\CircuitBreaker\Storage\CircuitBreakerStorage; | ||
|
||
class CircuitBreakerFactory | ||
{ | ||
protected CircuitBreaker $circuitBreaker; | ||
|
||
public static function make() | ||
{ | ||
$object = new self(); | ||
$object->circuitBreaker = new CircuitBreaker(); | ||
|
||
return $object; | ||
} | ||
|
||
public function for(string $service) | ||
{ | ||
$this->circuitBreaker->storage->setService($service); | ||
|
||
return $this; | ||
} | ||
|
||
public function withOptions(array $options) | ||
{ | ||
$this->circuitBreaker->config = Config::make($options); | ||
|
||
return $this; | ||
} | ||
|
||
public function storage(CircuitBreakerStorage $storage) | ||
{ | ||
$this->circuitBreaker->storage = $storage; | ||
|
||
return $this; | ||
} | ||
|
||
public function call(\Closure $action, ...$args) | ||
{ | ||
return $this->circuitBreaker->call($action, $args); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace Stfn\CircuitBreaker\Exceptions; | ||
|
||
class InvalidStateException extends \Exception | ||
{ | ||
/** | ||
* @param $state | ||
* @return InvalidStateException | ||
*/ | ||
public static function make($state) | ||
{ | ||
return new self("State {$state} is not valid"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters