|
| 1 | +<?php |
| 2 | +namespace Bunny\NG; |
| 3 | + |
| 4 | +use Bunny\NG\Sasl\SaslMechanismInterface; |
| 5 | + |
| 6 | +/** |
| 7 | + * @author Jakub Kulhan <[email protected]> |
| 8 | + */ |
| 9 | +final class RabbitConnectionOptions |
| 10 | +{ |
| 11 | + |
| 12 | + /** |
| 13 | + * Hostname or IP address of the server. |
| 14 | + * |
| 15 | + * @var string |
| 16 | + */ |
| 17 | + public $host; |
| 18 | + |
| 19 | + /** |
| 20 | + * Server port. |
| 21 | + * |
| 22 | + * @var int |
| 23 | + */ |
| 24 | + public $port; |
| 25 | + |
| 26 | + /** |
| 27 | + * Available SASL mechanisms. |
| 28 | + * |
| 29 | + * @var SaslMechanismInterface[] |
| 30 | + */ |
| 31 | + public $mechanisms; |
| 32 | + |
| 33 | + /** |
| 34 | + * Server virtual host. |
| 35 | + * |
| 36 | + * @var string |
| 37 | + */ |
| 38 | + public $virtualHost; |
| 39 | + |
| 40 | + /** |
| 41 | + * Heartbeat timeout defines max time the connection will be kept idle. Every `heartbeat` seconds the client will send |
| 42 | + * heartbeat frame to the server. If client doesn't hear from the server in `heartbeat * 2` seconds, the connection |
| 43 | + * is assumed to be dead. |
| 44 | + * |
| 45 | + * @var float |
| 46 | + */ |
| 47 | + public $heartbeat; |
| 48 | + |
| 49 | + /** |
| 50 | + * Timeout to establish the connection (connection parameters tuning, SASL exchange, opening virtual host). |
| 51 | + * |
| 52 | + * @var float |
| 53 | + */ |
| 54 | + public $connectTimeout; |
| 55 | + |
| 56 | + /** |
| 57 | + * Parameters for TLS-secured connections. |
| 58 | + * |
| 59 | + * @var TlsOptions|null |
| 60 | + */ |
| 61 | + public $tls; |
| 62 | + |
| 63 | + public static function new() |
| 64 | + { |
| 65 | + return new static(); |
| 66 | + } |
| 67 | + |
| 68 | + public static function fromUrl(string $url) |
| 69 | + { |
| 70 | + throw new \LogicException("TODO"); |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * @param string $host |
| 75 | + * @return self |
| 76 | + */ |
| 77 | + public function setHost(string $host) |
| 78 | + { |
| 79 | + $this->host = $host; |
| 80 | + return $this; |
| 81 | + } |
| 82 | + |
| 83 | + /** |
| 84 | + * @param int $port |
| 85 | + * @return self |
| 86 | + */ |
| 87 | + public function setPort(int $port) |
| 88 | + { |
| 89 | + $this->port = $port; |
| 90 | + return $this; |
| 91 | + } |
| 92 | + |
| 93 | + /** |
| 94 | + * @param SaslMechanismInterface[] $mechanisms |
| 95 | + * @return self |
| 96 | + */ |
| 97 | + public function setMechanisms(array $mechanisms) |
| 98 | + { |
| 99 | + $this->mechanisms = $mechanisms; |
| 100 | + return $this; |
| 101 | + } |
| 102 | + |
| 103 | + /** |
| 104 | + * @param SaslMechanismInterface $mechanism |
| 105 | + * @return self |
| 106 | + */ |
| 107 | + public function addMechanism(SaslMechanismInterface $mechanism) |
| 108 | + { |
| 109 | + if ($this->mechanisms === null) { |
| 110 | + $this->mechanisms = []; |
| 111 | + } |
| 112 | + |
| 113 | + $this->mechanisms[] = $mechanism; |
| 114 | + |
| 115 | + return $this; |
| 116 | + } |
| 117 | + |
| 118 | + /** |
| 119 | + * @param string $virtualHost |
| 120 | + * @return self |
| 121 | + */ |
| 122 | + public function setVirtualHost(string $virtualHost) |
| 123 | + { |
| 124 | + $this->virtualHost = $virtualHost; |
| 125 | + return $this; |
| 126 | + } |
| 127 | + |
| 128 | + /** |
| 129 | + * @param float $heartbeat |
| 130 | + * @return self |
| 131 | + */ |
| 132 | + public function setHeartbeat(float $heartbeat) |
| 133 | + { |
| 134 | + $this->heartbeat = $heartbeat; |
| 135 | + return $this; |
| 136 | + } |
| 137 | + |
| 138 | + /** |
| 139 | + * @param float $connectTimeout |
| 140 | + * @return self |
| 141 | + */ |
| 142 | + public function setConnectTimeout(float $connectTimeout) |
| 143 | + { |
| 144 | + $this->connectTimeout = $connectTimeout; |
| 145 | + return $this; |
| 146 | + } |
| 147 | + |
| 148 | + /** |
| 149 | + * @param TlsOptions|null $tls |
| 150 | + * @return self |
| 151 | + */ |
| 152 | + public function setTLS(?TlsOptions $tls) |
| 153 | + { |
| 154 | + $this->tls = $tls; |
| 155 | + return $this; |
| 156 | + } |
| 157 | + |
| 158 | +} |
0 commit comments