@@ -13,12 +13,12 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | final class MockClientStrategy implements DiscoveryStrategy |
| 15 | 15 | { |
| 16 | - public static function getCandidates($type) |
|
| 17 | - { |
|
| 18 | - if (is_a(HttpClient::class, $type, true) || is_a(HttpAsyncClient::class, $type, true)) { |
|
| 19 | - return [['class' => Mock::class, 'condition' => Mock::class]]; |
|
| 20 | - } |
|
| 16 | + public static function getCandidates($type) |
|
| 17 | + { |
|
| 18 | + if (is_a(HttpClient::class, $type, true) || is_a(HttpAsyncClient::class, $type, true)) { |
|
| 19 | + return [['class' => Mock::class, 'condition' => Mock::class]]; |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - return []; |
|
| 23 | - } |
|
| 22 | + return []; |
|
| 23 | + } |
|
| 24 | 24 | } |
@@ -11,8 +11,7 @@ |
||
| 11 | 11 | * |
| 12 | 12 | * @author Sam Rapaport <[email protected]> |
| 13 | 13 | */ |
| 14 | -final class MockClientStrategy implements DiscoveryStrategy |
|
| 15 | -{ |
|
| 14 | +final class MockClientStrategy implements DiscoveryStrategy { |
|
| 16 | 15 | public static function getCandidates($type) |
| 17 | 16 | { |
| 18 | 17 | if (is_a(HttpClient::class, $type, true) || is_a(HttpAsyncClient::class, $type, true)) { |
@@ -14,21 +14,21 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | final class StreamFactoryDiscovery extends ClassDiscovery |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * Finds a Stream Factory. |
|
| 19 | - * |
|
| 20 | - * @return StreamFactory |
|
| 21 | - * |
|
| 22 | - * @throws Exception\NotFoundException |
|
| 23 | - */ |
|
| 24 | - public static function find() |
|
| 25 | - { |
|
| 26 | - try { |
|
| 27 | - $streamFactory = static::findOneByType(StreamFactory::class); |
|
| 28 | - } catch (DiscoveryFailedException $e) { |
|
| 29 | - throw new NotFoundException('No stream factories found. To use Guzzle, Diactoros or Slim Framework factories install php-http/message and the chosen message implementation.', 0, $e); |
|
| 30 | - } |
|
| 17 | + /** |
|
| 18 | + * Finds a Stream Factory. |
|
| 19 | + * |
|
| 20 | + * @return StreamFactory |
|
| 21 | + * |
|
| 22 | + * @throws Exception\NotFoundException |
|
| 23 | + */ |
|
| 24 | + public static function find() |
|
| 25 | + { |
|
| 26 | + try { |
|
| 27 | + $streamFactory = static::findOneByType(StreamFactory::class); |
|
| 28 | + } catch (DiscoveryFailedException $e) { |
|
| 29 | + throw new NotFoundException('No stream factories found. To use Guzzle, Diactoros or Slim Framework factories install php-http/message and the chosen message implementation.', 0, $e); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - return static::instantiateClass($streamFactory); |
|
| 33 | - } |
|
| 32 | + return static::instantiateClass($streamFactory); |
|
| 33 | + } |
|
| 34 | 34 | } |
@@ -12,8 +12,7 @@ |
||
| 12 | 12 | * |
| 13 | 13 | * @deprecated This will be removed in 2.0. Consider using Psr17FactoryDiscovery. |
| 14 | 14 | */ |
| 15 | -final class StreamFactoryDiscovery extends ClassDiscovery |
|
| 16 | -{ |
|
| 15 | +final class StreamFactoryDiscovery extends ClassDiscovery { |
|
| 17 | 16 | /** |
| 18 | 17 | * Finds a Stream Factory. |
| 19 | 18 | * |
@@ -22,24 +22,24 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | class Psr18Client extends Psr17Factory implements ClientInterface |
| 24 | 24 | { |
| 25 | - private $client; |
|
| 25 | + private $client; |
|
| 26 | 26 | |
| 27 | - public function __construct( |
|
| 28 | - ?ClientInterface $client = null, |
|
| 29 | - ?RequestFactoryInterface $requestFactory = null, |
|
| 30 | - ?ResponseFactoryInterface $responseFactory = null, |
|
| 31 | - ?ServerRequestFactoryInterface $serverRequestFactory = null, |
|
| 32 | - ?StreamFactoryInterface $streamFactory = null, |
|
| 33 | - ?UploadedFileFactoryInterface $uploadedFileFactory = null, |
|
| 34 | - ?UriFactoryInterface $uriFactory = null |
|
| 35 | - ) { |
|
| 36 | - parent::__construct($requestFactory, $responseFactory, $serverRequestFactory, $streamFactory, $uploadedFileFactory, $uriFactory); |
|
| 27 | + public function __construct( |
|
| 28 | + ?ClientInterface $client = null, |
|
| 29 | + ?RequestFactoryInterface $requestFactory = null, |
|
| 30 | + ?ResponseFactoryInterface $responseFactory = null, |
|
| 31 | + ?ServerRequestFactoryInterface $serverRequestFactory = null, |
|
| 32 | + ?StreamFactoryInterface $streamFactory = null, |
|
| 33 | + ?UploadedFileFactoryInterface $uploadedFileFactory = null, |
|
| 34 | + ?UriFactoryInterface $uriFactory = null |
|
| 35 | + ) { |
|
| 36 | + parent::__construct($requestFactory, $responseFactory, $serverRequestFactory, $streamFactory, $uploadedFileFactory, $uriFactory); |
|
| 37 | 37 | |
| 38 | - $this->client = $client ?? Psr18ClientDiscovery::find(); |
|
| 39 | - } |
|
| 38 | + $this->client = $client ?? Psr18ClientDiscovery::find(); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - public function sendRequest(RequestInterface $request): ResponseInterface |
|
| 42 | - { |
|
| 43 | - return $this->client->sendRequest($request); |
|
| 44 | - } |
|
| 41 | + public function sendRequest(RequestInterface $request): ResponseInterface |
|
| 42 | + { |
|
| 43 | + return $this->client->sendRequest($request); |
|
| 44 | + } |
|
| 45 | 45 | } |
@@ -20,8 +20,7 @@ |
||
| 20 | 20 | * |
| 21 | 21 | * @author Nicolas Grekas <[email protected]> |
| 22 | 22 | */ |
| 23 | -class Psr18Client extends Psr17Factory implements ClientInterface |
|
| 24 | -{ |
|
| 23 | +class Psr18Client extends Psr17Factory implements ClientInterface { |
|
| 25 | 24 | private $client; |
| 26 | 25 | |
| 27 | 26 | public function __construct( |
@@ -18,120 +18,120 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | final class Psr17FactoryDiscovery extends ClassDiscovery |
| 20 | 20 | { |
| 21 | - private static function createException($type, Exception $e) |
|
| 22 | - { |
|
| 23 | - return new RealNotFoundException( |
|
| 24 | - 'No PSR-17 '.$type.' found. Install a package from this list: https://packagist.org/providers/psr/http-factory-implementation', |
|
| 25 | - 0, |
|
| 26 | - $e |
|
| 27 | - ); |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @return RequestFactoryInterface |
|
| 32 | - * |
|
| 33 | - * @throws RealNotFoundException |
|
| 34 | - */ |
|
| 35 | - public static function findRequestFactory() |
|
| 36 | - { |
|
| 37 | - try { |
|
| 38 | - $messageFactory = static::findOneByType(RequestFactoryInterface::class); |
|
| 39 | - } catch (DiscoveryFailedException $e) { |
|
| 40 | - throw self::createException('request factory', $e); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - return static::instantiateClass($messageFactory); |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @return ResponseFactoryInterface |
|
| 48 | - * |
|
| 49 | - * @throws RealNotFoundException |
|
| 50 | - */ |
|
| 51 | - public static function findResponseFactory() |
|
| 52 | - { |
|
| 53 | - try { |
|
| 54 | - $messageFactory = static::findOneByType(ResponseFactoryInterface::class); |
|
| 55 | - } catch (DiscoveryFailedException $e) { |
|
| 56 | - throw self::createException('response factory', $e); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - return static::instantiateClass($messageFactory); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @return ServerRequestFactoryInterface |
|
| 64 | - * |
|
| 65 | - * @throws RealNotFoundException |
|
| 66 | - */ |
|
| 67 | - public static function findServerRequestFactory() |
|
| 68 | - { |
|
| 69 | - try { |
|
| 70 | - $messageFactory = static::findOneByType(ServerRequestFactoryInterface::class); |
|
| 71 | - } catch (DiscoveryFailedException $e) { |
|
| 72 | - throw self::createException('server request factory', $e); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - return static::instantiateClass($messageFactory); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @return StreamFactoryInterface |
|
| 80 | - * |
|
| 81 | - * @throws RealNotFoundException |
|
| 82 | - */ |
|
| 83 | - public static function findStreamFactory() |
|
| 84 | - { |
|
| 85 | - try { |
|
| 86 | - $messageFactory = static::findOneByType(StreamFactoryInterface::class); |
|
| 87 | - } catch (DiscoveryFailedException $e) { |
|
| 88 | - throw self::createException('stream factory', $e); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - return static::instantiateClass($messageFactory); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * @return UploadedFileFactoryInterface |
|
| 96 | - * |
|
| 97 | - * @throws RealNotFoundException |
|
| 98 | - */ |
|
| 99 | - public static function findUploadedFileFactory() |
|
| 100 | - { |
|
| 101 | - try { |
|
| 102 | - $messageFactory = static::findOneByType(UploadedFileFactoryInterface::class); |
|
| 103 | - } catch (DiscoveryFailedException $e) { |
|
| 104 | - throw self::createException('uploaded file factory', $e); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - return static::instantiateClass($messageFactory); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * @return UriFactoryInterface |
|
| 112 | - * |
|
| 113 | - * @throws RealNotFoundException |
|
| 114 | - */ |
|
| 115 | - public static function findUriFactory() |
|
| 116 | - { |
|
| 117 | - try { |
|
| 118 | - $messageFactory = static::findOneByType(UriFactoryInterface::class); |
|
| 119 | - } catch (DiscoveryFailedException $e) { |
|
| 120 | - throw self::createException('url factory', $e); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - return static::instantiateClass($messageFactory); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * @return UriFactoryInterface |
|
| 128 | - * |
|
| 129 | - * @throws RealNotFoundException |
|
| 130 | - * |
|
| 131 | - * @deprecated This will be removed in 2.0. Consider using the findUriFactory() method. |
|
| 132 | - */ |
|
| 133 | - public static function findUrlFactory() |
|
| 134 | - { |
|
| 135 | - return static::findUriFactory(); |
|
| 136 | - } |
|
| 21 | + private static function createException($type, Exception $e) |
|
| 22 | + { |
|
| 23 | + return new RealNotFoundException( |
|
| 24 | + 'No PSR-17 '.$type.' found. Install a package from this list: https://packagist.org/providers/psr/http-factory-implementation', |
|
| 25 | + 0, |
|
| 26 | + $e |
|
| 27 | + ); |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @return RequestFactoryInterface |
|
| 32 | + * |
|
| 33 | + * @throws RealNotFoundException |
|
| 34 | + */ |
|
| 35 | + public static function findRequestFactory() |
|
| 36 | + { |
|
| 37 | + try { |
|
| 38 | + $messageFactory = static::findOneByType(RequestFactoryInterface::class); |
|
| 39 | + } catch (DiscoveryFailedException $e) { |
|
| 40 | + throw self::createException('request factory', $e); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + return static::instantiateClass($messageFactory); |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @return ResponseFactoryInterface |
|
| 48 | + * |
|
| 49 | + * @throws RealNotFoundException |
|
| 50 | + */ |
|
| 51 | + public static function findResponseFactory() |
|
| 52 | + { |
|
| 53 | + try { |
|
| 54 | + $messageFactory = static::findOneByType(ResponseFactoryInterface::class); |
|
| 55 | + } catch (DiscoveryFailedException $e) { |
|
| 56 | + throw self::createException('response factory', $e); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + return static::instantiateClass($messageFactory); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @return ServerRequestFactoryInterface |
|
| 64 | + * |
|
| 65 | + * @throws RealNotFoundException |
|
| 66 | + */ |
|
| 67 | + public static function findServerRequestFactory() |
|
| 68 | + { |
|
| 69 | + try { |
|
| 70 | + $messageFactory = static::findOneByType(ServerRequestFactoryInterface::class); |
|
| 71 | + } catch (DiscoveryFailedException $e) { |
|
| 72 | + throw self::createException('server request factory', $e); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + return static::instantiateClass($messageFactory); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @return StreamFactoryInterface |
|
| 80 | + * |
|
| 81 | + * @throws RealNotFoundException |
|
| 82 | + */ |
|
| 83 | + public static function findStreamFactory() |
|
| 84 | + { |
|
| 85 | + try { |
|
| 86 | + $messageFactory = static::findOneByType(StreamFactoryInterface::class); |
|
| 87 | + } catch (DiscoveryFailedException $e) { |
|
| 88 | + throw self::createException('stream factory', $e); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + return static::instantiateClass($messageFactory); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * @return UploadedFileFactoryInterface |
|
| 96 | + * |
|
| 97 | + * @throws RealNotFoundException |
|
| 98 | + */ |
|
| 99 | + public static function findUploadedFileFactory() |
|
| 100 | + { |
|
| 101 | + try { |
|
| 102 | + $messageFactory = static::findOneByType(UploadedFileFactoryInterface::class); |
|
| 103 | + } catch (DiscoveryFailedException $e) { |
|
| 104 | + throw self::createException('uploaded file factory', $e); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + return static::instantiateClass($messageFactory); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * @return UriFactoryInterface |
|
| 112 | + * |
|
| 113 | + * @throws RealNotFoundException |
|
| 114 | + */ |
|
| 115 | + public static function findUriFactory() |
|
| 116 | + { |
|
| 117 | + try { |
|
| 118 | + $messageFactory = static::findOneByType(UriFactoryInterface::class); |
|
| 119 | + } catch (DiscoveryFailedException $e) { |
|
| 120 | + throw self::createException('url factory', $e); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + return static::instantiateClass($messageFactory); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * @return UriFactoryInterface |
|
| 128 | + * |
|
| 129 | + * @throws RealNotFoundException |
|
| 130 | + * |
|
| 131 | + * @deprecated This will be removed in 2.0. Consider using the findUriFactory() method. |
|
| 132 | + */ |
|
| 133 | + public static function findUrlFactory() |
|
| 134 | + { |
|
| 135 | + return static::findUriFactory(); |
|
| 136 | + } |
|
| 137 | 137 | } |
@@ -16,8 +16,7 @@ |
||
| 16 | 16 | * |
| 17 | 17 | * @author Tobias Nyholm <[email protected]> |
| 18 | 18 | */ |
| 19 | -final class Psr17FactoryDiscovery extends ClassDiscovery |
|
| 20 | -{ |
|
| 19 | +final class Psr17FactoryDiscovery extends ClassDiscovery { |
|
| 21 | 20 | private static function createException($type, Exception $e) |
| 22 | 21 | { |
| 23 | 22 | return new RealNotFoundException( |
@@ -11,6 +11,5 @@ |
||
| 11 | 11 | * |
| 12 | 12 | * @deprecated since since version 1.0, and will be removed in 2.0. Use {@link \OCA\FullTextSearch_Elasticsearch\Vendor\Http\Discovery\Exception\NotFoundException} instead. |
| 13 | 13 | */ |
| 14 | -final class NotFoundException extends RealNotFoundException |
|
| 15 | -{ |
|
| 14 | +final class NotFoundException extends RealNotFoundException { |
|
| 16 | 15 | } |
@@ -14,21 +14,21 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | final class MessageFactoryDiscovery extends ClassDiscovery |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * Finds a Message Factory. |
|
| 19 | - * |
|
| 20 | - * @return MessageFactory |
|
| 21 | - * |
|
| 22 | - * @throws Exception\NotFoundException |
|
| 23 | - */ |
|
| 24 | - public static function find() |
|
| 25 | - { |
|
| 26 | - try { |
|
| 27 | - $messageFactory = static::findOneByType(MessageFactory::class); |
|
| 28 | - } catch (DiscoveryFailedException $e) { |
|
| 29 | - throw new NotFoundException('No php-http message factories found. Note that the php-http message factories are deprecated in favor of the PSR-17 message factories. To use the legacy Guzzle, Diactoros or Slim Framework factories of php-http, install php-http/message and php-http/message-factory and the chosen message implementation.', 0, $e); |
|
| 30 | - } |
|
| 17 | + /** |
|
| 18 | + * Finds a Message Factory. |
|
| 19 | + * |
|
| 20 | + * @return MessageFactory |
|
| 21 | + * |
|
| 22 | + * @throws Exception\NotFoundException |
|
| 23 | + */ |
|
| 24 | + public static function find() |
|
| 25 | + { |
|
| 26 | + try { |
|
| 27 | + $messageFactory = static::findOneByType(MessageFactory::class); |
|
| 28 | + } catch (DiscoveryFailedException $e) { |
|
| 29 | + throw new NotFoundException('No php-http message factories found. Note that the php-http message factories are deprecated in favor of the PSR-17 message factories. To use the legacy Guzzle, Diactoros or Slim Framework factories of php-http, install php-http/message and php-http/message-factory and the chosen message implementation.', 0, $e); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - return static::instantiateClass($messageFactory); |
|
| 33 | - } |
|
| 32 | + return static::instantiateClass($messageFactory); |
|
| 33 | + } |
|
| 34 | 34 | } |
@@ -12,8 +12,7 @@ |
||
| 12 | 12 | * |
| 13 | 13 | * @deprecated This will be removed in 2.0. Consider using Psr17FactoryDiscovery. |
| 14 | 14 | */ |
| 15 | -final class MessageFactoryDiscovery extends ClassDiscovery |
|
| 16 | -{ |
|
| 15 | +final class MessageFactoryDiscovery extends ClassDiscovery { |
|
| 17 | 16 | /** |
| 18 | 17 | * Finds a Message Factory. |
| 19 | 18 | * |
@@ -9,43 +9,43 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | final class FulfilledPromise implements Promise |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * @var mixed |
|
| 14 | - */ |
|
| 15 | - private $result; |
|
| 16 | - |
|
| 17 | - /** |
|
| 18 | - * @param mixed $result |
|
| 19 | - */ |
|
| 20 | - public function __construct($result) |
|
| 21 | - { |
|
| 22 | - $this->result = $result; |
|
| 23 | - } |
|
| 24 | - |
|
| 25 | - public function then(?callable $onFulfilled = null, ?callable $onRejected = null) |
|
| 26 | - { |
|
| 27 | - if (null === $onFulfilled) { |
|
| 28 | - return $this; |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - try { |
|
| 32 | - return new self($onFulfilled($this->result)); |
|
| 33 | - } catch (\Exception $e) { |
|
| 34 | - return new RejectedPromise($e); |
|
| 35 | - } |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - public function getState() |
|
| 39 | - { |
|
| 40 | - return Promise::FULFILLED; |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - public function wait($unwrap = true) |
|
| 44 | - { |
|
| 45 | - if ($unwrap) { |
|
| 46 | - return $this->result; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - return null; |
|
| 50 | - } |
|
| 12 | + /** |
|
| 13 | + * @var mixed |
|
| 14 | + */ |
|
| 15 | + private $result; |
|
| 16 | + |
|
| 17 | + /** |
|
| 18 | + * @param mixed $result |
|
| 19 | + */ |
|
| 20 | + public function __construct($result) |
|
| 21 | + { |
|
| 22 | + $this->result = $result; |
|
| 23 | + } |
|
| 24 | + |
|
| 25 | + public function then(?callable $onFulfilled = null, ?callable $onRejected = null) |
|
| 26 | + { |
|
| 27 | + if (null === $onFulfilled) { |
|
| 28 | + return $this; |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + try { |
|
| 32 | + return new self($onFulfilled($this->result)); |
|
| 33 | + } catch (\Exception $e) { |
|
| 34 | + return new RejectedPromise($e); |
|
| 35 | + } |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + public function getState() |
|
| 39 | + { |
|
| 40 | + return Promise::FULFILLED; |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + public function wait($unwrap = true) |
|
| 44 | + { |
|
| 45 | + if ($unwrap) { |
|
| 46 | + return $this->result; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + return null; |
|
| 50 | + } |
|
| 51 | 51 | } |
@@ -7,8 +7,7 @@ |
||
| 7 | 7 | * |
| 8 | 8 | * @author Joel Wurtz <[email protected]> |
| 9 | 9 | */ |
| 10 | -final class FulfilledPromise implements Promise |
|
| 11 | -{ |
|
| 10 | +final class FulfilledPromise implements Promise { |
|
| 12 | 11 | /** |
| 13 | 12 | * @var mixed |
| 14 | 13 | */ |
@@ -15,55 +15,55 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | interface Promise |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * Promise has not been fulfilled or rejected. |
|
| 20 | - */ |
|
| 21 | - const PENDING = 'pending'; |
|
| 18 | + /** |
|
| 19 | + * Promise has not been fulfilled or rejected. |
|
| 20 | + */ |
|
| 21 | + const PENDING = 'pending'; |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Promise has been fulfilled. |
|
| 25 | - */ |
|
| 26 | - const FULFILLED = 'fulfilled'; |
|
| 23 | + /** |
|
| 24 | + * Promise has been fulfilled. |
|
| 25 | + */ |
|
| 26 | + const FULFILLED = 'fulfilled'; |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * Promise has been rejected. |
|
| 30 | - */ |
|
| 31 | - const REJECTED = 'rejected'; |
|
| 28 | + /** |
|
| 29 | + * Promise has been rejected. |
|
| 30 | + */ |
|
| 31 | + const REJECTED = 'rejected'; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Adds behavior for when the promise is resolved or rejected (response will be available, or error happens). |
|
| 35 | - * |
|
| 36 | - * If you do not care about one of the cases, you can set the corresponding callable to null |
|
| 37 | - * The callback will be called when the value arrived and never more than once. |
|
| 38 | - * |
|
| 39 | - * @param callable|null $onFulfilled called when a response will be available |
|
| 40 | - * @param callable|null $onRejected called when an exception occurs |
|
| 41 | - * |
|
| 42 | - * @return Promise a new resolved promise with value of the executed callback (onFulfilled / onRejected) |
|
| 43 | - */ |
|
| 44 | - public function then(?callable $onFulfilled = null, ?callable $onRejected = null); |
|
| 33 | + /** |
|
| 34 | + * Adds behavior for when the promise is resolved or rejected (response will be available, or error happens). |
|
| 35 | + * |
|
| 36 | + * If you do not care about one of the cases, you can set the corresponding callable to null |
|
| 37 | + * The callback will be called when the value arrived and never more than once. |
|
| 38 | + * |
|
| 39 | + * @param callable|null $onFulfilled called when a response will be available |
|
| 40 | + * @param callable|null $onRejected called when an exception occurs |
|
| 41 | + * |
|
| 42 | + * @return Promise a new resolved promise with value of the executed callback (onFulfilled / onRejected) |
|
| 43 | + */ |
|
| 44 | + public function then(?callable $onFulfilled = null, ?callable $onRejected = null); |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Returns the state of the promise, one of PENDING, FULFILLED or REJECTED. |
|
| 48 | - * |
|
| 49 | - * @return string |
|
| 50 | - */ |
|
| 51 | - public function getState(); |
|
| 46 | + /** |
|
| 47 | + * Returns the state of the promise, one of PENDING, FULFILLED or REJECTED. |
|
| 48 | + * |
|
| 49 | + * @return string |
|
| 50 | + */ |
|
| 51 | + public function getState(); |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Wait for the promise to be fulfilled or rejected. |
|
| 55 | - * |
|
| 56 | - * When this method returns, the request has been resolved and if callables have been |
|
| 57 | - * specified, the appropriate one has terminated. |
|
| 58 | - * |
|
| 59 | - * When $unwrap is true (the default), the response is returned, or the exception thrown |
|
| 60 | - * on failure. Otherwise, nothing is returned or thrown. |
|
| 61 | - * |
|
| 62 | - * @param bool $unwrap Whether to return resolved value / throw reason or not |
|
| 63 | - * |
|
| 64 | - * @return ($unwrap is true ? mixed : null) Resolved value, null if $unwrap is set to false |
|
| 65 | - * |
|
| 66 | - * @throws \Throwable the rejection reason if $unwrap is set to true and the request failed |
|
| 67 | - */ |
|
| 68 | - public function wait($unwrap = true); |
|
| 53 | + /** |
|
| 54 | + * Wait for the promise to be fulfilled or rejected. |
|
| 55 | + * |
|
| 56 | + * When this method returns, the request has been resolved and if callables have been |
|
| 57 | + * specified, the appropriate one has terminated. |
|
| 58 | + * |
|
| 59 | + * When $unwrap is true (the default), the response is returned, or the exception thrown |
|
| 60 | + * on failure. Otherwise, nothing is returned or thrown. |
|
| 61 | + * |
|
| 62 | + * @param bool $unwrap Whether to return resolved value / throw reason or not |
|
| 63 | + * |
|
| 64 | + * @return ($unwrap is true ? mixed : null) Resolved value, null if $unwrap is set to false |
|
| 65 | + * |
|
| 66 | + * @throws \Throwable the rejection reason if $unwrap is set to true and the request failed |
|
| 67 | + */ |
|
| 68 | + public function wait($unwrap = true); |
|
| 69 | 69 | } |
@@ -13,8 +13,7 @@ |
||
| 13 | 13 | * @author Joel Wurtz <[email protected]> |
| 14 | 14 | * @author Márk Sági-Kazár <[email protected]> |
| 15 | 15 | */ |
| 16 | -interface Promise |
|
| 17 | -{ |
|
| 16 | +interface Promise { |
|
| 18 | 17 | /** |
| 19 | 18 | * Promise has not been fulfilled or rejected. |
| 20 | 19 | */ |
@@ -9,40 +9,40 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | final class RejectedPromise implements Promise |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * @var \Throwable |
|
| 14 | - */ |
|
| 15 | - private $exception; |
|
| 16 | - |
|
| 17 | - public function __construct(\Throwable $exception) |
|
| 18 | - { |
|
| 19 | - $this->exception = $exception; |
|
| 20 | - } |
|
| 21 | - |
|
| 22 | - public function then(?callable $onFulfilled = null, ?callable $onRejected = null) |
|
| 23 | - { |
|
| 24 | - if (null === $onRejected) { |
|
| 25 | - return $this; |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - try { |
|
| 29 | - return new FulfilledPromise($onRejected($this->exception)); |
|
| 30 | - } catch (\Exception $e) { |
|
| 31 | - return new self($e); |
|
| 32 | - } |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - public function getState() |
|
| 36 | - { |
|
| 37 | - return Promise::REJECTED; |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - public function wait($unwrap = true) |
|
| 41 | - { |
|
| 42 | - if ($unwrap) { |
|
| 43 | - throw $this->exception; |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - return null; |
|
| 47 | - } |
|
| 12 | + /** |
|
| 13 | + * @var \Throwable |
|
| 14 | + */ |
|
| 15 | + private $exception; |
|
| 16 | + |
|
| 17 | + public function __construct(\Throwable $exception) |
|
| 18 | + { |
|
| 19 | + $this->exception = $exception; |
|
| 20 | + } |
|
| 21 | + |
|
| 22 | + public function then(?callable $onFulfilled = null, ?callable $onRejected = null) |
|
| 23 | + { |
|
| 24 | + if (null === $onRejected) { |
|
| 25 | + return $this; |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + try { |
|
| 29 | + return new FulfilledPromise($onRejected($this->exception)); |
|
| 30 | + } catch (\Exception $e) { |
|
| 31 | + return new self($e); |
|
| 32 | + } |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + public function getState() |
|
| 36 | + { |
|
| 37 | + return Promise::REJECTED; |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + public function wait($unwrap = true) |
|
| 41 | + { |
|
| 42 | + if ($unwrap) { |
|
| 43 | + throw $this->exception; |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + return null; |
|
| 47 | + } |
|
| 48 | 48 | } |
@@ -7,8 +7,7 @@ |
||
| 7 | 7 | * |
| 8 | 8 | * @author Joel Wurtz <[email protected]> |
| 9 | 9 | */ |
| 10 | -final class RejectedPromise implements Promise |
|
| 11 | -{ |
|
| 10 | +final class RejectedPromise implements Promise { |
|
| 12 | 11 | /** |
| 13 | 12 | * @var \Throwable |
| 14 | 13 | */ |