Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPLIB-1538 Deprecate typeMap on operations without meaningful result #1473

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
use function array_diff_key;
use function is_array;
use function is_string;
use function sprintf;
use function trigger_error;

use const E_USER_DEPRECATED;

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

$server = select_server_for_write($this->manager, $options);
Expand Down
12 changes: 8 additions & 4 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ public function distinct(string $fieldName, array|object $filter = [], array $op
public function drop(array $options = [])
{
$options = $this->inheritWriteOptions($options);
$options = $this->inheritTypeMap($options);
$options = $this->inheritTypeMap($options, __FUNCTION__);

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

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

$options = $this->inheritWriteOptions($options);
$options = $this->inheritTypeMap($options);
$options = $this->inheritTypeMap($options, __FUNCTION__);

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

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

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

Expand Down Expand Up @@ -1212,8 +1212,12 @@ private function inheritReadPreference(array $options): array
return $options;
}

private function inheritTypeMap(array $options): array
private function inheritTypeMap(array $options, ?string $deprecatedFunction = null): array
{
if ($deprecatedFunction !== null && isset($options['typeMap'])) {
@trigger_error(sprintf('The function %s() will return nothing in mongodb/mongodb v2.0, the "typeMap" option is deprecated', $deprecatedFunction), E_USER_DEPRECATED);
}

// Only inherit the type map if no codec is used
if (! isset($options['typeMap']) && ! isset($options['codec'])) {
$options['typeMap'] = $this->typeMap;
Expand Down
12 changes: 12 additions & 0 deletions src/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@
use Traversable;

use function is_array;
use function sprintf;
use function strlen;
use function trigger_error;

use const E_USER_DEPRECATED;

class Database
{
Expand Down Expand Up @@ -286,6 +290,8 @@ public function createCollection(string $collectionName, array $options = [])
{
if (! isset($options['typeMap'])) {
$options['typeMap'] = $this->typeMap;
} else {
@trigger_error(sprintf('The function %s() will return nothing in mongodb/mongodb v2.0, the "typeMap" option is deprecated', __FUNCTION__), E_USER_DEPRECATED);
}

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

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

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

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