Skip to content

DOCSP-41962 - Stable API #117

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

Conversation

mongoKart
Copy link
Collaborator

@mongoKart mongoKart commented Aug 28, 2024

Adapted from the PyMongo page of the same name

Pull Request Info

PR Reviewing Guidelines

JIRA - https://jira.mongodb.org/browse/DOCSP-41962
Staging - https://preview-mongodbmongokart.gatsbyjs.io/php-library/docsp-41962-stable-api/connect/stable-api/

Self-Review Checklist

  • Is this free of any warnings or errors in the RST?
  • Did you run a spell-check?
  • Did you run a grammar-check?
  • Are all the links working?
  • Are the facets and meta keywords accurate?

Copy link
Collaborator

@norareidy norareidy left a comment

Choose a reason for hiding this comment

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

LGTM with some suggestions

@mongoKart mongoKart requested review from a team and jmikola and removed request for a team September 5, 2024 18:57
// end-specify-v1

// start-stable-api-options
<?php
Copy link
Member

Choose a reason for hiding this comment

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

I don't recall seeing multiple <?php tags in source files from @norareidy's previous PRs. This makes the file itself invalid, unless you intend to add a ?> above (probably between end-specify-v1 and start-stable-api-options since there's no reason to show ?> to a user (they won't use it in their files).

If these source files are ever meant to be executed for correctness (as we do for some existing sources in the PHPLIB docs before the docs team took over), that'd be even more reason to ensure the syntax within is valid.

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 wasn't sure about these. the existing, un-standardized docs (e.g., hhttps://www.mongodb.com/docs/php-library/current/tutorial/gridfs/#uploading-files-with-writable-streamsere) include them in all code samples, so i assumed it was the preferred syntax.

these files will never be executed in toto, so i'm just going to remove these tags.

Copy link
Member

@jmikola jmikola Sep 11, 2024

Choose a reason for hiding this comment

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

the existing, un-standardized docs include them in all code samples

I think that was necessary for syntax highlighting. Note that most of those code blocks are embedded in the RST and weren't being included from a common file (nor do they get automated testing). Speaking just of the GridFS examples, I'll also note that those are all full scripts that can be executed on their own (each constructs a Client).

I think it makes sense to leave <?php at the top of each of your source files. I expect it is also required for the CI workflow to check coding standards.

$uri = "mongodb://<hostname>:<port>";

