Skip to content

Commit d8b7877

Browse files
Merge v1.x into v2.x (#1474)
2 parents 36c6fa2 + 8d9f5b5 commit d8b7877

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

src/Client.php

+6
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@
5050
use function array_diff_key;
5151
use function is_array;
5252
use function is_string;
53+
use function sprintf;
54+
use function trigger_error;
55+
56+
use const E_USER_DEPRECATED;
5357

5458
class Client
5559
{
@@ -223,6 +227,8 @@ public function dropDatabase(string $databaseName, array $options = []): array|o
223227
{
224228
if (! isset($options['typeMap'])) {
225229
$options['typeMap'] = $this->typeMap;
230+
} else {
231+
@trigger_error(sprintf('The function %s() will return nothing in mongodb/mongodb v2.0, the "typeMap" option is deprecated', __FUNCTION__), E_USER_DEPRECATED);
226232
}
227233

228234
$server = select_server_for_write($this->manager, $options);

src/Collection.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ public function distinct(string $fieldName, array|object $filter = [], array $op
516516
public function drop(array $options = []): array|object
517517
{
518518
$options = $this->inheritWriteOptions($options);
519-
$options = $this->inheritTypeMap($options);
519+
$options = $this->inheritTypeMap($options, __FUNCTION__);
520520

521521
$server = select_server_for_write($this->manager, $options);
522522

@@ -552,7 +552,7 @@ public function dropIndex(string|IndexInfo $indexName, array $options = []): arr
552552
}
553553

554554
$options = $this->inheritWriteOptions($options);
555-
$options = $this->inheritTypeMap($options);
555+
$options = $this->inheritTypeMap($options, __FUNCTION__);
556556

557557
$operation = new DropIndexes($this->databaseName, $this->collectionName, $indexName, $options);
558558

@@ -572,7 +572,7 @@ public function dropIndex(string|IndexInfo $indexName, array $options = []): arr
572572
public function dropIndexes(array $options = []): array|object
573573
{
574574
$options = $this->inheritWriteOptions($options);
575-
$options = $this->inheritTypeMap($options);
575+
$options = $this->inheritTypeMap($options, __FUNCTION__);
576576

577577
$operation = new DropIndexes($this->databaseName, $this->collectionName, '*', $options);
578578

@@ -1176,8 +1176,12 @@ private function inheritReadPreference(array $options): array
11761176
return $options;
11771177
}
11781178

1179-
private function inheritTypeMap(array $options): array
1179+
private function inheritTypeMap(array $options, ?string $deprecatedFunction = null): array
11801180
{
1181+
if ($deprecatedFunction !== null && isset($options['typeMap'])) {
1182+
@trigger_error(sprintf('The function %s() will return nothing in mongodb/mongodb v2.0, the "typeMap" option is deprecated', $deprecatedFunction), E_USER_DEPRECATED);
1183+
}
1184+
11811185
// Only inherit the type map if no codec is used
11821186
if (! isset($options['typeMap']) && ! isset($options['codec'])) {
11831187
$options['typeMap'] = $this->typeMap;

src/Database.php

+12
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@
5555
use Throwable;
5656

5757
use function is_array;
58+
use function sprintf;
5859
use function strlen;
60+
use function trigger_error;
61+
62+
use const E_USER_DEPRECATED;
5963

6064
class Database
6165
{
@@ -280,6 +284,8 @@ public function createCollection(string $collectionName, array $options = []): a
280284
{
281285
if (! isset($options['typeMap'])) {
282286
$options['typeMap'] = $this->typeMap;
287+
} else {
288+
@trigger_error(sprintf('The function %s() will return nothing in mongodb/mongodb v2.0, the "typeMap" option is deprecated', __FUNCTION__), E_USER_DEPRECATED);
283289
}
284290

285291
if (! isset($options['writeConcern']) && ! is_in_transaction($options)) {
@@ -323,6 +329,8 @@ public function createEncryptedCollection(string $collectionName, ClientEncrypti
323329
{
324330
if (! isset($options['typeMap'])) {
325331
$options['typeMap'] = $this->typeMap;
332+
} else {
333+
@trigger_error(sprintf('The function %s() will return nothing in mongodb/mongodb v2.0, the "typeMap" option is deprecated', __FUNCTION__), E_USER_DEPRECATED);
326334
}
327335

328336
if (! isset($options['writeConcern']) && ! is_in_transaction($options)) {
@@ -356,6 +364,8 @@ public function drop(array $options = []): array|object
356364
{
357365
if (! isset($options['typeMap'])) {
358366
$options['typeMap'] = $this->typeMap;
367+
} else {
368+
@trigger_error(sprintf('The function %s() will return nothing in mongodb/mongodb v2.0, the "typeMap" option is deprecated', __FUNCTION__), E_USER_DEPRECATED);
359369
}
360370

361371
$server = select_server_for_write($this->manager, $options);
@@ -384,6 +394,8 @@ public function dropCollection(string $collectionName, array $options = []): arr
384394
{
385395
if (! isset($options['typeMap'])) {
386396
$options['typeMap'] = $this->typeMap;
397+
} else {
398+
@trigger_error(sprintf('The function %s() will return nothing in mongodb/mongodb v2.0, the "typeMap" option is deprecated', __FUNCTION__), E_USER_DEPRECATED);
387399
}
388400

389401
$server = select_server_for_write($this->manager, $options);

0 commit comments

Comments
 (0)