Allow forcing socket type via driver configuration #284
+117
−6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add Explicit Socket Type Configuration
Overview
This PR enables users to explicitly choose between Socket and Stream connection factories via driver configuration, while maintaining full backwards compatibility with auto-detection as the default behavior.
Problem
Previously, the connection factory type was determined solely by automatic detection via
extension_loaded('sockets')at the singleton level. Users had no way to override this behavior, even if they wanted to force a specific connection type for performance, debugging, or compatibility reasons.Solution
Added a new optional
socketTypeconfiguration parameter that allows users to explicitly specify which connection factory to use:'sockets'- Force SocketConnectionFactory (faster, requires PHP sockets extension)'stream'- Force StreamConnectionFactory (always available, slightly slower)null(default) - Auto-detect based on available extensions (existing behavior)Changes
socketTypeproperty with getter/setter methodsgetInstance()to accept preferred socket type parametercreate()to pass socket type to SystemWideConnectionFactorycreate()to extract and pass socket type from configurationUsage Example
// Force Stream factory
$config = DriverConfiguration::default()->withSocketType('stream');
$driver = BoltDriver::create('neo4j://localhost', $config);
// Force Socket factory
$config = DriverConfiguration::default()->withSocketType('sockets');
$driver = BoltDriver::create('neo4j://localhost', $config);
// Auto-detect (default)
$config = DriverConfiguration::default();
$driver = BoltDriver::create('neo4j://localhost', $config);### Implementation Details
Testing
New test coverage:
Backwards Compatibility
Fully backwards compatible - all new parameters default to
nullwhich preserves existing auto-detection behavior.