Skip to content

Commit 794e726

Browse files
committed
Merge branch 'v1.18' into merge-v1.17-into-v1.18-1715326101426
* v1.18: (50 commits) Enable auto-merge in merge-up workflow (#1295) PHPLIB-1447: Add SBOM lite (#1292) Fix syntax error in docs (#1285) PHPLIB-1163 Create tutorial for using MongoDB with Bref (#1273) (#1282) Create sarif report when running psalm (#1280) Update composer.json and CI matrices for 1.18.0 PHPLIB-1410: Invoke drivers-evergreen-tools scripts with bash (#1267) PHPLIB-1302: Use Composer\InstalledVersions (#1262) PHPLIB-1320: Support "comment" command option in Collection::createIndex() (#1263) PHPLIB-1413: Use env instead of matrix for driver-version (#1261) Fix Markdown heading PHPLIB-1399: Docs examples for agg expr projection (#1260) PHPLIB-1412: Skip range encryption tests on MongoDB 8.0+ (#1259) PHPLIB-1409: Skip $out and mapReduce tests on serverless (#1254) Exclude read-write-concern tests from serverless testing (#1253) PHPLIB-1409: Convert default write concern tests to unified test format (#1252) PHPLIB-1408: Convert ADL spec test to unified test format (#1250) Remove redundant annotations (#1251) PHPLIB-1404: Convert retryable reads spec tests to unified test format (#1247) DOCSP-36627: Additional double backslash fixes for master (#1246) ...
2 parents 96908fa + 720bc05 commit 794e726

15 files changed

+557
-5
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "mongodb/bref-tutorial",
3+
"type": "project",
4+
"license": "MIT",
5+
"repositories": [
6+
{
7+
"type": "path",
8+
"url": "../../..",
9+
"options": {
10+
"symlink": false
11+
}
12+
}
13+
],
14+
"require": {
15+
"bref/bref": "^2.1",
16+
"bref/extra-php-extensions": "^1.4",
17+
"mongodb/mongodb": "@dev"
18+
}
19+
}

source/examples/aws-lambda/index.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
use MongoDB\Client;
4+
5+
require_once __DIR__ . '/vendor/autoload.php';
6+
7+
$uri = getenv('MONGODB_URI');
8+
9+
try {
10+
$client = new Client($uri);
11+
$planets = $client
12+
->selectCollection('sample_guides', 'planets')
13+
->find([], ['sort' => ['orderFromSun' => 1]]);
14+
} catch (Throwable $exception) {
15+
exit($exception->getMessage());
16+
}
17+
18+
?>
19+
<!DOCTYPE html>
20+
<html lang="en">
21+
<head>
22+
<title>MongoDB Planets</title>
23+
</head>
24+
<body>
25+
<ul>
26+
<?php foreach ($planets as $planet) : ?>
27+
<li><?= $planet->name ?></li>
28+
<?php endforeach ?>
29+
</ul>
30+
</body>
31+
</html>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
service: app
2+
3+
provider:
4+
name: aws
5+
region: us-east-1
6+
environment:
7+
MONGODB_URI: ${env:MONGODB_URI}
8+
9+
plugins:
10+
- ./vendor/bref/bref
11+
- ./vendor/bref/extra-php-extensions
12+
13+
functions:
14+
api:
15+
handler: index.php
16+
description: ''
17+
runtime: php-83-fpm
18+
timeout: 28 # in seconds (API Gateway has a timeout of 29 seconds)
19+
events:
20+
- httpApi: '*'
21+
layers:
22+
- ${bref-extra:mongodb-php-83}

source/reference/class/MongoDBClient.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Methods
3030

3131
__construct() </reference/method/MongoDBClient__construct>
3232
__get() </reference/method/MongoDBClient__get>
33+
addSubscriber() </reference/method/MongoDBClient-addSubscriber>
3334
createClientEncryption() </reference/method/MongoDBClient-createClientEncryption>
3435
dropDatabase() </reference/method/MongoDBClient-dropDatabase>
3536
getManager() </reference/method/MongoDBClient-getManager>
@@ -39,13 +40,15 @@ Methods
3940
getWriteConcern() </reference/method/MongoDBClient-getWriteConcern>
4041
listDatabaseNames() </reference/method/MongoDBClient-listDatabaseNames>
4142
listDatabases() </reference/method/MongoDBClient-listDatabases>
43+
removeSubscriber() </reference/method/MongoDBClient-removeSubscriber>
4244
selectCollection() </reference/method/MongoDBClient-selectCollection>
4345
selectDatabase() </reference/method/MongoDBClient-selectDatabase>
4446
startSession() </reference/method/MongoDBClient-startSession>
4547
watch() </reference/method/MongoDBClient-watch>
4648

