|
8 | 8 | use mikemadisonweb\rabbitmq\exceptions\InvalidConfigException; |
9 | 9 | use PhpAmqpLib\Connection\AbstractConnection; |
10 | 10 | use PhpAmqpLib\Connection\AMQPLazyConnection; |
| 11 | +use PhpAmqpLib\Connection\AMQPSSLConnection; |
| 12 | +use Yii; |
11 | 13 | use yii\base\Component; |
| 14 | +use yii\di\NotInstantiableException; |
12 | 15 | use yii\helpers\ArrayHelper; |
13 | 16 |
|
14 | 17 | class Configuration extends Component |
@@ -145,44 +148,53 @@ public function getConfig() : Configuration |
145 | 148 | /** |
146 | 149 | * Get connection service |
147 | 150 | * @param string $connectionName |
148 | | - * @return AbstractConnection |
| 151 | + * @return object|AbstractConnection |
| 152 | + * @throws NotInstantiableException |
| 153 | + * @throws \yii\base\InvalidConfigException |
149 | 154 | */ |
150 | 155 | public function getConnection(string $connectionName = '') : AbstractConnection |
151 | 156 | { |
152 | 157 | if ('' === $connectionName) { |
153 | 158 | $connectionName = self::DEFAULT_CONNECTION_NAME; |
154 | 159 | } |
155 | 160 |
|
156 | | - return \Yii::$container->get(sprintf(self::CONNECTION_SERVICE_NAME, $connectionName)); |
| 161 | + return Yii::$container->get(sprintf(self::CONNECTION_SERVICE_NAME, $connectionName)); |
157 | 162 | } |
158 | 163 |
|
159 | 164 | /** |
160 | 165 | * Get producer service |
161 | 166 | * @param string $producerName |
162 | | - * @return Producer |
| 167 | + * @return Producer|object |
| 168 | + * @throws \yii\base\InvalidConfigException |
| 169 | + * @throws NotInstantiableException |
163 | 170 | */ |
164 | | - public function getProducer(string $producerName) : Producer |
| 171 | + public function getProducer(string $producerName) |
165 | 172 | { |
166 | | - return \Yii::$container->get(sprintf(self::PRODUCER_SERVICE_NAME, $producerName)); |
| 173 | + return Yii::$container->get(sprintf(self::PRODUCER_SERVICE_NAME, $producerName)); |
167 | 174 | } |
168 | 175 |
|
169 | 176 | /** |
170 | 177 | * Get consumer service |
171 | 178 | * @param string $consumerName |
172 | | - * @return Consumer |
| 179 | + * @return Consumer|object |
| 180 | + * @throws NotInstantiableException |
| 181 | + * @throws \yii\base\InvalidConfigException |
173 | 182 | */ |
174 | | - public function getConsumer(string $consumerName) : Consumer |
| 183 | + public function getConsumer(string $consumerName) |
175 | 184 | { |
176 | | - return \Yii::$container->get(sprintf(self::CONSUMER_SERVICE_NAME, $consumerName)); |
| 185 | + return Yii::$container->get(sprintf(self::CONSUMER_SERVICE_NAME, $consumerName)); |
177 | 186 | } |
178 | 187 |
|
179 | 188 | /** |
180 | 189 | * Get routing service |
181 | | - * @return Routing |
| 190 | + * @param AbstractConnection $connection |
| 191 | + * @return Routing|object|string |
| 192 | + * @throws NotInstantiableException |
| 193 | + * @throws \yii\base\InvalidConfigException |
182 | 194 | */ |
183 | | - public function getRouting(AbstractConnection $connection) : Routing |
| 195 | + public function getRouting(AbstractConnection $connection) |
184 | 196 | { |
185 | | - return \Yii::$container->get(Configuration::ROUTING_SERVICE_NAME, ['conn' => $connection]); |
| 197 | + return Yii::$container->get(Configuration::ROUTING_SERVICE_NAME, ['conn' => $connection]); |
186 | 198 | } |
187 | 199 |
|
188 | 200 | /** |
@@ -261,6 +273,12 @@ protected function validateRequired() |
261 | 273 | if (isset($connection['type']) && !is_subclass_of($connection['type'], AbstractConnection::class)) { |
262 | 274 | throw new InvalidConfigException('Connection type should be a subclass of PhpAmqpLib\Connection\AbstractConnection.'); |
263 | 275 | } |
| 276 | + if (!empty($connection['ssl_context']) && empty($connection['type'])) { |
| 277 | + throw new InvalidConfigException('If you are using a ssl connection, the connection type must be AMQPSSLConnection::class'); |
| 278 | + } |
| 279 | + if (!empty($connection['ssl_context']) && $connection['type'] !== AMQPSSLConnection::class) { |
| 280 | + throw new InvalidConfigException('If you are using a ssl connection, the connection type must be AMQPSSLConnection::class'); |
| 281 | + } |
264 | 282 | } |
265 | 283 |
|
266 | 284 | foreach ($this->exchanges as $exchange) { |
|
0 commit comments