Skip to content

Commit 36e5bcd

Browse files
committed
Deprecate typeMap on operations without meaningful result
1 parent 0527fa4 commit 36e5bcd

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

src/Client.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ public function dropDatabase(string $databaseName, array $options = [])
228228
{
229229
if (! isset($options['typeMap'])) {
230230
$options['typeMap'] = $this->typeMap;
231+
} else {
232+
@trigger_error(sprintf('The function %s() will return nothing in mongodb/mongodb v2.0, the "typeMap" option is deprecated', __FUNCTION__), E_USER_DEPRECATED);
231233
}
232234

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

src/Collection.php

Lines changed: 8 additions & 4 deletions
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 && 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;

src/Database.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ public function createCollection(string $collectionName, array $options = [])
286286
{
287287
if (! isset($options['typeMap'])) {
288288
$options['typeMap'] = $this->typeMap;
289+
} else {
290+
@trigger_error(sprintf('The function %s() will return nothing in mongodb/mongodb v2.0, the "typeMap" option is deprecated', __FUNCTION__), E_USER_DEPRECATED);
289291
}
290292

291293
if (! isset($options['writeConcern']) && ! is_in_transaction($options)) {
@@ -329,6 +331,8 @@ public function createEncryptedCollection(string $collectionName, ClientEncrypti
329331
{
330332
if (! isset($options['typeMap'])) {
331333
$options['typeMap'] = $this->typeMap;
334+
} else {
335+
@trigger_error(sprintf('The function %s() will return nothing in mongodb/mongodb v2.0, the "typeMap" option is deprecated', __FUNCTION__), E_USER_DEPRECATED);
332336
}
333337

334338
if (! isset($options['writeConcern']) && ! is_in_transaction($options)) {
@@ -362,6 +366,8 @@ public function drop(array $options = [])
362366
{
363367
if (! isset($options['typeMap'])) {
364368
$options['typeMap'] = $this->typeMap;
369+
} else {
370+
@trigger_error(sprintf('The function %s() will return nothing in mongodb/mongodb v2.0, the "typeMap" option is deprecated', __FUNCTION__), E_USER_DEPRECATED);
365371
}
366372

367373
$server = select_server_for_write($this->manager, $options);
@@ -390,6 +396,8 @@ public function dropCollection(string $collectionName, array $options = [])
390396
{
391397
if (! isset($options['typeMap'])) {
392398
$options['typeMap'] = $this->typeMap;
399+
} else {
400+
@trigger_error(sprintf('The function %s() will return nothing in mongodb/mongodb v2.0, the "typeMap" option is deprecated', __FUNCTION__), E_USER_DEPRECATED);
393401
}
394402

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

0 commit comments

Comments
 (0)