Skip to content

Commit bf85cb9

Browse files
PHPLIB-748: Support 'let' option for multiple CRUD commands (#910)
* Updating all necessary classes with new 'let' option support. * Adding actual tests from specifications for "let" option by syncing unified spec tests with mongodb/specifications@1028c34 * Updating tests skips as some features are not yet implemented. * Updating driver version requirements. * Updating Mongo docs. Co-authored-by: Jeremy Mikola <[email protected]>
1 parent 452bc0f commit bf85cb9

35 files changed

+226
-83
lines changed

.evergreen/config.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -591,14 +591,20 @@ axes:
591591
- id: driver-versions
592592
display_name: Driver Version
593593
values:
594+
# TODO: Update to "1.14.0" once PHPC 1.14.0 is released
594595
- id: "oldest-supported"
595-
display_name: "1.13.0"
596+
# display_name: "1.14.0"
597+
display_name: "1.14-dev (master)"
596598
variables:
597-
EXTENSION_VERSION: "1.13.0"
599+
# EXTENSION_VERSION: "1.14.0"
600+
EXTENSION_BRANCH: "master"
601+
# TODO: Update to "1.14.x"/"stable" once PHPC 1.14.0 is released
598602
- id: "latest-stable"
599-
display_name: "1.13.x"
603+
# display_name: "1.14.x"
604+
display_name: "1.14-dev (master)"
600605
variables:
601-
EXTENSION_VERSION: "stable"
606+
# EXTENSION_VERSION: "stable"
607+
EXTENSION_BRANCH: "master"
602608
- id: "latest-dev"
603609
display_name: "1.14-dev (master)"
604610
variables:

.github/workflows/coding-standards.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
php-version:
2121
- "7.4"
2222
driver-version:
23-
- "stable"
23+
- "mongodb/mongo-php-driver@master"
2424

2525
steps:
2626
- name: "Checkout"

.github/workflows/tests.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,24 @@ jobs:
2727
mongodb-version:
2828
- "4.4"
2929
driver-version:
30-
- "stable"
30+
- "mongodb/mongo-php-driver@master"
3131
topology:
3232
- "server"
3333
include:
3434
- os: "ubuntu-20.04"
3535
php-version: "8.0"
3636
mongodb-version: "5.0"
37-
driver-version: "stable"
37+
driver-version: "mongodb/mongo-php-driver@master"
3838
topology: "server"
3939
- os: "ubuntu-20.04"
4040
php-version: "8.0"
4141
mongodb-version: "4.4"
42-
driver-version: "stable"
42+
driver-version: "mongodb/mongo-php-driver@master"
4343
topology: "replica_set"
4444
- os: "ubuntu-20.04"
4545
php-version: "8.0"
4646
mongodb-version: "4.4"
47-
driver-version: "stable"
47+
driver-version: "mongodb/mongo-php-driver@master"
4848
topology: "sharded_cluster"
4949

5050
steps:

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"php": "^7.2 || ^8.0",
1313
"ext-hash": "*",
1414
"ext-json": "*",
15-
"ext-mongodb": "^1.13.0",
15+
"ext-mongodb": "^1.14.0",
1616
"jean85/pretty-package-versions": "^1.2 || ^2.0.1",
1717
"symfony/polyfill-php80": "^1.19"
1818
},

docs/includes/apiargs-MongoDBCollection-method-aggregate-option.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ post: |
2929
.. versionadded:: 1.3
3030
---
3131
source:
32-
file: apiargs-aggregate-option.yaml
32+
file: apiargs-common-option.yaml
3333
ref: let
3434
post: |
3535
.. versionadded:: 1.9

docs/includes/apiargs-MongoDBCollection-method-bulkWrite-option.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ source:
22
file: apiargs-MongoDBCollection-common-option.yaml
33
ref: bypassDocumentValidation
44
---
5+
source:
6+
file: apiargs-common-option.yaml
7+
ref: let
8+
post: |
9+
.. versionadded:: 1.13
10+
---
511
arg_name: option
612
name: ordered
713
type: boolean

docs/includes/apiargs-MongoDBCollection-method-deleteMany-option.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ post: |
1111
1212
.. versionadded:: 1.7
1313
---
14+
source:
15+
file: apiargs-common-option.yaml
16+
ref: let
17+
post: |
18+
.. versionadded:: 1.13
19+
---
1420
source:
1521
file: apiargs-common-option.yaml
1622
ref: session

docs/includes/apiargs-MongoDBCollection-method-deleteOne-option.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ post: |
1111
1212
.. versionadded:: 1.7
1313
---
14+
source:
15+
file: apiargs-common-option.yaml
16+
ref: let
17+
post: |
18+
.. versionadded:: 1.13
19+
---
1420
source:
1521
file: apiargs-common-option.yaml
1622
ref: session