$driverOptions = [
'serverApi' => new MongoDB\Driver\ServerApi('1', true, true)
Copy link
Member

Choose a reason for hiding this comment

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

@alcaeus: I'm not sure what version of PHPLIB is being targeted here, but if we're bumping to PHP 8.1+ with version 1.20 I think this would be a good opportunity to use named arguments (available in PHP 8.0+) for the the booleans. Consider:

'serverApi' => new MongoDB\Driver\ServerApi('1', strict: true, deprecationErrors: true),

Ignore this suggestion if we need to remain compatible with earlier versions (back to PHP 7.4).

Also, my previous comment about a trailing comma after elements in multi-line arrays also applies here.

Copy link
Member

Choose a reason for hiding this comment

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

I think we can assume newer PHP versions, so using named arguments sounds like a great idea, especially for those boolean flags!

Copy link
Collaborator Author

@mongoKart mongoKart Sep 11, 2024

Choose a reason for hiding this comment

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

love it. helps a ton with readability.

FYI @rustagir and @norareidy

Copy link

netlify bot commented Sep 11, 2024

Deploy Preview for docs-php-library failed. Why did it fail? →

Name Link
🔨 Latest commit 4434310
🔍 Latest deploy log https://app.netlify.com/sites/docs-php-library/deploys/66f469c2d4afbd000804dd4e

// start-stable-api-options
$uri = "mongodb://<hostname>:<port>";

$driverOptions = ['serverApi' => new MongoDB\Driver\ServerApi('1', strict: true, deprecationErrors: true)];
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If I wanted to split this line into multiple, shorter lines, how would I do that?

Copy link
Member

Choose a reason for hiding this comment

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

I think this would be readable:

$uri = "mongodb://<hostname>:<port>";

$serverApi = new MongoDB\Driver\ServerApi('1', strict: true, deprecationErrors: true);
$driverOptions = ['serverApi' => $serverApi];

$client = new MongoDB\Client($uri, [], $driverOptions);

I also think the previous example could benefit from an extra newline before $client = ....


If you want to break ServerApi across multiple lines, you can do something like:

$serverApi = new MongoDB\Driver\ServerApi(
    '1',
    strict: true,
    deprecationErrors: true,
);

PHP 8.0 allows trailing commas in parameter lists (consistent with what we'd do for multi-line arrays): https://php.watch/versions/8.0/trailing-comma-parameter-use-list

If that's too much wrapping, you could also do this:

$driverOptions = [
    'serverApi' => new MongoDB\Driver\ServerApi('1', strict: true, deprecationErrors: true),
];

That said, I don't think either of these are better than just assigning $serverApi on its own line as I did in the first suggestion.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

thanks!

@mongoKart mongoKart requested a review from jmikola September 11, 2024 17:30
// start-stable-api-options
$uri = "mongodb://<hostname>:<port>";

$driverOptions = ['serverApi' => new MongoDB\Driver\ServerApi('1', strict: true, deprecationErrors: true)];
Copy link
Member

Choose a reason for hiding this comment

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

I think this would be readable:

$uri = "mongodb://<hostname>:<port>";

$serverApi = new MongoDB\Driver\ServerApi('1', strict: true, deprecationErrors: true);
$driverOptions = ['serverApi' => $serverApi];

$client = new MongoDB\Client($uri, [], $driverOptions);

I also think the previous example could benefit from an extra newline before $client = ....


If you want to break ServerApi across multiple lines, you can do something like:

$serverApi = new MongoDB\Driver\ServerApi(
    '1',
    strict: true,
    deprecationErrors: true,
);

PHP 8.0 allows trailing commas in parameter lists (consistent with what we'd do for multi-line arrays): https://php.watch/versions/8.0/trailing-comma-parameter-use-list

If that's too much wrapping, you could also do this:

$driverOptions = [
    'serverApi' => new MongoDB\Driver\ServerApi('1', strict: true, deprecationErrors: true),
];

That said, I don't think either of these are better than just assigning $serverApi on its own line as I did in the first suggestion.

mongoKart and others added 2 commits September 24, 2024 08:29
Co-authored-by: Jeremy Mikola <jmikola@gmail.com>
@mongoKart mongoKart requested a review from jmikola September 24, 2024 13:44
@mongoKart mongoKart merged commit f31eb3e into mongodb:php-standardization Sep 25, 2024
0 of 5 checks passed
@mongoKart mongoKart deleted the docsp-41962-stable-api branch September 25, 2024 19:51
norareidy added a commit that referenced this pull request Sep 27, 2024
* Add PR template

* Scaffolding

* DOCSP-41953: Create a deployment (#93)

* DOCSP-41953: Create a deployment

* toc

* add troubleshoot file

* DOCSP-41954: Create a connection string (#99)

* DOCSP-41954: Create a connection string

* edits

* spacing

* DOCSP-42388: Next steps (#101)

* DOCSP-41975: Retrieve data (#102)

* DOCSP-41975: Retrieve data

* fixes

* quotes

* code fix

* JS feedback

* JT feedback

* code format

* fix

* JT feedback 2

* edit

* DOCSP-41952: Download and Install (#92)

* DOCSP-41952: Download and Install

* edits

* toc, fixes

* AS feedback

* AS feedback 2

* typo

* JT feedback

* DOCSP-41976: Projection guide (#104)

* DOCSP-41976: Projection guide

* edits

* fixes

* code edits, output

* JS feedback

* JT feedback

* DOCSP-41955: Connect to MongoDB (#100)

* DOCSP-41955: Connect to MongoDB

* edits

* edit

* RR feedback

* typo

* code edit

* DOCSP-41974: Specify a query (#103)

* DOCSP-41974: Specify a query

* edits

* output

* fix

* snooty.toml

* RR feedback

* code edits

* DOCSP-41977: Specify documents to return (#105)

* DOCSP-41977: Specify documents to return

* edits

* code output

* toc

* MM feedback, code edits

* edit

* JT feedback

* edit

* test

* MM feedback 2

* DOCSP-41957 - Mongo Client (#106)

Co-authored-by: Rea Rustagi <85902999+rustagir@users.noreply.github.com>

* DOCSP-41960 - TLS (#114)

* DOCSP-41978: Count documents (#108)

* DOCSP-41978: Count documents

* edits

* code ex format

* link

* RR feedback

* DOCSP-41979: Distinct values (#109)

Adds a Distinct Values guide.

* DOCSP-41981: Change streams (#113)

Adds a Change Streams guide.

* DOCSP-41993 Compatibility Table

* test webhook

* toc and sharedincludes

* lang table

* edits

* headings

* retry on shared include

* shared includes

* callout

* help links

* DOCSP-41958 - Connection Targets (#107)

Co-authored-by: Nora Reidy <nora.reidy@mongodb.com>
Co-authored-by: Andreas Braun <git@alcaeus.org>

* tech review

* DOCSP-41968: Update documents (#118)

* DOCSP-41968: Update documents

* snooty fix

* edits

* DOCSP-41967: Insert documents (#116)

* DOCSP-41967: Insert documents

* build

* snooty

* edit

* JS feedback

* JT feedback

* JT feedback 2

* DOCSP-41980: Cursor guide (#110)

* DOCSP-41980: Cursor guide

* edits

* code edits

* output

* vale fix

* MM feedback

* edit

* fix code ex

* edit

* JT feedback

* DOCSP-41988: Aggregation (#115)

* DOCSP-41988: Aggregation

* toc

* edits

* code edit

* JS feedback

* dev center

* JM feedback

* explain api link

* JM feedback 2

* DOCSP-41983: indexes landing pg

* wip

* wip

* MM PR fixes 1

* JM tech review 1

* JM tech review 1

* wip

* wip

* DOCSP-41969: Replace documents (#125)

* DOCSP-41969: Replace documents

* edits

* wording

* SA

* JT feedback

* JM tech review 2

* Add files via upload

* DOCSP-41970: Delete documents (#128)

Adds a guide that shows how to delete documents.

* DOCSP-41984: single field index

* wip

* JS PR fixes 1

* wip

* DOCSP-41986: multikey indexes

* links

* bullet pts

* JS suggestion

* fix whitespace per JM comment

* uncomment

* DOCSP-41985: compound idx

* small fix

* DOCSP-41966: Write operations landing (#135)

* DOCSP-41966: Write operations landing

* edits

* RR feedback

* JT feedback

* JT feedback 2

* gridfs examples

* DOCSP-42026: In use encryption (#142)

* DOCSP-42026: In use encryption

* edit

* DOCSP-41972: GridFS guide (#133)

* DOCSP-41972: GridFS guide

* fixes

* code edits

* fix

* RR feedback

* phpmethod

* fix

* JM most feedback

* alternate upload/download methods

* file revisions

* code fix

* tojson

* edits

* JM feedback 2

* edits

* JM last feedback

* DOCSP-41971: Bulk write (#130)

* DOCSP-41971: Bulk write

* edits

* JS feedback

* api links

* DOCSP-41987: atlas search idx

* resolve todos

* toc

* DOCSP-41963: Databases and collections (#136)

* DOCSP-41963: Databases and collections

* edits

* phpmethod

* code fix

* MW feedback

* fix

* MW feedback 2

* JM feedback

* JM feedback 2

* JS fix

* internal review

* DOCSP-41982: cluster monitoring

* small fixes

* MW PR fixes 1

* test netlify

* spacing

* try using out of repo ref and add back legend

* ou of repo ref

* legend glitch

* JM tech review 1

* single quotes

* links

* vale

* remove older driver version past 1.15

* DOCSP-41991 What's New

* add rest of versions

* fix links

* fix links

* JM tech review 2

* DOCSP-41964: Time series collections (#138)

* DOCSP-41964: Time series collections

* toc

* edits

* keywords

* SA feedback

* JT feedback

* JM final fixes

* review comments

* typo

* DOCSP-41973 Read Landing Page

* review comments

* vale errors

* small thing

* full page with ex

* add page

* meta

* DOCSP-41965: Read and write settings (#146)

* DOCSP-41965: Read and write settings

* more info

* edits

* edits

* headers

* fix link

* fix

* RR feedback

* api docs

* fix

* fix

* DOCSP-41950: Landing page (#150)

* DOCSP-41950: Landing page

* fix build errors

* fixes, data formats

* toc

* fix

* data formats folder

* RR feedback

* fix

* remove file

* edit sample app intro

* change links in count sections

* update sample app intro

* DOCSP-41990: Authentication mechanisms (#139)

* DOCSP-41990: Authentication mechanisms

* client tabs

* edits

* edits

* add info

* reduce repetition

* add section

* fix link

* MW feedback

* fix

* JM most feedback

* move to code file

* more JM edits

* JM feedback 2

* DOCSP-41989: Security landing page (#149)

* DOCSP-41989: Security landing page

* more info

* edits

* snooty.toml

* edits

* RR feedback

* JM feedback

* DOCSP-41962 - Stable API (#117)

Co-authored-by: Jeremy Mikola <jmikola@gmail.com>

* DOCSP-41992 Upgrade versions

* toc

* edits

* how to upgrade sections

* style

* edit

* edit

* review comments

* ref

* Revise descriptions for server opening/closed events

* DOCSP-43204: Connection landing page (#147)

* DOCSP-43204: Connection landing page

* toc edit

* edits

* remove compression

* fix

* sample app

* snooty

* JM feedback

* replica set

* JM feedback 2

* JM last feedback

* DOCSP-43819: php 1.20 release

* fix

* DOCSP-41956: run a command

* wip

* formatting fix

* JS PR fixes 1

* link fix

* style fixes

* JT tech review 1

* wip

* JM tech review

* tree

* api links

* links

* JM tech review 2

* small fixes

* add ext upgrade command

* DOCSP-41995: transaction

* wip

* update code

* NR PR fixes 1

* wip

* add emphasis

* add with_txn() method to api links

* cxn string env

* edit

* JM tech review 1

* remove dupe sc

* tech review

* wrap fix

* edit copy

* DOCSP-41959 - Connection Options (#112)

Co-authored-by: Nora Reidy <nora.reidy@mongodb.com>
Co-authored-by: Jeremy Mikola <jmikola@gmail.com>

* DOCSP-43396: Cleanup (#151)

* DOCSP-43396: Cleanup

* quickstart fix

* code fixes

* edit

* snooty

* edit

* code output

* build log errors

* another build fix

* add info

* upgrade guide to landing

* fix

* driver mentions

* RR feedback

* build fix

* build fix

* php directives

---------

Co-authored-by: Mike Woofter <108414937+mongoKart@users.noreply.github.com>
Co-authored-by: Rea Rustagi <85902999+rustagir@users.noreply.github.com>
Co-authored-by: Lindsey Moore <lindsey.moore@mongodb.com>
Co-authored-by: Andreas Braun <git@alcaeus.org>
Co-authored-by: rustagir <rea.rustagi@mongodb.com>
Co-authored-by: Brandon Ly <brandonly@lostcoding.com>
Co-authored-by: lindseymoore <71525840+lindseymoore@users.noreply.github.com>
Co-authored-by: Jeremy Mikola <jmikola@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants