Skip to content

Commit 8d9f5b5

Browse files
authored
Deprecate typeMap on operations without meaningful result (#1473)
1 parent 0527fa4 commit 8d9f5b5

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

Diff for: src/Client.php

+6
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@
4949
use function array_diff_key;
5050
use function is_array;
5151
use function is_string;
52+
use function sprintf;
53+
use function trigger_error;
54+
55+
use const E_USER_DEPRECATED;
5256

5357
class Client
5458
{
@@ -228,6 +232,8 @@ public function dropDatabase(string $databaseName, array $options = [])
228232
{
229233
if (! isset($options['typeMap'])) {
230234
$options['typeMap'] = $this->typeMap;
235+
} else {
236+
@trigger_error(sprintf('The function %s() will return nothing in mongodb/mongodb v2.0, the "typeMap" option is deprecated', __FUNCTION__), E_USER_DEPRECATED);
231237
}
232238

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

Diff for: src/Collection.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ public function distinct(string $fieldName, array|object $filter = [], array $op
524524
public function drop(array $options = [])
525525
{
526526
$options = $this->inheritWriteOptions($options);
527-
$options = $this->inheritTypeMap($options);
527+
$options = $this->inheritTypeMap($options, __FUNCTION__);
528528

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

@@ -560,7 +560,7 @@ public function dropIndex(string|IndexInfo $indexName, array $options = [])
560560
}
561561

562562
$options = $this->inheritWriteOptions($options);
563-
$options = $this->inheritTypeMap($options);
563+
$options = $this->inheritTypeMap($options, __FUNCTION__);
564564

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

@@ -580,7 +580,7 @@ public function dropIndex(string|IndexInfo $indexName, array $options = [])
580580
public function dropIndexes(array $options = [])
581581
{
582582
$options = $this->inheritWriteOptions($options);
583-
$options = $this->inheritTypeMap($options);
583+
$options = $this->inheritTypeMap($options, __FUNCTION__);
584584

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

@@ -1212,8 +1212,12 @@ private function inheritReadPreference(array $options): array
12121212
return $options;
12131213
}
12141214

1215-
private function inheritTypeMap(array $options): array
1215+
private function inheritTypeMap(array $options, ?string $deprecatedFunction = null): array
12161216
{
1217+
if ($deprecatedFunction !== null && isset($options['typeMap'])) {
1218+
@trigger_error(sprintf('The function %s() will return nothing in mongodb/mongodb v2.0, the "typeMap" option is deprecated', $deprecatedFunction), E_USER_DEPRECATED);
1219+
}
1220+
12171221
// Only inherit the type map if no codec is used
12181222
if (! isset($options['typeMap']) && ! isset($options['codec'])) {
12191223
$options['typeMap'] = $this->typeMap;

Diff for: src/Database.php

+12
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@
5555
use Traversable;
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
{
@@ -286,6 +290,8 @@ public function createCollection(string $collectionName, array $options = [])
286290
{
287291
if (! isset($options['typeMap'])) {
288292
$options['typeMap'] = $this->typeMap;
293+
} else {
294+
@trigger_error(sprintf('The function %s() will return nothing in mongodb/mongodb v2.0, the "typeMap" option is deprecated', __FUNCTION__), E_USER_DEPRECATED);
289295
}
290296

291297
if (! isset($options['writeConcern']) && ! is_in_transaction($options)) {
@@ -329,6 +335,8 @@ public function createEncryptedCollection(string $collectionName, ClientEncrypti
329335
{
330336
if (! isset($options['typeMap'])) {
331337
$options['typeMap'] = $this->typeMap;
338+
} else {
339+
@trigger_error(sprintf('The function %s() will return nothing in mongodb/mongodb v2.0, the "typeMap" option is deprecated', __FUNCTION__), E_USER_DEPRECATED);
332340
}
333341

334342
if (! isset($options['writeConcern']) && ! is_in_transaction($options)) {
@@ -362,6 +370,8 @@ public function drop(array $options = [])
362370
{
363371
if (! isset($options['typeMap'])) {
364372
$options['typeMap'] = $this->typeMap;
373+
} else {
374+
@trigger_error(sprintf('The function %s() will return nothing in mongodb/mongodb v2.0, the "typeMap" option is deprecated', __FUNCTION__), E_USER_DEPRECATED);
365375
}
366376

367377
$server = select_server_for_write($this->manager, $options);
@@ -390,6 +400,8 @@ public function dropCollection(string $collectionName, array $options = [])
390400
{
391401
if (! isset($options['typeMap'])) {
392402
$options['typeMap'] = $this->typeMap;
403+
} else {
404+
@trigger_error(sprintf('The function %s() will return nothing in mongodb/mongodb v2.0, the "typeMap" option is deprecated', __FUNCTION__), E_USER_DEPRECATED);
393405
}
394406

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

0 commit comments

Comments
 (0)