Skip to content

Use PSR-17 createRequest() instead of deprecated getMessageFactory()#17

Open
mwansinck wants to merge 1 commit into
geo6:1.xfrom
webstacknl:fix/psr17-drop-message-factory
Open

Use PSR-17 createRequest() instead of deprecated getMessageFactory()#17
mwansinck wants to merge 1 commit into
geo6:1.xfrom
webstacknl:fix/psr17-drop-message-factory

Conversation

@mwansinck

Copy link
Copy Markdown

Problem

bpost::executeQuery() is the only place that still calls the deprecated AbstractHttpProvider::getMessageFactory(). That method returns an Http\Message\MessageFactory, an interface that exists solely in the archived/abandoned php-http/message-factory package. As a result the provider hard-requires that abandoned package at runtime, and fails with:

Interface "Http\Message\MessageFactory" not found

whenever it isn't present (e.g. when consumers prune abandoned dependencies). See #16.

Fix

Switch the request construction to AbstractHttpProvider::createRequest() (from geocoder-php/common-http), which already builds the request through PSR-17 factories and has an identical argument signature ($method, $uri, array $headers = [], ?string $body = null). This is exactly the approach every other geocoder-php provider uses.

-        $request = $this->getMessageFactory()->createRequest(
+        $request = $this->createRequest(
             'POST',
             $url,
             [
                 'Content-Type' => 'application/json',
             ],
             $data
         );

This removes the last reference to Http\Message\MessageFactory, so the provider no longer pulls in php-http/message-factory. No behavioural change — the produced request is identical.

Testing

Verified against a real project: with this change applied and php-http/message-factory removed, the bpost geocoding integration tests (mocked bpost responses) still pass. Without the change they fatal on the missing interface.

Fixes #16

…ssageFactory()

The only call to the deprecated getMessageFactory() was in executeQuery().
getMessageFactory() returns an Http\Message\MessageFactory, an interface that
lives solely in the abandoned/archived php-http/message-factory package, which
forces that dependency at runtime (fatal "Interface 'Http\Message\MessageFactory'
not found" otherwise). See geo6#16.

AbstractHttpProvider::createRequest() (from geocoder-php/common-http) already
builds the request via PSR-17 factories with an identical argument signature,
exactly like every other geocoder-php provider. Switching to it drops the last
dependency on php-http/message-factory with no behavioural change.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.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.

Requires php-http/message which requires php-http/message-factory which is abandoned

1 participant