Skip to content

fix: compatibility with new version of guzzle (guzzle > 5.3.0 & PHP >= 8) #2670

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

emanuelgomez-s1
Copy link

This PR addresses a compatibility issue in the Google\Http\REST class related to legacy support for GuzzleHttp\Message\ResponseInterface, which was removed in Guzzle 6+. The existing code conditionally checks for this obsolete interface and attempts to convert responses, but this behavior is unnecessary (and potentially problematic) in modern environments using Guzzle >=6 and PHP 8.

The proposed change removes this outdated compatibility layer and ensures cleaner, future-proof code that aligns.

Thanks for your cooperation @macatapichon

@emanuelgomez-s1 emanuelgomez-s1 requested a review from a team as a code owner May 7, 2025 13:55
Copy link

google-cla bot commented May 7, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@bshaffer
Copy link
Contributor

bshaffer commented May 7, 2025

This class is using Psr\Http\Message\ResponseInterface, and not GuzzleHttp\Message\ResponseInterface, so I'm not sure what problem is being solved here. Perhaps you can write a test or provide a code example?

@emanuelgomez-s1
Copy link
Author

emanuelgomez-s1 commented May 8, 2025

Hi @bshaffer, thanks for the feedback!

The issue I'm addressing occurs when using "google/apiclient": "^2.9" together with "guzzlehttp/guzzle": "^7.0.1" and PHP 8. In this setup, I'm encountering a critical runtime error because the \GuzzleHttp\Message\ResponseInterface interface no longer exists in Guzzle 6+:

Captura desde 2025-05-08 09-05-24

Error: Failed opening required '/efs/apps/XXX/model/GuzzleHttp/Message/ResponseInterface.php' (include_path='.:/usr/share/php')

Captura desde 2025-05-08 09-08-33

This stems from the condition in REST::doExecute():

if (
    interface_exists('\GuzzleHttp\Message\ResponseInterface')
    && $response instanceof \GuzzleHttp\Message\ResponseInterface
)

Captura desde 2025-05-08 09-05-02

Even though the class is primarily working with Psr\Http\Message\ResponseInterface, the fallback to \GuzzleHttp\Message\ResponseInterface is what causes the issue on newer setups. Since older versions of Guzzle (e.g., 5.x) are not compatible with PHP 8, referencing interfaces from those versions causes fatal errors in modern environments. My patch updates the condition to a safer and more compatible approach:

if ($response instanceof ResponseInterface && !($response instanceof Response))

This avoids referencing a non-existent interface and maintains compatibility with PSR-7 responses.

Let me know if you'd like me to add a test or more context

@emanuelgomez-s1 emanuelgomez-s1 changed the title Compatibility with new version of guzzle (guzzle > 5.3.0 & PHP >= 8) fix: compatibility with new version of guzzle (guzzle > 5.3.0 & PHP >= 8) May 8, 2025
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.

2 participants