I am using CI4, php8.0, guzzlehttp/guzzle 7.9.2 & guzzlehttp/promises: 2.0.3. While guzzle works well, when I gets to promises, it fails.
I load up the classes with:
use GuzzleHttp\Client;
use GuzzleHttp\Promise;
I want to settle the promises like below, however, I get Class "GuzzleHttp\Promise" not found
// Wait for all the asynchronous requests to complete
$responses = Promise::settle($promises)->wait();
My composer.json says:
"require": {
"php": "^7.3||^8.0",
"codeigniter4/framework": "^4",
"phpbu/phpbu": "^6.0",
"guzzlehttp/guzzle": "^7.9.2",
"guzzlehttp/promises": "2.0.3",
In vendor, I can clearly see: guzzlehttp->guzzle guzzlehttp->promises
Not sure how to further debug so any pointers appreciated.
First, ensure you are using the correct namespace. Update your use
statements as follows:
use GuzzleHttp\Client;
use GuzzleHttp\Promise\Utils;
Then, update your code to use the Utils
class for handling promises:
// Wait for all the asynchronous requests to complete
$responses = Utils::settle($promises)->wait();
Run the following command to regenerate the Composer autoloader:
composer dump-autoload