Back to Promises

UPGRADING

UPGRADING.md

2.4.12.8 KB
Original Source

Guzzle Promises Upgrade Guide

1.x to 2.0

Guzzle Promises 2.0 is a major release that removes deprecated APIs, raises the minimum PHP version, and adds PHP 7 parameter and return types. Applications that only use the object-oriented API should usually need small changes. Applications that call helper functions, implement package interfaces, extend package classes, or pass invalid argument types need closer review.

PHP Version and Dependencies

Guzzle Promises 2.0 requires PHP ^7.2.5 || ^8.0. Guzzle Promises 1.x supported PHP >=5.5.

PHP 7 Type Hints and Return Types

Type hints and return types were added wherever possible. Please make sure:

  • You pass values of the documented type when calling methods and functions.
  • Classes that implement PromiseInterface, PromisorInterface, or TaskQueueInterface update method signatures to remain compatible.
  • Classes that extend Guzzle Promises classes update any overridden method signatures to remain compatible.
  • Code that expected package-specific exceptions for invalid argument types may now receive PHP TypeError exceptions instead.

Soft-Final Classes

All previously non-final non-exception classes are now final or annotated with @final. If your code extends one of these classes, replace inheritance with composition or implement the relevant interface directly.

Removed Function API

The static API was introduced in 1.4.0 to mitigate problems with functions conflicting between global and local copies of the package. The function API was removed in 2.0.0, along with the Composer files autoload entry that loaded src/functions_include.php.

Replace namespaced function calls with the corresponding static methods in the GuzzleHttp\Promise namespace:

php
// Before:
use function GuzzleHttp\Promise\promise_for;

$promise = promise_for('value');

// After:
use GuzzleHttp\Promise\Create;

$promise = Create::promiseFor('value');
Original FunctionReplacement Method
queueUtils::queue
taskUtils::task
promise_forCreate::promiseFor
rejection_forCreate::rejectionFor
exception_forCreate::exceptionFor
iter_forCreate::iterFor
inspectUtils::inspect
inspect_allUtils::inspectAll
unwrapUtils::unwrap
allUtils::all
someUtils::some
anyUtils::any
settleUtils::settle
eachEach::of
each_limitEach::ofLimit
each_limit_allEach::ofLimitAll
!is_fulfilledIs::pending
is_fulfilledIs::fulfilled
is_rejectedIs::rejected
is_settledIs::settled
coroutineCoroutine::of

For the full 2.0 diff, see https://github.com/guzzle/promises/compare/1.5.3...2.0.0.