- md5
- 2fbd4692b01a1fe726a3d6fb9a0e38e7
- sha1
- a29b7aa77523e5f05e9e047ff79242789158d1cd
- sha256
- 6f4f29509d752d1fc7c9c1da4c70526a5246df95329fc2ee8e1fa5c8d416eeb0
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\HttpClient\Response;
use GuzzleHttp\Promise\Create;
use GuzzleHttp\Promise\PromiseInterface as GuzzlePromiseInterface;
use Http\Promise\Promise as HttplugPromiseInterface;
use Psr\Http\Message\ResponseInterface as Psr7ResponseInterface;
/**
* @author Tobias Nyholm <[email protected]>
*
* @internal
*/
final class HttplugPromise implements HttplugPromiseInterface
{
private GuzzlePromiseInterface $promise;
public function __construct(GuzzlePromiseInterface $promise)
{
$this->promise = $promise;
}
public function then(?callable $onFulfilled = null, ?callable $onRejected = null): self
{
return new self($this->promise->then(
$this->wrapThenCallback($onFulfilled),
$this->wrapThenCallback($onRejected)
));
}
public function cancel(): void
{
$this->promise->cancel();
}
public function getState(): string
{
return $this->promise->getState();
}
/**
* @return Psr7ResponseInterface|mixed
*/
public function wait($unwrap = true): mixed
{
$result = $this->promise->wait($unwrap);
while ($result instanceof HttplugPromiseInterface || $result instanceof GuzzlePromiseInterface) {
$result = $result->wait($unwrap);
}
return $result;
}
private function wrapThenCallback(?callable $callback): ?callable
{
if (null === $callback) {
return null;
}
return static fn ($value) => Create::promiseFor($callback($value));
}
}
The same content is in 87 releases, Joomla 5.1.0-beta1 to 6.0.0-alpha3. See them all, or every version of this file.