Skip to content

Require php-http/promise 1.3.0 to be compatible with PHP 8.4 #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"league/oauth2-client": "^2.6.1",
"open-telemetry/sdk": "^1.0.0",
"php": "^7.4 || ^8.0",
"php-http/promise": "~1.2.0",
"php-http/promise": "~1.3.0",
"psr/http-message": "^1.1 || ^2.0",
"ramsey/uuid": "^4.2.3",
"stduritemplate/stduritemplate": "^0.0.53 || ^0.0.54 || ^0.0.55 || ^0.0.56 || ^0.0.57 || ^0.0.59 || ^1.0.0 || ^2.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Microsoft\Kiota\Abstractions\Authentication;

use Http\Promise\Promise;
use Microsoft\Kiota\Abstraction\Promise\Promise;

/**
* Interface AccessTokenProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Microsoft\Kiota\Abstractions\Authentication;

use Http\Promise\FulfilledPromise;
use Http\Promise\Promise;
use Microsoft\Kiota\Abstraction\Promise\FulfilledPromise;
use Microsoft\Kiota\Abstraction\Promise\Promise;
use Microsoft\Kiota\Abstractions\RequestInformation;

class AnonymousAuthenticationProvider implements AuthenticationProvider {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace Microsoft\Kiota\Abstractions\Authentication;

use Http\Promise\Promise;
use Microsoft\Kiota\Abstraction\Promise\Promise;
use Microsoft\Kiota\Abstractions\RequestInformation;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Microsoft\Kiota\Abstractions\Authentication;

use Http\Promise\FulfilledPromise;
use Http\Promise\Promise;
use Microsoft\Kiota\Abstraction\Promise\FulfilledPromise;
use Microsoft\Kiota\Abstraction\Promise\Promise;
use Microsoft\Kiota\Abstractions\RequestInformation;

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/abstractions/src/NativeResponseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Microsoft\Kiota\Abstractions;

use Http\Promise\FulfilledPromise;
use Microsoft\Kiota\Abstraction\Promise\FulfilledPromise;
use Psr\Http\Message\ResponseInterface;
use Http\Promise\Promise;
use Microsoft\Kiota\Abstraction\Promise\Promise;

/**
* Default response handler that returns the PSR-7 Response
Expand Down
2 changes: 1 addition & 1 deletion packages/abstractions/src/RequestAdapter.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace Microsoft\Kiota\Abstractions;

use Http\Promise\Promise;
use Microsoft\Kiota\Abstraction\Promise\Promise;
use Microsoft\Kiota\Abstractions\Serialization\ParseNodeFactory;
use Microsoft\Kiota\Abstractions\Serialization\SerializationWriterFactory;
use Microsoft\Kiota\Abstractions\Store\BackingStoreFactory;
Expand Down
2 changes: 1 addition & 1 deletion packages/abstractions/src/ResponseHandler.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace Microsoft\Kiota\Abstractions;

use Http\Promise\Promise;
use Microsoft\Kiota\Abstraction\Promise\Promise;
use Psr\Http\Message\ResponseInterface;
use Microsoft\Kiota\Abstractions\Serialization\Parsable;

Expand Down
56 changes: 56 additions & 0 deletions packages/abstractions/src/promise/FulfilledPromise.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
declare(strict_types=1);

namespace Microsoft\Kiota\Abstraction\Promise;

/**
* A promise already fulfilled.
*
* @author Joel Wurtz <[email protected]>
*
* @template-covariant T
*
* @implements Promise<T>
*/
class FulfilledPromise implements Promise
{
/**
* @var T
*/
private $result;

/**
* @param T $result
*/
public function __construct($result)
{
$this->result = $result;
}

public function then(?callable $onFulfilled = null, ?callable $onRejected = null)
{
if (null === $onFulfilled) {
return $this;
}

try {
return new self($onFulfilled($this->result));
} catch (\Exception $e) {
return new RejectedPromise($e);
}
}

public function getState()
{
return Promise::FULFILLED;
}

public function wait($unwrap = true)
{
if ($unwrap) {
return $this->result;
}

return NULL;
}
}
54 changes: 54 additions & 0 deletions packages/abstractions/src/promise/Promise.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
declare(strict_types=1);

namespace Microsoft\Kiota\Abstraction\Promise;

