44
44
45
45
class Client
46
46
{
47
+ public const DEFAULT_URI = 'mongodb://127.0.0.1/ ' ;
48
+
47
49
/** @var array */
48
50
private static $ defaultTypeMap = [
49
51
'array ' => BSONArray::class,
@@ -91,14 +93,14 @@ class Client
91
93
* @see https://mongodb.com/docs/manual/reference/connection-string/
92
94
* @see https://php.net/manual/en/mongodb-driver-manager.construct.php
93
95
* @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
97
99
* @throws InvalidArgumentException for parameter/option parsing errors
98
100
* @throws DriverInvalidArgumentException for parameter/option parsing errors in the driver
99
101
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
100
102
*/
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 = [])
102
104
{
103
105
$ driverOptions += ['typeMap ' => self ::$ defaultTypeMap ];
104
106
@@ -116,7 +118,7 @@ public function __construct(string $uri = 'mongodb://127.0.0.1/', array $uriOpti
116
118
117
119
$ driverOptions ['driver ' ] = $ this ->mergeDriverInfo ($ driverOptions ['driver ' ] ?? []);
118
120
119
- $ this ->uri = $ uri ;
121
+ $ this ->uri = $ uri ?? self :: DEFAULT_URI ;
120
122
$ this ->typeMap = $ driverOptions ['typeMap ' ];
121
123
122
124
unset($ driverOptions ['typeMap ' ]);
0 commit comments