4444
4545class Client
4646{
47+ public const DEFAULT_URI = 'mongodb://127.0.0.1/ ' ;
48+
4749 /** @var array */
4850 private static $ defaultTypeMap = [
4951 'array ' => BSONArray::class,
@@ -91,14 +93,14 @@ class Client
9193 * @see https://mongodb.com/docs/manual/reference/connection-string/
9294 * @see https://php.net/manual/en/mongodb-driver-manager.construct.php
9395 * @see https://php.net/manual/en/mongodb.persistence.php#mongodb.persistence.typemaps
94- * @param string $uri MongoDB connection string
95- * @param array $uriOptions Additional connection string options
96- * @param array $driverOptions Driver-specific options
96+ * @param string|null $uri MongoDB connection string. If none is provided, this defaults to self::DEFAULT_URI.
97+ * @param array $uriOptions Additional connection string options
98+ * @param array $driverOptions Driver-specific options
9799 * @throws InvalidArgumentException for parameter/option parsing errors
98100 * @throws DriverInvalidArgumentException for parameter/option parsing errors in the driver
99101 * @throws DriverRuntimeException for other driver errors (e.g. connection errors)
100102 */
101- public function __construct (string $ uri = ' mongodb://127.0.0.1/ ' , array $ uriOptions = [], array $ driverOptions = [])
103+ public function __construct (? string $ uri = null , array $ uriOptions = [], array $ driverOptions = [])
102104 {
103105 $ driverOptions += ['typeMap ' => self ::$ defaultTypeMap ];
104106
@@ -116,7 +118,7 @@ public function __construct(string $uri = 'mongodb://127.0.0.1/', array $uriOpti
116118
117119 $ driverOptions ['driver ' ] = $ this ->mergeDriverInfo ($ driverOptions ['driver ' ] ?? []);
118120
119- $ this ->uri = $ uri ;
121+ $ this ->uri = $ uri ?? self :: DEFAULT_URI ;
120122 $ this ->typeMap = $ driverOptions ['typeMap ' ];
121123
122124 unset($ driverOptions ['typeMap ' ]);
0 commit comments