/**
* Promise represents a value that may not be available yet, but will be resolved at some point in future.
* It acts like a proxy to the actual value.
*
* This interface is an extension of the promises/a+ specification.
*
* @see https://promisesaplus.com/
*
* @author Joel Wurtz <[email protected]>
* @author Márk Sági-Kazár <[email protected]>
*
* @template-covariant T
*/
interface Promise extends \Http\Promise\Promise
{

/**
* Adds behavior for when the promise is resolved or rejected (response will be available, or error happens).
*
* If you do not care about one of the cases, you can set the corresponding callable to null
* The callback will be called when the value arrived and never more than once.
*
* @param callable(T): V|null $onFulfilled called when a response will be available
* @param callable(\Exception): V|null $onRejected called when an exception occurs
*
* @return Promise<V> a new resolved promise with value of the executed callback (onFulfilled / onRejected)
*
* @template V
*/
public function then(?callable $onFulfilled = null, ?callable $onRejected = null);

/**
* Wait for the promise to be fulfilled or rejected.
*
* When this method returns, the request has been resolved and if callables have been
* specified, the appropriate one has terminated.
*
* When $unwrap is true (the default), the response is returned, or the exception thrown
* on failure. Otherwise, nothing is returned or thrown.
*
* @param bool $unwrap Whether to return resolved value / throw reason or not
*
* @return ($unwrap is true ? T : null) Resolved value, null if $unwrap is set to false
*
* @throws \Exception the rejection reason if $unwrap is set to true and the request failed
*/
public function wait($unwrap = true);

}
53 changes: 53 additions & 0 deletions packages/abstractions/src/promise/RejectedPromise.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
declare(strict_types=1);

namespace Microsoft\Kiota\Abstraction\Promise;

/**
* A rejected promise.
*
* @author Joel Wurtz <[email protected]>
*
* @template-covariant T
*
* @implements Promise<T>
*/
class RejectedPromise implements Promise
{
/**
* @var \Exception
*/
private $exception;

public function __construct(\Exception $exception)
{
$this->exception = $exception;
}

public function then(?callable $onFulfilled = null, ?callable $onRejected = null)
{
if (null === $onRejected) {
return $this;
}

try {
return new FulfilledPromise($onRejected($this->exception));
} catch (\Exception $e) {
return new self($e);
}
}

public function getState()
{
return Promise::REJECTED;
}

public function wait($unwrap = true)
{
if ($unwrap) {
throw $this->exception;
}

return NULL;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Microsoft\Kiota\Abstractions\Tests\Authentication;

use Http\Promise\FulfilledPromise;
use Microsoft\Kiota\Abstraction\Promise\FulfilledPromise;
use Microsoft\Kiota\Abstractions\Authentication\AccessTokenProvider;
use Microsoft\Kiota\Abstractions\Authentication\BaseBearerTokenAuthenticationProvider;
use Microsoft\Kiota\Abstractions\RequestInformation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Microsoft\Kiota\Abstractions\Tests\TestFiles;

use Http\Promise\FulfilledPromise;
use Http\Promise\Promise;
use Microsoft\Kiota\Abstraction\Promise\FulfilledPromise;
use Microsoft\Kiota\Abstraction\Promise\Promise;
use Microsoft\Kiota\Abstractions\RequestAdapter;
use Microsoft\Kiota\Abstractions\RequestInformation;
use Microsoft\Kiota\Abstractions\Serialization\ParseNodeFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Microsoft\Kiota\Authentication\Oauth;

use Http\Promise\Promise;
use Microsoft\Kiota\Abstraction\Promise\Promise;

trait CAEConfigurationTrait
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace Microsoft\Kiota\Authentication\Oauth;

use League\OAuth2\Client\Token\AccessToken;
use Http\Promise\Promise;
use Microsoft\Kiota\Abstraction\Promise\Promise;

/**
* Interface TokenRequestContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@


use Exception;
use Http\Promise\FulfilledPromise;
use Http\Promise\Promise;
use Http\Promise\RejectedPromise;
use Microsoft\Kiota\Abstraction\Promise\FulfilledPromise;
use Microsoft\Kiota\Abstraction\Promise\Promise;
use Microsoft\Kiota\Abstraction\Promise\RejectedPromise;
use InvalidArgumentException;
use League\OAuth2\Client\Provider\AbstractProvider;
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use Http\Promise\FulfilledPromise;
use Microsoft\Kiota\Http\FulfilledPromise;
use InvalidArgumentException;
use League\OAuth2\Client\Token\AccessToken;
use Microsoft\Kiota\Authentication\Cache\InMemoryAccessTokenCache;
Expand Down
2 changes: 1 addition & 1 deletion packages/http/guzzle/src/GuzzleRequestAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Exception;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Psr7\Request;
use Http\Promise\Promise;
use Microsoft\Kiota\Abstraction\Promise\Promise;
use InvalidArgumentException;
use Microsoft\Kiota\Abstractions\ApiClientBuilder;
use Microsoft\Kiota\Abstractions\ApiException;
Expand Down
4 changes: 2 additions & 2 deletions packages/http/guzzle/tests/GuzzleRequestAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Psr7\Utils;
use Http\Promise\FulfilledPromise;
use Http\Promise\Promise;
use Microsoft\Kiota\Abstraction\Promise\FulfilledPromise;
use Microsoft\Kiota\Abstraction\Promise\Promise;
use Microsoft\Kiota\Abstractions\ApiException;
use Microsoft\Kiota\Abstractions\Authentication\AuthenticationProvider;
use Microsoft\Kiota\Abstractions\Enum;
Expand Down