guzzlehttp/promises
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
The Guzzle Promises package provides a Promises/A+ implementation that handles promise chaining and resolution iteratively. Thus, it allows for infinite promise chaining while maintaining the stack size constant.
You can install and utilize 'guzzlehttp/promises' in your PHP project by following these steps:
composer require guzzlehttp/promises
Next, import the Promise class from the GuzzleHttp\Promise namespace into your PHP script.
After importing, you can create a new promise using the 'new' keyword and Promise constructor.
Then, you can use methods like 'then', 'wait', 'cancel', 'getState', 'resolve', and 'reject' to interact with your Promise.
Below is a basic usage example:
use GuzzleHttp\Promise\Promise;
$promise = new Promise();
$promise->then(
// $onFulfilled
function ($value) {
echo 'The promise was fulfilled.';
},
// $onRejected
function ($reason) {
echo 'The promise was rejected.';
}
);
Here is an example of resolving a promise:
use GuzzleHttp\Promise\Promise;
$promise = new Promise();
$promise
->then(function ($value) {
// Return a value and don't break the chain
return "Hello, " . $value;
})
->then(function ($value) {
echo $value;
});
$promise->resolve('reader.'); //Will output "Hello, reader."
The documentation for Guzzle Promises can be found in the README file of its GitHub repository. The documentation provides adequate information like package features, API reference, version guidance, installation and usage instructions, and highlights on key implementation notes.