4749
- :phpmethod:`MongoDB\Client::__construct()`
4850
- :phpmethod:`MongoDB\Client::__get()`
51+
- :phpmethod:`MongoDB\Client::addSubscriber()`
4952
- :phpmethod:`MongoDB\Client::createClientEncryption()`
5053
- :phpmethod:`MongoDB\Client::dropDatabase()`
5154
- :phpmethod:`MongoDB\Client::getManager()`
@@ -55,6 +58,7 @@ Methods
5558
- :phpmethod:`MongoDB\Client::getWriteConcern()`
5659
- :phpmethod:`MongoDB\Client::listDatabaseNames()`
5760
- :phpmethod:`MongoDB\Client::listDatabases()`
61+
- :phpmethod:`MongoDB\Client::removeSubscriber()`
5862
- :phpmethod:`MongoDB\Client::selectCollection()`
5963
- :phpmethod:`MongoDB\Client::selectDatabase()`
6064
- :phpmethod:`MongoDB\Client::startSession()`

source/reference/class/MongoDBGridFSBucket.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ Methods
5555
openDownloadStream() </reference/method/MongoDBGridFSBucket-openDownloadStream>
5656
openDownloadStreamByName() </reference/method/MongoDBGridFSBucket-openDownloadStreamByName>
5757
openUploadStream() </reference/method/MongoDBGridFSBucket-openUploadStream>
58+
registerGlobalStreamWrapperAlias() </reference/method/MongoDBGridFSBucket-registerGlobalStreamWrapperAlias>
5859
rename() </reference/method/MongoDBGridFSBucket-rename>
5960
uploadFromStream() </reference/method/MongoDBGridFSBucket-uploadFromStream>
6061

