diff --git a/MongodbConnectionFactory.php b/MongodbConnectionFactory.php index a5148f1..05fdd89 100644 --- a/MongodbConnectionFactory.php +++ b/MongodbConnectionFactory.php @@ -27,7 +27,7 @@ class MongodbConnectionFactory implements ConnectionFactory * * or * - * mongodb://127.0.0.1:27017/dbname?polling_interval=1000&enqueue_collection=enqueue + * mongodb://127.0.0.1:27017/defaultauthdb?polling_interval=1000&enqueue_database=enqueue&enqueue_collection=enqueue * * @param array|string|null $config */ @@ -38,7 +38,10 @@ public function __construct($config = 'mongodb:') } elseif (is_string($config)) { $config = $this->parseDsn($config); } elseif (is_array($config)) { - $config = $this->parseDsn(empty($config['dsn']) ? 'mongodb:' : $config['dsn']); + $config = array_replace( + $config, + $this->parseDsn(empty($config['dsn']) ? 'mongodb:' : $config['dsn']) + ); } else { throw new \LogicException('The config must be either an array of options, a DSN string or null'); } @@ -86,6 +89,8 @@ public static function parseDsn(string $dsn): array ]; } $config['dsn'] = $dsn; + // FIXME this is NOT a dbname but rather authdb. But removing this would be a BC break. + // see: https://github.com/php-enqueue/enqueue-dev/issues/1027 if (isset($parsedUrl['path']) && '/' !== $parsedUrl['path']) { $pathParts = explode('/', $parsedUrl['path']); //DB name @@ -103,6 +108,9 @@ public static function parseDsn(string $dsn): array if (!empty($queryParts['enqueue_collection'])) { $config['collection_name'] = $queryParts['enqueue_collection']; } + if (!empty($queryParts['enqueue_database'])) { + $config['dbname'] = $queryParts['enqueue_database']; + } } return $config; diff --git a/MongodbProducer.php b/MongodbProducer.php index d27f014..12956f7 100644 --- a/MongodbProducer.php +++ b/MongodbProducer.php @@ -110,7 +110,7 @@ public function send(Destination $destination, Message $message): void $collection = $this->context->getCollection(); $collection->insertOne($mongoMessage); } catch (\Exception $e) { - throw new Exception('The transport has failed to send the message due to some internal error.', null, $e); + throw new Exception('The transport has failed to send the message due to some internal error.', $e->getCode(), $e); } }