This adds checks to ensure that explicit sessions and unacknowledged write concerns (explicit or inherited) will not be mixed when executing bulk writes or commands. Additionally, we ensure that command execution does not create its own implicit session (per PHPC-1152) if the effective write concern is unacknowledged.
Note: libmongoc still needs to ensure that it does not create implicit sessions for unacknowledged commands (CDRIVER-2615).
This ensures that phongo_execute_command creates an implicit session (if supported and not explicit session was provided). In turn, this ensures that any command cursor shares the same session as its originating command.
By creating a Session object, we can ensure that the implicit session is destroyed during garbage collection when the last reference is removed.
This corrects the function signatures to return a boolean indicating success instead of an integer (which was cast from a boolean).
Additionally, it restructures phongo_execute_command() to use a cleanup label, in anticipation of implicit session changes.
Execute options are now parsed via php_array functions, which makes the options case-sensitive.
A helper function is now used to convert legacy options for the original three execute methods into an array. This simplifies option parsing in php_phongo.c.
Additionally, Manager methods now perform their own server selection, which means that execute functions in php_phongo.c can rely on a server_id being provided.
Tests have been updated to expect a serverId option when relevant (e.g. query opts). Additionally, error tests for execute methods have been improved so that invalid values for all known options are tested.
This introduces a Session class, which wraps libmongoc's client session object. Additionally, we support a "session" option on Manager and Server execute methods to allow operations to be associated with an explicit session (mostly relevant for causal consistency).
This only updates exceptions where object types are entirely unexpected. For instance, options that expect a BSON document (i.e. array or object) need not use this macro, as any object would be accepted.
Note: generic boolean options (e.g. "ssl") will continue to accept non-boolean types for BC, since we cast via bson_iter_as_bool(). However, RP and WC-specific boolean options (e.g. "slaveOk", "journal") will throw since they previously silently ignored non-boolean values.
In addition to revising read preference tests, this adds new tests for read concern and write concern options.
In CDRIVER-2208, bson_as_json() (used by toJSON()) was reverted to its original output format. Canonical and relaxed extended JSON are now produced by bson_as_canonical_json() and bson_as_relaxed_json(), respectively. This commit removes toExtendedJSON() (added in 980f1fb01a) in favor of the new functions.
Implementations for the BSON functions have been moved to their own file, which is consistent with what we're doing for the APM subscriber functions.