@@ -78,5 +79,6 @@ Methods
7879
- :phpmethod:`MongoDB\GridFS\Bucket::openDownloadStream()`
7980
- :phpmethod:`MongoDB\GridFS\Bucket::openDownloadStreamByName()`
8081
- :phpmethod:`MongoDB\GridFS\Bucket::openUploadStream()`
82+
- :phpmethod:`MongoDB\GridFS\Bucket::registerGlobalStreamWrapperAlias()`
8183
- :phpmethod:`MongoDB\GridFS\Bucket::rename()`
8284
- :phpmethod:`MongoDB\GridFS\Bucket::uploadFromStream()`
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
================================
2+
MongoDB\\Client::addSubscriber()
3+
================================
4+
5+
.. versionadded:: 1.18
6+
7+
.. default-domain:: mongodb
8+
9+
.. contents:: On this page
10+
:local:
11+
:backlinks: none
12+
:depth: 1
13+
:class: singlecol
14+
15+
Definition
16+
----------
17+
18+
.. phpmethod:: MongoDB\Client::addSubscriber()
19+
20+
Registers a monitoring event subscriber with this Client. The subscriber
21+
will be notified of all events for this Client.
22+
23+
.. code-block:: php
24+
25+
function addSubscriber(MongoDB\Driver\Monitoring\Subscriber $subscriber): void
26+
27+
Parameters
28+
----------
29+
30+
``$subscriber`` : :php:`MongoDB\Driver\Monitoring\Subscriber <class.mongodb-driver-monitoring-subscriber>`
31+
A monitoring event subscriber to register with this Client.
32+
33+
Errors/Exceptions
34+
-----------------
35+
36+
.. include:: /includes/extracts/error-invalidargumentexception.rst
37+
38+
:php:`MongoDB\Driver\Exception\InvalidArgumentException <mongodb-driver-exception-invalidargumentexception>`
39+
if subscriber is a :php:`MongoDB\Driver\Monitoring\LogSubscriber <class.mongodb-driver-monitoring-logsubscriber>`,
40+
since loggers can only be registered globally with
41+
:php:`MongoDB\Driver\Monitoring\addSubscriber <function.mongodb.driver.monitoring.addsubscriber>`.
42+
43+
Behavior
44+
--------
45+
46+
If ``$subscriber`` is already registered with this Client, this function is a
47+
no-op. If ``$subscriber`` is also registered globally, it will still only be
48+
notified once of each event for this Client.
49+
50+
Example
51+
-------
52+
53+
Create a :phpclass:`MongoDB\Driver\Monitoring\CommandSubscriber` that
54+
logs all events:
55+
56+
.. code-block:: php
57+
58+
<?php
59+
60+
use MongoDB\Driver\Monitoring\CommandSubscriber;
61+
use MongoDB\Driver\Monitoring\CommandStartedEvent;
62+
use MongoDB\Driver\Monitoring\CommandSucceededEvent;
63+
use MongoDB\Driver\Monitoring\CommandFailedEvent;
64+
65+
class LogCommandSubscriber implements CommandSubscriber
66+
{
67+
private $stream;
68+
public function __construct($stream)
69+
{
70+
$this->stream = $stream;
71+
}
72+
73+
public function commandStarted(CommandStartedEvent $event): void
74+
{
75+
fwrite($this->stream, sprintf(
76+
'Started command #%d "%s": %s%s',
77+
$event->getRequestId(),
78+
$event->getCommandName(),
79+
Document::fromPHP($event->getCommand())->toCanonicalExtendedJSON(),
80+
PHP_EOL,
81+
));
82+
}
83+
84+
public function commandSucceeded(CommandSucceededEvent $event): void
85+
{
86+
fwrite($this->stream, sprintf(
87+
'Succeeded command #%d "%s" in %d microseconds: %s%s',
88+
$event->getRequestId(),
89+
$event->getCommandName(),
90+
$event->getDurationMicros(),
91+
json_encode($event->getReply()),
92+
PHP_EOL,
93+
));
94+
}
95+
96+
public function commandFailed(CommandFailedEvent $event): void
97+
{
98+
fwrite($this->stream, sprintf(
99+
'Failed command #%d "%s" in %d microseconds: %s%s',
100+
$event->getRequestId(),
101+
$event->getCommandName(),
102+
$event->getDurationMicros(),
103+
$event->getError()->getMessage(),
104+
PHP_EOL,
105+
));
106+
}
107+
}
108+
109+
The subscriber can then be registered with a Client:
110+
111+
.. code-block:: php
112+
113+
<?php
114+
115+
$client = new MongoDB\Client();
116+
$subscriber = new LogCommandSubscriber(STDERR);
117+
118+
$client->addSubscriber($subscriber);
119+
120+
$client->test->users->insertOne(['username' => 'alice']);
121+
122+
The above code will write the following to stderr output:
123+
124+
.. code-block:: text
125+
126+
Started command #1 "insert": { "insert" : "users", "ordered" : true, "$db" : "test", "lsid" : { "id" : { "$binary" : { "base64" : "dKTBhZD7Qvi0vUhvR58mCA==", "subType" : "04" } } }, "documents" : [ { "username" : "alice", "_id" : { "$oid" : "655d1fca12e81018340a4fc2" } } ] }
127+
Succeeded command #1 "insert" in 876 microseconds: {"n":1,"ok":1}
128+
129+
See Also
130+
--------
131+
132+
- :phpmethod:`MongoDB\Client::removeSubscriber()`
133+
- :php:`Application Performance Monitoring (APM) <manual/en/mongodb.tutorial.apm>`
134+
- :php:`MongoDB\Driver\Manager::addSubscriber() <manual/en/mongodb-driver-manager.addsubscriber>`
135+
- :php:`MongoDB\Driver\Monitoring\CommandSubscriber <manual/en/class.mongodb-driver-monitoring-commandsubscriber>`
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
===================================
2+
MongoDB\\Client::removeSubscriber()
3+
===================================
4+
5+
.. versionadded:: 1.18
6+
7+
.. default-domain:: mongodb
8+
9+
.. contents:: On this page
10+
:local:
11+
:backlinks: none
12+
:depth: 1
13+
:class: singlecol
14+
15+
Definition
16+
----------
17+
18+
.. phpmethod:: MongoDB\Client::removeSubscriber()
19+
20+
Unregisters a monitoring event subscriber with this Client.
21+
22+
.. code-block:: php
23+
24+
function removeSubscriber(MongoDB\Driver\Monitoring\Subscriber $subscriber): void
25+
26+
Parameters
27+
----------
28+
29+
``$subscriber`` : :php:`MongoDB\Driver\Monitoring\Subscriber <class.mongodb-driver-monitoring-subscriber>`
30+
A monitoring event subscriber to unregister with this Client.
31+
32+
Errors/Exceptions
33+
-----------------
34+
35+
.. include:: /includes/extracts/error-invalidargumentexception.rst
36+
37+
Behavior
38+
--------
39+
40+
If ``$subscriber`` is not registered with this Client, this function is a no-op.
41+
42+
See Also
43+
--------
44+
45+
- :phpmethod:`MongoDB\Client::addSubscriber()`
46+
- :php:`Application Performance Monitoring (APM) <manual/en/mongodb.tutorial.apm>`
47+
- :php:`MongoDB\Driver\Manager::removeSubscriber() <manual/en/mongodb-driver-manager.addsubscriber>`
48+
- :php:`MongoDB\Driver\Monitoring\CommandSubscriber <manual/en/class.mongodb-driver-monitoring-commandsubscriber>`

source/reference/method/MongoDBDatabase-aggregate.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ running command operations.
163163
$cursor = $database->aggregate(
164164
[
165165
['$currentOp' => []],
166-
['$match' => ['op' => 'command'],
166+
['$match' => ['op' => 'command']],
167167
]
168168
);
169169

source/reference/method/MongoDBDatabase-selectGridFSBucket.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Parameters
5555
- boolean
5656
- Whether to disable automatic MD5 generation when storing files.
5757

58-
Defaults to ``false``.
58+
Defaults to ``false``. Only ``true`` will be supported in 2.0.
5959

6060
.. versionadded:: 1.4
6161

source/reference/method/MongoDBGridFSBucket-openUploadStream.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Parameters
5555
- boolean
5656
- Whether to disable automatic MD5 generation when storing files.
5757

58-
Defaults to ``false``.
58+
Defaults to ``false``. Only ``true`` will be supported in 2.0.
5959

6060
.. versionadded:: 1.4
6161

0 commit comments

Comments
 (0)