Skip to content

feat: add support for Guzzle 8 #9377

Draft
GrahamCampbell wants to merge 1 commit into
googleapis:mainfrom
GrahamCampbell:guzzle-8
Draft

feat: add support for Guzzle 8 #9377
GrahamCampbell wants to merge 1 commit into
googleapis:mainfrom
GrahamCampbell:guzzle-8

Conversation

@GrahamCampbell

Copy link
Copy Markdown
Contributor

Guzzle 8.0.0 was released on July 20th. Lots of people want to use it, and thus popular packages in the ecosystem like this one need to be updated to support it, so here I am, adding support. :)

Comment thread Gax/phpstan.neon.dist Outdated
Comment thread Gax/src/ApiException.php
$res = $ex->getResponse();
// Guzzle 7 carries the response on RequestException, Guzzle 8 only on
// its ResponseException subclass, hence the method_exists() check.
$res = method_exists($ex, 'getResponse') ? $ex->getResponse() : null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there no way to use instanceof here instead using the appropriate subclass? Using method_exists seems a little hacky

@GrahamCampbell GrahamCampbell Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because of the need to keep Guzzle 7 support. Guzzle 7 has RequestException and Guzzle 8 and both RequestException and ResponseException. RequestException in Guzzle 7 has getResponse, but only ResponseException in Guzzle 8 has getResponse. After dropping Guzzle 7 at some point in the future, this can be replaced with an instanceof ResponseException


Guzzle 7.x uses this hierarchy:

. \RuntimeException
└── TransferException (implements GuzzleException)
    ├── ConnectException (implements NetworkExceptionInterface)
    └── RequestException (implements RequestExceptionInterface)
        ├── BadResponseException
        │   ├── ClientException
        │   └── ServerException
        └── TooManyRedirectsException

Guzzle 8.0 uses this hierarchy:

. \RuntimeException
└── TransferException (implements GuzzleException)
    ├── HandlerClosedException
    ├── NetworkException (implements NetworkExceptionInterface)
    │   ├── ConnectException
    │   │   └── ConnectTimeoutException
    │   └── NetworkTimeoutException
    └── RequestException (implements RequestExceptionInterface)
        └── ResponseException
            ├── BadResponseException
            │   ├── ClientException
            │   └── ServerException
            ├── ResponseTransferException
            │   └── ResponseTimeoutException
            └── TooManyRedirectsException

Signed-off-by: Graham Campbell <hello@gjcampbell.co.uk>
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