docs/includes/apiargs-MongoDBCollection-method-find-option.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,4 +257,10 @@ description: |
257257
interface: phpmethod
258258
operation: ~
259259
optional: true
260+
---
261+
source:
262+
file: apiargs-common-option.yaml
263+
ref: let
264+
post: |
265+
.. versionadded:: 1.13
260266
...

docs/includes/apiargs-MongoDBCollection-method-findOne-option.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,10 @@ source:
7575
source:
7676
file: apiargs-MongoDBCollection-method-find-option.yaml
7777
ref: modifiers
78+
---
79+
source:
80+
file: apiargs-common-option.yaml
81+
ref: let
82+
post: |
83+
.. versionadded:: 1.13
7884
...

docs/includes/apiargs-MongoDBCollection-method-findOneAndDelete-option.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ post: |
1919
2020
.. versionadded:: 1.7
2121
---
22+
source:
23+
file: apiargs-common-option.yaml
24+
ref: let
25+
post: |
26+
.. versionadded:: 1.13
27+
---
2228
source:
2329
file: apiargs-common-option.yaml
2430
ref: maxTimeMS

docs/includes/apiargs-MongoDBCollection-method-findOneAndReplace-option.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ source:
2727
file: apiargs-MongoDBCollection-common-option.yaml
2828
ref: bypassDocumentValidation
2929
---
30+
source:
31+
file: apiargs-common-option.yaml
32+
ref: let
33+
post: |
34+
.. versionadded:: 1.13
35+
---
3036
arg_name: option
3137
name: returnDocument
3238
type: integer

docs/includes/apiargs-MongoDBCollection-method-findOneAndUpdate-option.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ source:
3333
file: apiargs-MongoDBCollection-common-option.yaml
3434
ref: bypassDocumentValidation
3535
---
36+
source:
37+
file: apiargs-common-option.yaml
38+
ref: let
39+
post: |
40+
.. versionadded:: 1.13
41+
---
3642
arg_name: option
3743
name: returnDocument
3844
type: integer

docs/includes/apiargs-MongoDBCollection-method-replaceOne-option.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ post: |
1919
2020
.. versionadded:: 1.6
2121
---
22+
source:
23+
file: apiargs-common-option.yaml
24+
ref: let
25+
post: |
26+
.. versionadded:: 1.13
27+
---
2228
source:
2329
file: apiargs-common-option.yaml
2430
ref: session

docs/includes/apiargs-MongoDBCollection-method-updateMany-option.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ post: |
2525
2626
.. versionadded:: 1.6
2727
---
28+
source:
29+
file: apiargs-common-option.yaml
30+
ref: let
31+
post: |
32+
.. versionadded:: 1.13
33+
---
2834
source:
2935
file: apiargs-common-option.yaml
3036
ref: session

docs/includes/apiargs-MongoDBCollection-method-updateOne-option.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ post: |
2525
2626
.. versionadded:: 1.6
2727
---
28+
source:
29+
file: apiargs-common-option.yaml
30+
ref: let
31+
post: |
32+
.. versionadded:: 1.13
33+
---
2834
source:
2935
file: apiargs-common-option.yaml
3036
ref: session

docs/includes/apiargs-MongoDBDatabase-method-aggregate-option.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ source:
2323
ref: hint
2424
---
2525
source:
26-
file: apiargs-aggregate-option.yaml
26+
file: apiargs-common-option.yaml
2727
ref: let
2828
post: |
2929
.. versionadded:: 1.9

docs/includes/apiargs-aggregate-option.yaml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,4 @@ description: |
4545
interface: phpmethod
4646
operation: ~
4747
optional: true
48-
---
49-
arg_name: option
50-
name: let
51-
type: array|object
52-
description: |
53-
Map of parameter names and values. Values must be constant or closed
54-
expressions that do not reference document fields. Parameters can then be
55-
accessed as variables in an aggregate expression context (e.g. ``$$var``).
56-
57-
This is not supported for server versions prior to 5.0 and will result in an
58-
exception at execution time if used.
59-
interface: phpmethod
60-
operation: ~
61-
optional: true
6248
...

docs/includes/apiargs-common-option.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@ operation: ~
2424
optional: true
2525
---
2626
arg_name: option
27+
name: let
28+
type: array|object
29+
description: |
30+
Map of parameter names and values. Values must be constant or closed
31+
expressions that do not reference document fields. Parameters can then be
32+
accessed as variables in an aggregate expression context (e.g. ``$$var``).
33+
34+
This is not supported for server versions prior to 5.0 and will result in an
35+
exception at execution time if used.
36+
interface: phpmethod
37+
operation: ~
38+
optional: true
39+
---
40+
arg_name: option
2741
name: maxTimeMS
2842
type: integer
2943
description: |

