* PHPC-2242: Return BSON values in BSON class accessors
* PHPC-2243: Drop BSON value class
* PHPC-2244: Return Int64 instances when converting BSON objects to PHP
* First implementation for MongoDB\BSON\Value
* Add is* methods to MongoDB\BSON\Value
* Extract functions to create BSON instances
* Add getters for all BSON types
* Apply code review feedback
* Rename BSON factory functions
* Return bool in BSON factories
* Clean up int64 compatibility macro includes
* Use macro to throw unexpected BSON type exceptions
* Extract int64 tests for BSON value
* Add error test for BSON value factory
* Implement debug output for BSON value instances
* Remove object comparison handler
* Implement tests for cloning BSON value instances
* Add tests for isInt and getInt
* Ensure stdbool.h is included for compat macros
* Refactor phongo_bson_value_to_zval
The new implementation no longer uses a bson_iter_t for simple values, but instantiates BSON objects directly. Arrays and documents are still passed to php_phongo_bson_to_zval_ex for convenience.
* Refactor phongo_zval_to_bson_value
* Return bson_value_t instances in BSON iterator
* Return bson_value_t instances in Document::get
* Return bson_value_t instances in PackedArray::get
* Return BSON type instances in bson_value_t
This includes a small change to return PHP objects for compatibility in ClientEncryption::decrypt and ClientEncryption::encrypt
* Remove obsolete php_phongo_bson_iter_to_zval function
* Use PHP values in debug output
* Comprehensively test all BSON types
* Implement serialisation of BSON Value instances
* Drop isInt and getInt methods from BSON value class
* Always return int64 instances in Value::getInt64
* Update serialisation and debug info for BSON classes
With the new logic, debug output will always show raw BSON data and PHP data for documents and packed arrays. Serialised data will only contain raw BSON data. This also changes Int64 serialisation to always serialise as Int64 instances, regardless of value or platform.
* Create Int64 instances directly
* Add comment explaining extra property in get_debug_info
* Clarify exception message when initialising Value instance
* Simplify invocations of get_properties_hash with string type
* Handle zval conversion error in get_properties_hash
* Add comment noting phongo_bson_value_to_zval will throw
* Fix zval capitalisation
* Handle bson value conversion error on serialisation
* Document exceptions when converting values to zval
* Clean up unused macros
* Add missing __set_state methods
* Test MongoDB\BSON\Value::__set_state()
* Skip __set_state test on PHP 7.2
* Change docblock to regular comment
* Use new BSON value conversion function when encrypting data
Since the encrypted data will always be a BSON binary object, there is no reason to use the legacy function to avoid receiving a Document or PackedArray instance.
* Extract bson to json conversion logic
* PHPC-326: Add class to represent raw BSON document
* PHPC-326: Add class to represent raw BSON array
* Typemaps now support raw BSON type
* Short-circuit encoding of BSON zvals
* PHPC-324: Add BSONIterator class
* Polyfill zend_array_is_list on PHP < 8.1
* Add offset accessors to BSON classes
* Add more tests around iterators and fetching offsets
* Remove compare handler for BSONIterator
* Rename BSONArray to ArrayList
* Rename BSONDocument to Document
* Rename BSONIterator to Iterator
* Implement Document::fromBSONString
* Test BSON document in bson-corpus tests
* Fix ArrayList handling of BSON arrays with wrong keys
* Address code review for bson-corpus tests
* Address code review in ArrayList
* Address code review for Document
* Address code review for Iterator
* Allow BSON iterators to be rewound
* Address code review in tests
* Fix comment explaining php_phongo_bson_append_object
* Remove obsolete php_phongo_bson_append_zval
* More review changes to tests
* Return base64 encoded data when debugging BSON classes
* Allow serialisation of Document and ArrayList
* Add test for iterating past the end of a structure
* Update exception message to contain class name
* Make BSON pclass handling test more complete
* Fix wrong handling of type map in nested structures
* Ensure objects are backed by actual memory
* Validate UTF-8 BSON data before returning it
* Allow ArrayList::toPHP() to accept a different root type map
* Ignore null return type for invalid BSON iterators on PHP < 8
* Throw when calling get on non-existing BSON offsets
* Remove unnecessary length from serialised output
* Refactor names around type map handling
* Use short array syntax in new tests
* Improve test descriptions
* Restructure BSON iterator tests
* Expand BSON class serialisation tests
* Throw exception when iterator is exhausted
The previous method relied on the type system of PHP to throw an exception when accessing the key of an exhausted iterator, but this does not work on non-debug versions of PHP.
* Update test description
* Rename ArrayList class to PackedArray
Revert previous enum instantiation behavior and PersistableEnum trait from de5f1e5a93
Backed enums will be encoded as their case value. Non-backed cannot be encoded and no enums can be encoded at the root level.
Prohibit enums from implementing Persistable and Unserializable.
* Match error message variations between libmongoc 1.23+ and older
This typo was corrected in mongodb/mongo-c-driver@1d7229f0e9 and will appear in the 1.23.0 release.
* PHPC-2103: Report loaded crypt_shared version in phpinfo()
* PHPC-2132: Fix pattern for matching phpinfo() values
Enums serialize like PHP objects with a "name" property (BackedEnum instance will also have a "value") and thus become BSON documents. In order for a document to unserialize back to an enum, it must implement either Unserializable or Persistable. The bsonUnserialize() method serves no purpose for initialization, but it will still be invoked.
This introduces a PersistableEnum trait, which can be used for both Unserializable or Persistable implementations.
Co-authored-by: Sara Golemon <pollita@php.net>
* Add missing macros for declaring arguments
* Add macros to define disabled constructor and __wakeup
* Define arginfo via stubs for BSON classes
* Declare tentative return types in interfaces
* Add correct return type for __set_state methods
* Generate class entries for BSON classes
* Declare Binary class constants in stub file
* Use stubs in exception classes
* Add stubs for monitoring classes
* Fix wrong JsonSerializable class in BSON stubs
* Disable declaration-after-statement
This is necessary to let the generated arginfo files compile
* Use stubs for driver classes
* Fix deprecation messages in tests
* Add missing macro
* Fix tests relying on value injection
* Parse parameters in disabled constructor/wakup function
* Add note about arginfo files to contribution docs
* Add GitHub action to check generated arginfo files
* PHPC-2115: Use DateTimeInterface in UTCDateTime constructor signature
* Don't install mongodb extension in GitHub actions workflows
* Change indentation in stub files
* Use individual #if conditions for each stub method
* Make disabled constructor/wakeup methods static
* Fix bulkWrite parameter name
* Use %d to match property count in tests
* Ensure all classes with disabled serialisation declare __wakeup
* Replace zend_parse_parameters calls with macros
* Fix warning about uninitialized variable
* Fix wrong parameter type in Server::executeBulkWrite
* Add compat macro for Z_PARAM_ARRAY_OR_OBJECT
This also cleans up header includes throughout the project. The order follows: libbson, libmongoc, libmongocrypt, PHP, contrib (e.g. PHP array API), internal modules (e.g. php_phongo.h, phongo_bson.h), and class headers. Quoted strings are used for all but PHP includes, which are always sourced from system directories.
php_phongo.h is now responsible for including config.h and assigning the default logging domain.
* PHPC-2023: Allow observation of TopologyClosedEvent
Observation is only possible for non-persistent clients freed before RSHUTDOWN. This change also allows for reliable testing of ServerClosedEvent.
* PHPC-2030: Test observation of commands issued during client destruction
Command monitoring events can only be observed for non-persistent clients freed before RSHUTDOWN.
* PHPC-1805: Implement ServerDescription class
* PHPC-1910: Implement Server::getServerDescription()
* PHPC-1934: Check for uninitialized intern in ServerDescription get_properties_hash
* PHPC-1925: Change ServerDescription::getType() to return a string
* PHPC-1891: Implement TopologyDescription class
* PHPC-1892: Implement SDAMSubscriber interface
* PHPC-1893: Implement SDAM event classes
* Revise server and topology event classes and tests
Use phongo_objectid_init in getTopologyId() methods. Report topologyId as an ObjectId in debug info. Report TopologyDescription servers as ServerDescription in debug info.
Copy parameters in phongo_serverdescription_init and phongo_topologydescription_init for consistency with other functions (e.g. phongo_readconcern_init). This also creates phongo_serverdescription_init_ex for when we want to skip copying in Server::getServerDescription().
* PHPC-1953: Add tests for debug handlers
* PHPC-1959: Utilize Manager::addSubscriber() in tests
Skip TopologyClosedEvent test (pending PHPC-2023)
* PHPC-1958: Assert same topologyId for SDAM events
* PHPC-2025: Support load balancer in ServerDescription and TopologyDescription
* PHPC-2026: Handle 64-bit lastUpdateTime for 32-bit platforms
Co-authored-by: Tanli Su <46271307+tanlisu@users.noreply.github.com>
Co-authored-by: Andreas Braun <git@alcaeus.org>
Co-authored-by: Tanli Su <tanli.su@gmail.com>
This allows PHPC to defer entirely to libmongoc for cross-option URI validation
Bump libmongoc to 1.21-dev
Build changes are ported from upstream CMake changes (see: CDRIVER-4249)
* PHPC-2009: Support tlsOptions encryption option
This also adds some missing option validation tests for the autoEncryption driver option and Manager::createClientEncryption().
* PHPC-2010: Type validation for autoEncryption.extraOptions
This also consolidates INI functions (and trace logging) into a separate file and ensure that mongoc logging is disabled during GSHUTDOWN (avoiding a potential segfault).
Enable service ID mocking when testing load balancers with HAProxy.
* Use latest version of libmongoc
* Remove deprecated terminology for primary
* Remove deprecated terminology for secondary
* Fix clang-format
* Remove check for legacy field
* Fix missing space in error expectation
* Harden test expectation around primary checks
* Use zend_exception_ce instead of zend_exception_get_default()
zend_exception_get_default() has been deprecated since PHP 7.0. See: php/php-src@f9e9d3a437
* Check retval from php_phongo_set_monitoring_callbacks
This ensures that php_phongo_client_register is never called in the event this method fails (however unlikely).
* Index subscriber HashTable by numeric object handles
This also updates add/removeSubscriber to use the new argument parsing macros from deead9687e.
* PHPC-1804: Manager::addSubscriber and removeSubscriber
Implements per-client event subscribers. Moves existing APM code to a new phongo_apm.c module and adds logic to coordinate dispatching between global and per-client subscribers.
* Introduce MongoDB\Driver\ServerApi
* Accept serverApi driver option
* Introduce create_test_manager factory to create manager
A centralised entry point is required to inject the API_VERSION env variable later.
* Add build variant to test with requireApiVersion=true
* Fix wrong configuration for auth variable
This changed when migrating from our own scripts to drivers-evergreen-tools and was not updated properly, causing all tests to run with auth disabled.
* Declare ZEND_PARSE_PARAMETERS_NONE macro
This macro is missing on PHP < 7.3
* Remove duplicated API param storage
* Add missing semicolons
* Add ZEND_PARSE_PARAMETERS_NON_EX macro
* Extract error handling functionality to separate macros
* Throw if internal mongoc_server_api_t is already initialised
* Use imported namespaces in tools file
* Fix type info for reflection
* Use American English spelling
* Only use typed serialize signature on PHP 8+
* Update PHONGO_PARSE_PARAMETERS_NONE macro for PHP < 7.3
* Remove usage of ZEND_STRL within zend_hash_str_add
This causes compile failures on PHP < 7.3 that I have yet to understand.
* Fix errors in new PHONGO_PARSE_PARAMETERS macros
* v1.9:
PHPC-1739 Move from travis-ci to GitHub Actions (#1199)
PHPC-1774 Fix truncation of PHP_VERSION constant in handshake metadata (#1202)
PHPC-1775 Use correct size for strncpy in when initialising DBPointer (#1203)
* PHPC-1529: Reset libmongocrypt key vault client after forking
* Run ping command instead of find
* Update wrong comment
* Only run tests when libmongocrypt is present
* Add mongocryptd.pid to gitignore
* Fix test failures due to missing mongocryptd
This ensures persistent clients in all threads are freed, not just those in the main thread. Doing so also required that we call mongoc_cleanup and bson_mem_restore_vtable in the final GSHUTDOWN (tracked by an atomic counter).
* Replace client pointers on object structs with Manager references
* Request-scoped Manager registry for APM events
* Ensure Manager is registered regardless of persistent client
* Reset request-scoped clients when forking
* Test for freeing Manager during RSHUTDOWN via subscriber reference
Co-authored-by: Andreas Braun <git@alcaeus.org>
The ReadConcern, ReadPreference, WriteConcern, and BSON classes have no properties beyond pointers to libmongoc/libbson structs; however, all of these classes use get_properties to report fields for var_export (PHPC-850, PHPC-460).
The standard get_gc handler defers to get_properties to collect other zvals for GC inspection. This is problematic for the aforementioned get_properties handlers, since a HashTable of zvals intended for debugging will be returned and those properties will already be freed by our free_object handler (via FREE_HASHTABLE).
Having each class define its own get_gc handler is the first step to fixing this issue. The BSON classes already defined their own get_gc handlers, but erroneously returned the internally cached properties directly.
The second step to fixing this issue is ensuring that get_gc delegates to zend_std_get_properties, as is done in various PHP core extensions. Doing so ensures that we do not leak other zvals that may be assigned as public properties by the application (covered by the second regression test), since zend_std_get_properties will return those for GC inspection.