Skip to content

DOCSP-51123: CC edits and cleanup #279

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

Merged
merged 12 commits into from
Jul 2, 2025
Merged
Show file tree
Hide file tree
Changes from 11 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: 3 additions & 3 deletions composer/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "mongodb/docs-php-library",
"description": "MongoDB PHP Library Documentation",
"require": {
"ext-mongodb": "^1.20",
"mongodb/mongodb": "^1.20"
"ext-mongodb": "^2.1",
"mongodb/mongodb": "^2.1"
},
"require-dev": {
"doctrine/coding-standard": "^12.0",
Expand All @@ -15,4 +15,4 @@
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
}
7 changes: 0 additions & 7 deletions source/aggregation.txt
Original file line number Diff line number Diff line change
Expand Up @@ -389,13 +389,6 @@ learn more, see the :ref:`php-atlas-search` guide.
You can perform similarity searches on vector embeddings by using the
Atlas Vector Search feature. To learn more, see the :ref:`php-vector-search` guide.

.. TODO:
Aggregation Tutorials
~~~~~~~~~~~~~~~~~~~~~

.. To view step-by-step explanations of common aggregation tasks, see
.. :ref:`php-aggregation-tutorials-landing`.

API Documentation
~~~~~~~~~~~~~~~~~

Expand Down
30 changes: 27 additions & 3 deletions source/connect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,30 @@ connection to your MongoDB instance:

To learn more about the {+stable-api+}, see the :ref:`php-stable-api` guide.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S: out of scope of this PR but should all of the TLS content go in its own page in the specify options drawer? I have seen this TOC org in other drivers

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put TLS in the Security drawer based on the unified toc spreadsheet. But I should move this content anyway (to the Security landing page)


.. TODO:
Network Compression
-------------------
Network Compression
-------------------

The following code shows how to specify the Snappy, Zlib, and Zstandard
compression algorithms for a connection:

.. tabs::

.. tab:: MongoDB\\Client
:tabid: Client

.. literalinclude:: /includes/usage-examples/connect-code-examples.php
:language: php
:dedent:
:start-after: start-compression-client
:end-before: end-compression-client

.. tab:: Connection URI
:tabid: connectionstring

.. literalinclude:: /includes/usage-examples/connect-code-examples.php
:language: php
:dedent:
:start-after: start-compression-uri
:end-before: end-compression-uri

To learn more about network compression, see the :ref:`php-network-compression` guide.
31 changes: 20 additions & 11 deletions source/data-formats/modeling-bson-data.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ these values into BSON documents when inserting them into a collection.
The following example creates a BSON document that represents the preceding
:ref:`sample BSON document <php-bson-sample>`:

.. literalinclude:: /includes/bson.php
.. literalinclude:: /includes/bson/interact-bson.php
:language: php
:dedent:
:start-after: start-create-doc
Expand All @@ -73,7 +73,7 @@ to the :ref:`sample BSON document <php-bson-sample>`:
- Adds a new ``restaurant_id`` field that has a value of ``12345``
- Changes the ``name`` field value to ``"Galaxy Pizza"``

.. literalinclude:: /includes/bson.php
.. literalinclude:: /includes/bson/interact-bson.php
:language: php
:dedent:
:start-after: start-modify-doc
Expand Down Expand Up @@ -142,7 +142,7 @@ Custom Type Map Example
The following example sets the ``typeMap`` option for the ``restaurants`` collection
that serializes arrays and BSON documents as ``MongoDB\Model\BSONDocument`` objects:

.. literalinclude:: /includes/bson.php
.. literalinclude:: /includes/bson/interact-bson.php
:language: php
:dedent:
:start-after: start-type-map
Expand Down Expand Up @@ -170,7 +170,7 @@ Consider the following ``Person`` class definition, which implements the
``Persistable`` interface and specifies how to serialize and deserialize
object fields as BSON values:

.. literalinclude:: /includes/bson.php
.. literalinclude:: /includes/bson/Person.php
:language: php
:dedent:
:start-after: start-person-class
Expand All @@ -182,7 +182,7 @@ database, and reads it back as an object of the same type:
.. io-code-block::
:copyable:

.. input:: /includes/bson.php
.. input:: /includes/bson/interact-bson.php
:start-after: start-person-serialize
:end-before: end-person-serialize
:language: php
Expand Down Expand Up @@ -245,24 +245,33 @@ and ``bsonUnserialize()`` methods in your class definition.
Example
```````

Consider the following ``User`` class definition, which specifies
logic for serializing and deserializing its fields into BSON values.
The class includes a ``role`` field, which has a backed enum value:
Consider the following backed enum named ``Role``, which has two
integer-valued cases:

.. literalinclude:: /includes/bson.php
.. literalinclude:: /includes/bson/Role.php
:language: php
:emphasize-lines: 15, 24
:dedent:
:start-after: start-backed-enum
:end-before: end-backed-enum

This ``User`` class definition includes a ``role`` field with a ``Role`` enum
value and specifies logic for serializing and deserializing its fields into BSON
values:

.. literalinclude:: /includes/bson/User.php
:language: php
:emphasize-lines: 5
:dedent:
:start-after: start-user-class
:end-before: end-user-class

The following example constructs a ``User`` object with a ``role`` field,
inserts it into the database, and reads it back as an object of the same type:

.. io-code-block::
:copyable:

.. input:: /includes/bson.php
.. input:: /includes/bson/interact-bson.php
:start-after: start-enum-serialize
:end-before: end-enum-serialize
:language: php
Expand Down
5 changes: 2 additions & 3 deletions source/get-started.txt
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,8 @@ The connection string includes the hostname or IP address and
port of your deployment, the authentication mechanism, user credentials
when applicable, and connection options.

.. TODO:
To connect to an instance or deployment not hosted on Atlas, see
:ref:`php-connection-targets`.
To connect to an instance or deployment not hosted on Atlas, see
:ref:`php-connection-targets`.

.. procedure::
:style: connected
Expand Down
117 changes: 0 additions & 117 deletions source/includes/bson.php

This file was deleted.

33 changes: 33 additions & 0 deletions source/includes/bson/Person.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Bson;

// start-person-class
class Person implements MongoDB\BSON\Persistable
{
private \MongoDB\BSON\ObjectId $id;
private \MongoDB\BSON\UTCDateTime $createdAt;

public function __construct(private string $name)
{
$this->id = new \MongoDB\BSON\ObjectId();
$this->createdAt = new \MongoDB\BSON\UTCDateTime();
}

public function bsonSerialize(): array
{
return [
'_id' => $this->id,
'name' => $this->name,
'createdAt' => $this->createdAt,
];
}

public function bsonUnserialize(array $data): void
{
$this->id = $data['_id'];
$this->name = $data['name'];
$this->createdAt = $data['createdAt'];
}
}
// end-person-class
11 changes: 11 additions & 0 deletions source/includes/bson/Role.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Bson;

// start-backed-enum
enum Role: int
{
case USER = 1;
case ADMIN = 2;
}
// end-backed-enum
31 changes: 31 additions & 0 deletions source/includes/bson/User.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Bson;

// start-user-class
class User implements MongoDB\BSON\Persistable
{
public function __construct(
private string $username,
private Role $role,
private MongoDB\BSON\ObjectId $_id = new MongoDB\BSON\ObjectId(),
) {
}

public function bsonSerialize(): array
{
return [
'_id' => $this->_id,
'username' => $this->username,
'role' => $this->role,
];
}

public function bsonUnserialize(array $data): void
{
$this->_id = $data['_id'];
$this->username = $data['username'];
$this->role = Role::from($data['role']);
}
}
// end-user-class
Loading
Loading