src/Operation/BulkWrite.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ class BulkWrite implements Executable
107107
* performing the remaining writes. If false, when a write fails,
108108
* continue with the remaining writes, if any. The default is true.
109109
*
110+
* * let (document): Map of parameter names and values. Values must be
111+
* constant or closed expressions that do not reference document fields.
112+
* Parameters can then be accessed as variables in an aggregate
113+
* expression context (e.g. "$$var").
114+
*
110115
* * session (MongoDB\Driver\Session): Client session.
111116
*
112117
* * writeConcern (MongoDB\Driver\WriteConcern): Write concern.
@@ -275,6 +280,10 @@ public function __construct($databaseName, $collectionName, array $operations, a
275280
throw InvalidArgumentException::invalidType('"writeConcern" option', $options['writeConcern'], WriteConcern::class);
276281
}
277282

283+
if (isset($options['let']) && ! is_array($options['let']) && ! is_object($options['let'])) {
284+
throw InvalidArgumentException::invalidType('"let" option', $options['let'], 'array or object');
285+
}
286+
278287
if (isset($options['bypassDocumentValidation']) && ! $options['bypassDocumentValidation']) {
279288
unset($options['bypassDocumentValidation']);
280289
}
@@ -348,6 +357,10 @@ private function createBulkWriteOptions()
348357
$options['bypassDocumentValidation'] = $this->options['bypassDocumentValidation'];
349358
}
350359

360+
if (isset($this->options['let'])) {
361+
$options['let'] = (object) $this->options['let'];
362+
}
363+
351364
return $options;
352365
}
353366

src/Operation/Delete.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ class Delete implements Executable, Explainable
7575
* This is not supported for server versions < 4.4 and will result in an
7676
* exception at execution time if used.
7777
*
78+
* * let (document): Map of parameter names and values. Values must be
79+
* constant or closed expressions that do not reference document fields.
80+
* Parameters can then be accessed as variables in an aggregate
81+
* expression context (e.g. "$$var").
82+
*
7883
* * session (MongoDB\Driver\Session): Client session.
7984
*
8085
* * writeConcern (MongoDB\Driver\WriteConcern): Write concern.
@@ -114,6 +119,10 @@ public function __construct($databaseName, $collectionName, $filter, $limit, arr
114119
throw InvalidArgumentException::invalidType('"writeConcern" option', $options['writeConcern'], WriteConcern::class);
115120
}
116121

122+
if (isset($options['let']) && ! is_array($options['let']) && ! is_object($options['let'])) {
123+
throw InvalidArgumentException::invalidType('"let" option', $options['let'], 'array or object');
124+
}
125+
117126
if (isset($options['writeConcern']) && $options['writeConcern']->isDefault()) {
118127
unset($options['writeConcern']);
119128
}
@@ -150,7 +159,7 @@ public function execute(Server $server)
150159
throw UnsupportedException::writeConcernNotSupportedInTransaction();
151160
}
152161

153-
$bulk = new Bulk();
162+
$bulk = new Bulk($this->createBulkWriteOptions());
154163
$bulk->delete($this->filter, $this->createDeleteOptions());
155164

156165
$writeResult = $server->executeBulkWrite($this->databaseName . '.' . $this->collectionName, $bulk, $this->createExecuteOptions());
@@ -176,6 +185,22 @@ public function getCommandDocument(Server $server)
176185
return $cmd;
177186
}
178187

188+
/**
189+
* Create options for constructing the bulk write.
190+
*
191+
* @see https://php.net/manual/en/mongodb-driver-bulkwrite.construct.php
192+
*/
193+
private function createBulkWriteOptions(): array
194+
{
195+
$options = [];
196+
197+
if (isset($this->options['let'])) {
198+
$options['let'] = (object) $this->options['let'];
199+
}
200+
201+
return $options;
202+
}
203+
179204
/**
180205
* Create options for the delete command.
181206
*

src/Operation/DeleteMany.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ class DeleteMany implements Executable, Explainable
4949
* This is not supported for server versions < 4.4 and will result in an
5050
* exception at execution time if used.
5151
*
52+
* * let (document): Map of parameter names and values. Values must be
53+
* constant or closed expressions that do not reference document fields.
54+
* Parameters can then be accessed as variables in an aggregate
55+
* expression context (e.g. "$$var").
56+
*
5257
* * session (MongoDB\Driver\Session): Client session.
5358
*
5459
* * writeConcern (MongoDB\Driver\WriteConcern): Write concern.

src/Operation/DeleteOne.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ class DeleteOne implements Executable, Explainable
4949
* This is not supported for server versions < 4.4 and will result in an
5050
* exception at execution time if used.
5151
*
52+
* * let (document): Map of parameter names and values. Values must be
53+
* constant or closed expressions that do not reference document fields.
54+
* Parameters can then be accessed as variables in an aggregate
55+
* expression context (e.g. "$$var").
56+
*
5257
* * session (MongoDB\Driver\Session): Client session.
5358
*
5459
* * writeConcern (MongoDB\Driver\WriteConcern): Write concern.

0 commit comments

Comments
 (0)