Skip to content

Commit

Permalink
Merge pull request #65 from ruudk/do-not-use-deprecated-functions
Browse files Browse the repository at this point in the history
Do not use deprecated GuzzleHttp functions and start testing v2
  • Loading branch information
mcg-web authored Aug 25, 2023
2 parents 333f5eb + 4128cc8 commit ab4fd58
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"php": "^8.0"
},
"require-dev": {
"guzzlehttp/promises": "^1.5.0",
"guzzlehttp/promises": "^1.5.0 || ^2.0.0",
"phpunit/phpunit": "^9.5.10",
"react/promise": "^2.8.0",
"webonyx/graphql-php": "^14.0"
Expand Down
14 changes: 8 additions & 6 deletions lib/promise-adapter/src/Adapter/GuzzleHttpPromiseAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@

namespace Overblog\PromiseAdapter\Adapter;

use GuzzleHttp\Promise\Create;
use GuzzleHttp\Promise\FulfilledPromise;
use GuzzleHttp\Promise\Promise;
use GuzzleHttp\Promise\PromiseInterface;
use GuzzleHttp\Promise\RejectedPromise;
use GuzzleHttp\Promise\Utils;
use Overblog\PromiseAdapter\PromiseAdapterInterface;

/**
Expand All @@ -29,7 +31,7 @@ class GuzzleHttpPromiseAdapter implements PromiseAdapterInterface
*/
public function create(&$resolve = null, &$reject = null, callable $canceller = null)
{
$queue = \GuzzleHttp\Promise\queue();
$queue = Utils::queue();
$promise = new Promise([$queue, 'run'], $canceller);

$reject = [$promise, 'reject'];
Expand All @@ -45,7 +47,7 @@ public function create(&$resolve = null, &$reject = null, callable $canceller =
*/
public function createFulfilled($promiseOrValue = null)
{
$promise = \GuzzleHttp\Promise\promise_for($promiseOrValue);
$promise = Create::promiseFor($promiseOrValue);

return $promise;
}
Expand All @@ -57,7 +59,7 @@ public function createFulfilled($promiseOrValue = null)
*/
public function createRejected($reason)
{
$promise = \GuzzleHttp\Promise\rejection_for($reason);
$promise = Create::rejectionFor($reason);

return $promise;
}
Expand All @@ -69,7 +71,7 @@ public function createRejected($reason)
*/
public function createAll($promisesOrValues)
{
$promise = empty($promisesOrValues) ? $this->createFulfilled($promisesOrValues) : \GuzzleHttp\Promise\all($promisesOrValues);
$promise = empty($promisesOrValues) ? $this->createFulfilled($promisesOrValues) : Utils::all($promisesOrValues);

return $promise;
}
Expand Down Expand Up @@ -107,7 +109,7 @@ public function await($promise = null, $unwrap = false)
}, function ($reason) use (&$exception) {
$exception = $reason;
});
\GuzzleHttp\Promise\queue()->run();
Utils::queue()->run();

if ($exception instanceof \Exception) {
if (!$unwrap) {
Expand All @@ -116,7 +118,7 @@ public function await($promise = null, $unwrap = false)
throw $exception;
}
} else {
\GuzzleHttp\Promise\queue()->run();
Utils::queue()->run();
}

return $resolvedValue;
Expand Down

0 comments on commit ab4fd58

Please sign in to comment.