Guzzle 7 Uncaught Error: Call to undefined function GuzzleHttp\Psr7\stream_for()
kupoback opened this issue ยท 4 comments
kupoback commented
When I attempt to get an access token on the latest version of Guzzle, ^7.3
, it errors out giving me the following error:
PHP Fatal error: Uncaught Error: Call to undefined function GuzzleHttp\Psr7\stream_for() in /path/to/project/vendor/kamermans/guzzle-oauth2-subscriber/src/GrantType/ClientCredentials.php:93
Stack trace:
#0 /path/to/project/vendor/kamermans/guzzle-oauth2-subscriber/src/GrantType/ClientCredentials.php(57): kamermans\OAuth2\GrantType\ClientCredentials->getPostBody()
#1 /path/to/project/vendor/kamermans/guzzle-oauth2-subscriber/src/OAuth2Handler.php(285): kamermans\OAuth2\GrantType\ClientCredentials->getRawData(Object(kamermans\OAuth2\Signer\ClientCredentials\BasicAuth))
#2 /path/to/project/vendor/kamermans/guzzle-oauth2-subscriber/src/OAuth2Handler.php(213): kamermans\OAuth2\OAuth2Handler->requestNewAccessToken()
#3 /path/to/project/public/FileName.php(230): kamermans\OAuth2\OAuth2Handler->getAccessTo in /path/to/project/vendor/kamermans/guzzle-oauth2-subscriber/src/GrantType/ClientCredentials.php on line 93
This is the method I've written, maybe I did something wrong, but dropping the Guzzle version to the latest v6, it works:
protected function grabToken()
{
$client_id = env("CLIENT_ID");
$client_secret = env("CLIENT_SECRET");
try {
$reauth_client = new Client(['base_uri' => 'https://URL.com/auth/connect/token',]);
$reauth_config = [
'client_id' => $client_id,
'client_secret' => $client_secret,
];
$grant_type = new ClientCredentials($reauth_client, $reauth_config);
$refresh_gt = new RefreshToken($reauth_client, $reauth_config);
$oauth = new OAuth2Middleware($grant_type, $refresh_gt);
error_log(print_r($oauth->getAccessToken(), true)); // This is me checking the token's existence
return $oauth;
}
catch (\Exception $exception) {
return rest_ensure_response($exception->getMessage());
}
}
MattApril commented
I fixed it by downgrading guzzlehttp/psr version.
composer require guzzlehttp/psr7:^1.7
stsepelin commented
I fixed it by changing stream_for
to Utils::streamFor
in ClientCredentials.
kamermans commented
Thanks @stsepelin, indeed it is deprecated.
Looking at the code, I see stream_for
became and alias for Utils::streamFor
and deprecated in Guzzle\Psr7 v1.7.0
:
/** @deprecated stream_for will be removed in guzzlehttp/psr7:2.0. Use Utils::streamFor instead.
*/
function stream_for($resource = '', array $options = [])
{
return Utils::streamFor($resource, $options);
}
I'll put in a conditional to resolve this. Thanks for reporting this @kupoback!