diff options
Diffstat (limited to 'vendor/clue/connection-manager-extra/src/ConnectionManagerReject.php')
-rw-r--r-- | vendor/clue/connection-manager-extra/src/ConnectionManagerReject.php | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/vendor/clue/connection-manager-extra/src/ConnectionManagerReject.php b/vendor/clue/connection-manager-extra/src/ConnectionManagerReject.php new file mode 100644 index 0000000..1222c83 --- /dev/null +++ b/vendor/clue/connection-manager-extra/src/ConnectionManagerReject.php @@ -0,0 +1,41 @@ +<?php + +namespace ConnectionManager\Extra; + +use React\Socket\ConnectorInterface; +use React\Promise; +use Exception; + +// a simple connection manager that rejects every single connection attempt +class ConnectionManagerReject implements ConnectorInterface +{ + private $reason = 'Connection rejected'; + + /** + * @param null|string|callable $reason + */ + public function __construct($reason = null) + { + if ($reason !== null) { + $this->reason = $reason; + } + } + + public function connect($uri) + { + $reason = $this->reason; + if (!is_string($reason)) { + try { + $reason = $reason($uri); + } catch (\Exception $e) { + $reason = $e; + } + } + + if (!$reason instanceof \Exception) { + $reason = new Exception($reason); + } + + return Promise\reject($reason); + } +} |