@@ -16,8 +16,7 @@ |
||
16 | 16 | * |
17 | 17 | * Don't miss updating src/Composer/Plugin.php when adding a new supported class. |
18 | 18 | */ |
19 | -final class CommonPsr17ClassesStrategy implements DiscoveryStrategy |
|
20 | -{ |
|
19 | +final class CommonPsr17ClassesStrategy implements DiscoveryStrategy { |
|
21 | 20 | /** |
22 | 21 | * @var array |
23 | 22 | */ |
@@ -17,18 +17,18 @@ |
||
17 | 17 | */ |
18 | 18 | final class CommonPsr17ClassesStrategy implements DiscoveryStrategy |
19 | 19 | { |
20 | - /** |
|
21 | - * @var array |
|
22 | - */ |
|
23 | - private static $classes = [RequestFactoryInterface::class => ['OCA\\FullTextSearch_Elasticsearch\\Vendor\\Phalcon\\Http\\Message\\RequestFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Nyholm\\Psr7\\Factory\\Psr17Factory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\GuzzleHttp\\Psr7\\HttpFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Http\\Factory\\Diactoros\\RequestFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Http\\Factory\\Guzzle\\RequestFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Http\\Factory\\Slim\\RequestFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Laminas\\Diactoros\\RequestFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Slim\\Psr7\\Factory\\RequestFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\HttpSoft\\Message\\RequestFactory'], ResponseFactoryInterface::class => ['OCA\\FullTextSearch_Elasticsearch\\Vendor\\Phalcon\\Http\\Message\\ResponseFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Nyholm\\Psr7\\Factory\\Psr17Factory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\GuzzleHttp\\Psr7\\HttpFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Http\\Factory\\Diactoros\\ResponseFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Http\\Factory\\Guzzle\\ResponseFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Http\\Factory\\Slim\\ResponseFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Laminas\\Diactoros\\ResponseFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Slim\\Psr7\\Factory\\ResponseFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\HttpSoft\\Message\\ResponseFactory'], ServerRequestFactoryInterface::class => ['OCA\\FullTextSearch_Elasticsearch\\Vendor\\Phalcon\\Http\\Message\\ServerRequestFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Nyholm\\Psr7\\Factory\\Psr17Factory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\GuzzleHttp\\Psr7\\HttpFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Http\\Factory\\Diactoros\\ServerRequestFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Http\\Factory\\Guzzle\\ServerRequestFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Http\\Factory\\Slim\\ServerRequestFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Laminas\\Diactoros\\ServerRequestFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Slim\\Psr7\\Factory\\ServerRequestFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\HttpSoft\\Message\\ServerRequestFactory'], StreamFactoryInterface::class => ['OCA\\FullTextSearch_Elasticsearch\\Vendor\\Phalcon\\Http\\Message\\StreamFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Nyholm\\Psr7\\Factory\\Psr17Factory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\GuzzleHttp\\Psr7\\HttpFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Http\\Factory\\Diactoros\\StreamFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Http\\Factory\\Guzzle\\StreamFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Http\\Factory\\Slim\\StreamFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Laminas\\Diactoros\\StreamFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Slim\\Psr7\\Factory\\StreamFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\HttpSoft\\Message\\StreamFactory'], UploadedFileFactoryInterface::class => ['OCA\\FullTextSearch_Elasticsearch\\Vendor\\Phalcon\\Http\\Message\\UploadedFileFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Nyholm\\Psr7\\Factory\\Psr17Factory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\GuzzleHttp\\Psr7\\HttpFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Http\\Factory\\Diactoros\\UploadedFileFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Http\\Factory\\Guzzle\\UploadedFileFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Http\\Factory\\Slim\\UploadedFileFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Laminas\\Diactoros\\UploadedFileFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Slim\\Psr7\\Factory\\UploadedFileFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\HttpSoft\\Message\\UploadedFileFactory'], UriFactoryInterface::class => ['OCA\\FullTextSearch_Elasticsearch\\Vendor\\Phalcon\\Http\\Message\\UriFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Nyholm\\Psr7\\Factory\\Psr17Factory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\GuzzleHttp\\Psr7\\HttpFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Http\\Factory\\Diactoros\\UriFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Http\\Factory\\Guzzle\\UriFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Http\\Factory\\Slim\\UriFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Laminas\\Diactoros\\UriFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Slim\\Psr7\\Factory\\UriFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\HttpSoft\\Message\\UriFactory']]; |
|
24 | - public static function getCandidates($type) |
|
25 | - { |
|
26 | - $candidates = []; |
|
27 | - if (isset(self::$classes[$type])) { |
|
28 | - foreach (self::$classes[$type] as $class) { |
|
29 | - $candidates[] = ['class' => $class, 'condition' => [$class]]; |
|
30 | - } |
|
31 | - } |
|
32 | - return $candidates; |
|
33 | - } |
|
20 | + /** |
|
21 | + * @var array |
|
22 | + */ |
|
23 | + private static $classes = [RequestFactoryInterface::class => ['OCA\\FullTextSearch_Elasticsearch\\Vendor\\Phalcon\\Http\\Message\\RequestFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Nyholm\\Psr7\\Factory\\Psr17Factory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\GuzzleHttp\\Psr7\\HttpFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Http\\Factory\\Diactoros\\RequestFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Http\\Factory\\Guzzle\\RequestFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Http\\Factory\\Slim\\RequestFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Laminas\\Diactoros\\RequestFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Slim\\Psr7\\Factory\\RequestFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\HttpSoft\\Message\\RequestFactory'], ResponseFactoryInterface::class => ['OCA\\FullTextSearch_Elasticsearch\\Vendor\\Phalcon\\Http\\Message\\ResponseFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Nyholm\\Psr7\\Factory\\Psr17Factory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\GuzzleHttp\\Psr7\\HttpFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Http\\Factory\\Diactoros\\ResponseFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Http\\Factory\\Guzzle\\ResponseFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Http\\Factory\\Slim\\ResponseFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Laminas\\Diactoros\\ResponseFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Slim\\Psr7\\Factory\\ResponseFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\HttpSoft\\Message\\ResponseFactory'], ServerRequestFactoryInterface::class => ['OCA\\FullTextSearch_Elasticsearch\\Vendor\\Phalcon\\Http\\Message\\ServerRequestFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Nyholm\\Psr7\\Factory\\Psr17Factory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\GuzzleHttp\\Psr7\\HttpFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Http\\Factory\\Diactoros\\ServerRequestFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Http\\Factory\\Guzzle\\ServerRequestFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Http\\Factory\\Slim\\ServerRequestFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Laminas\\Diactoros\\ServerRequestFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Slim\\Psr7\\Factory\\ServerRequestFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\HttpSoft\\Message\\ServerRequestFactory'], StreamFactoryInterface::class => ['OCA\\FullTextSearch_Elasticsearch\\Vendor\\Phalcon\\Http\\Message\\StreamFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Nyholm\\Psr7\\Factory\\Psr17Factory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\GuzzleHttp\\Psr7\\HttpFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Http\\Factory\\Diactoros\\StreamFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Http\\Factory\\Guzzle\\StreamFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Http\\Factory\\Slim\\StreamFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Laminas\\Diactoros\\StreamFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Slim\\Psr7\\Factory\\StreamFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\HttpSoft\\Message\\StreamFactory'], UploadedFileFactoryInterface::class => ['OCA\\FullTextSearch_Elasticsearch\\Vendor\\Phalcon\\Http\\Message\\UploadedFileFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Nyholm\\Psr7\\Factory\\Psr17Factory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\GuzzleHttp\\Psr7\\HttpFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Http\\Factory\\Diactoros\\UploadedFileFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Http\\Factory\\Guzzle\\UploadedFileFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Http\\Factory\\Slim\\UploadedFileFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Laminas\\Diactoros\\UploadedFileFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Slim\\Psr7\\Factory\\UploadedFileFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\HttpSoft\\Message\\UploadedFileFactory'], UriFactoryInterface::class => ['OCA\\FullTextSearch_Elasticsearch\\Vendor\\Phalcon\\Http\\Message\\UriFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Nyholm\\Psr7\\Factory\\Psr17Factory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\GuzzleHttp\\Psr7\\HttpFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Http\\Factory\\Diactoros\\UriFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Http\\Factory\\Guzzle\\UriFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Http\\Factory\\Slim\\UriFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Laminas\\Diactoros\\UriFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\Slim\\Psr7\\Factory\\UriFactory', 'OCA\\FullTextSearch_Elasticsearch\\Vendor\\HttpSoft\\Message\\UriFactory']]; |
|
24 | + public static function getCandidates($type) |
|
25 | + { |
|
26 | + $candidates = []; |
|
27 | + if (isset(self::$classes[$type])) { |
|
28 | + foreach (self::$classes[$type] as $class) { |
|
29 | + $candidates[] = ['class' => $class, 'condition' => [$class]]; |
|
30 | + } |
|
31 | + } |
|
32 | + return $candidates; |
|
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 | * |
@@ -13,20 +13,20 @@ |
||
13 | 13 | */ |
14 | 14 | final class StreamFactoryDiscovery extends ClassDiscovery |
15 | 15 | { |
16 | - /** |
|
17 | - * Finds a Stream Factory. |
|
18 | - * |
|
19 | - * @return StreamFactory |
|
20 | - * |
|
21 | - * @throws Exception\NotFoundException |
|
22 | - */ |
|
23 | - public static function find() |
|
24 | - { |
|
25 | - try { |
|
26 | - $streamFactory = static::findOneByType(StreamFactory::class); |
|
27 | - } catch (DiscoveryFailedException $e) { |
|
28 | - 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); |
|
29 | - } |
|
30 | - return static::instantiateClass($streamFactory); |
|
31 | - } |
|
16 | + /** |
|
17 | + * Finds a Stream Factory. |
|
18 | + * |
|
19 | + * @return StreamFactory |
|
20 | + * |
|
21 | + * @throws Exception\NotFoundException |
|
22 | + */ |
|
23 | + public static function find() |
|
24 | + { |
|
25 | + try { |
|
26 | + $streamFactory = static::findOneByType(StreamFactory::class); |
|
27 | + } catch (DiscoveryFailedException $e) { |
|
28 | + 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); |
|
29 | + } |
|
30 | + return static::instantiateClass($streamFactory); |
|
31 | + } |
|
32 | 32 | } |
@@ -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 | * |
@@ -13,20 +13,20 @@ |
||
13 | 13 | */ |
14 | 14 | final class MessageFactoryDiscovery extends ClassDiscovery |
15 | 15 | { |
16 | - /** |
|
17 | - * Finds a Message Factory. |
|
18 | - * |
|
19 | - * @return MessageFactory |
|
20 | - * |
|
21 | - * @throws Exception\NotFoundException |
|
22 | - */ |
|
23 | - public static function find() |
|
24 | - { |
|
25 | - try { |
|
26 | - $messageFactory = static::findOneByType(MessageFactory::class); |
|
27 | - } catch (DiscoveryFailedException $e) { |
|
28 | - 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); |
|
29 | - } |
|
30 | - return static::instantiateClass($messageFactory); |
|
31 | - } |
|
16 | + /** |
|
17 | + * Finds a Message Factory. |
|
18 | + * |
|
19 | + * @return MessageFactory |
|
20 | + * |
|
21 | + * @throws Exception\NotFoundException |
|
22 | + */ |
|
23 | + public static function find() |
|
24 | + { |
|
25 | + try { |
|
26 | + $messageFactory = static::findOneByType(MessageFactory::class); |
|
27 | + } catch (DiscoveryFailedException $e) { |
|
28 | + 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); |
|
29 | + } |
|
30 | + return static::instantiateClass($messageFactory); |
|
31 | + } |
|
32 | 32 | } |
@@ -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 | */ |
@@ -9,37 +9,37 @@ |
||
9 | 9 | */ |
10 | 10 | final class FulfilledPromise implements Promise |
11 | 11 | { |
12 | - /** |
|
13 | - * @var mixed |
|
14 | - */ |
|
15 | - private $result; |
|
16 | - /** |
|
17 | - * @param mixed $result |
|
18 | - */ |
|
19 | - public function __construct($result) |
|
20 | - { |
|
21 | - $this->result = $result; |
|
22 | - } |
|
23 | - public function then(?callable $onFulfilled = null, ?callable $onRejected = null) |
|
24 | - { |
|
25 | - if (null === $onFulfilled) { |
|
26 | - return $this; |
|
27 | - } |
|
28 | - try { |
|
29 | - return new self($onFulfilled($this->result)); |
|
30 | - } catch (\Exception $e) { |
|
31 | - return new RejectedPromise($e); |
|
32 | - } |
|
33 | - } |
|
34 | - public function getState() |
|
35 | - { |
|
36 | - return Promise::FULFILLED; |
|
37 | - } |
|
38 | - public function wait($unwrap = \true) |
|
39 | - { |
|
40 | - if ($unwrap) { |
|
41 | - return $this->result; |
|
42 | - } |
|
43 | - return null; |
|
44 | - } |
|
12 | + /** |
|
13 | + * @var mixed |
|
14 | + */ |
|
15 | + private $result; |
|
16 | + /** |
|
17 | + * @param mixed $result |
|
18 | + */ |
|
19 | + public function __construct($result) |
|
20 | + { |
|
21 | + $this->result = $result; |
|
22 | + } |
|
23 | + public function then(?callable $onFulfilled = null, ?callable $onRejected = null) |
|
24 | + { |
|
25 | + if (null === $onFulfilled) { |
|
26 | + return $this; |
|
27 | + } |
|
28 | + try { |
|
29 | + return new self($onFulfilled($this->result)); |
|
30 | + } catch (\Exception $e) { |
|
31 | + return new RejectedPromise($e); |
|
32 | + } |
|
33 | + } |
|
34 | + public function getState() |
|
35 | + { |
|
36 | + return Promise::FULFILLED; |
|
37 | + } |
|
38 | + public function wait($unwrap = \true) |
|
39 | + { |
|
40 | + if ($unwrap) { |
|
41 | + return $this->result; |
|
42 | + } |
|
43 | + return null; |
|
44 | + } |
|
45 | 45 | } |
@@ -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 | */ |
@@ -15,50 +15,50 @@ |
||
15 | 15 | */ |
16 | 16 | interface Promise |
17 | 17 | { |
18 | - /** |
|
19 | - * Promise has not been fulfilled or rejected. |
|
20 | - */ |
|
21 | - const PENDING = 'pending'; |
|
22 | - /** |
|
23 | - * Promise has been fulfilled. |
|
24 | - */ |
|
25 | - const FULFILLED = 'fulfilled'; |
|
26 | - /** |
|
27 | - * Promise has been rejected. |
|
28 | - */ |
|
29 | - const REJECTED = 'rejected'; |
|
30 | - /** |
|
31 | - * Adds behavior for when the promise is resolved or rejected (response will be available, or error happens). |
|
32 | - * |
|
33 | - * If you do not care about one of the cases, you can set the corresponding callable to null |
|
34 | - * The callback will be called when the value arrived and never more than once. |
|
35 | - * |
|
36 | - * @param callable|null $onFulfilled called when a response will be available |
|
37 | - * @param callable|null $onRejected called when an exception occurs |
|
38 | - * |
|
39 | - * @return Promise a new resolved promise with value of the executed callback (onFulfilled / onRejected) |
|
40 | - */ |
|
41 | - public function then(?callable $onFulfilled = null, ?callable $onRejected = null); |
|
42 | - /** |
|
43 | - * Returns the state of the promise, one of PENDING, FULFILLED or REJECTED. |
|
44 | - * |
|
45 | - * @return string |
|
46 | - */ |
|
47 | - public function getState(); |
|
48 | - /** |
|
49 | - * Wait for the promise to be fulfilled or rejected. |
|
50 | - * |
|
51 | - * When this method returns, the request has been resolved and if callables have been |
|
52 | - * specified, the appropriate one has terminated. |
|
53 | - * |
|
54 | - * When $unwrap is true (the default), the response is returned, or the exception thrown |
|
55 | - * on failure. Otherwise, nothing is returned or thrown. |
|
56 | - * |
|
57 | - * @param bool $unwrap Whether to return resolved value / throw reason or not |
|
58 | - * |
|
59 | - * @return ($unwrap is true ? mixed : null) Resolved value, null if $unwrap is set to false |
|
60 | - * |
|
61 | - * @throws \Throwable the rejection reason if $unwrap is set to true and the request failed |
|
62 | - */ |
|
63 | - public function wait($unwrap = \true); |
|
18 | + /** |
|
19 | + * Promise has not been fulfilled or rejected. |
|
20 | + */ |
|
21 | + const PENDING = 'pending'; |
|
22 | + /** |
|
23 | + * Promise has been fulfilled. |
|
24 | + */ |
|
25 | + const FULFILLED = 'fulfilled'; |
|
26 | + /** |
|
27 | + * Promise has been rejected. |
|
28 | + */ |
|
29 | + const REJECTED = 'rejected'; |
|
30 | + /** |
|
31 | + * Adds behavior for when the promise is resolved or rejected (response will be available, or error happens). |
|
32 | + * |
|
33 | + * If you do not care about one of the cases, you can set the corresponding callable to null |
|
34 | + * The callback will be called when the value arrived and never more than once. |
|
35 | + * |
|
36 | + * @param callable|null $onFulfilled called when a response will be available |
|
37 | + * @param callable|null $onRejected called when an exception occurs |
|
38 | + * |
|
39 | + * @return Promise a new resolved promise with value of the executed callback (onFulfilled / onRejected) |
|
40 | + */ |
|
41 | + public function then(?callable $onFulfilled = null, ?callable $onRejected = null); |
|
42 | + /** |
|
43 | + * Returns the state of the promise, one of PENDING, FULFILLED or REJECTED. |
|
44 | + * |
|
45 | + * @return string |
|
46 | + */ |
|
47 | + public function getState(); |
|
48 | + /** |
|
49 | + * Wait for the promise to be fulfilled or rejected. |
|
50 | + * |
|
51 | + * When this method returns, the request has been resolved and if callables have been |
|
52 | + * specified, the appropriate one has terminated. |
|
53 | + * |
|
54 | + * When $unwrap is true (the default), the response is returned, or the exception thrown |
|
55 | + * on failure. Otherwise, nothing is returned or thrown. |
|
56 | + * |
|
57 | + * @param bool $unwrap Whether to return resolved value / throw reason or not |
|
58 | + * |
|
59 | + * @return ($unwrap is true ? mixed : null) Resolved value, null if $unwrap is set to false |
|
60 | + * |
|
61 | + * @throws \Throwable the rejection reason if $unwrap is set to true and the request failed |
|
62 | + */ |
|
63 | + public function wait($unwrap = \true); |
|
64 | 64 | } |
@@ -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 | */ |
@@ -9,34 +9,34 @@ |
||
9 | 9 | */ |
10 | 10 | final class RejectedPromise implements Promise |
11 | 11 | { |
12 | - /** |
|
13 | - * @var \Throwable |
|
14 | - */ |
|
15 | - private $exception; |
|
16 | - public function __construct(\Throwable $exception) |
|
17 | - { |
|
18 | - $this->exception = $exception; |
|
19 | - } |
|
20 | - public function then(?callable $onFulfilled = null, ?callable $onRejected = null) |
|
21 | - { |
|
22 | - if (null === $onRejected) { |
|
23 | - return $this; |
|
24 | - } |
|
25 | - try { |
|
26 | - return new FulfilledPromise($onRejected($this->exception)); |
|
27 | - } catch (\Exception $e) { |
|
28 | - return new self($e); |
|
29 | - } |
|
30 | - } |
|
31 | - public function getState() |
|
32 | - { |
|
33 | - return Promise::REJECTED; |
|
34 | - } |
|
35 | - public function wait($unwrap = \true) |
|
36 | - { |
|
37 | - if ($unwrap) { |
|
38 | - throw $this->exception; |
|
39 | - } |
|
40 | - return null; |
|
41 | - } |
|
12 | + /** |
|
13 | + * @var \Throwable |
|
14 | + */ |
|
15 | + private $exception; |
|
16 | + public function __construct(\Throwable $exception) |
|
17 | + { |
|
18 | + $this->exception = $exception; |
|
19 | + } |
|
20 | + public function then(?callable $onFulfilled = null, ?callable $onRejected = null) |
|
21 | + { |
|
22 | + if (null === $onRejected) { |
|
23 | + return $this; |
|
24 | + } |
|
25 | + try { |
|
26 | + return new FulfilledPromise($onRejected($this->exception)); |
|
27 | + } catch (\Exception $e) { |
|
28 | + return new self($e); |
|
29 | + } |
|
30 | + } |
|
31 | + public function getState() |
|
32 | + { |
|
33 | + return Promise::REJECTED; |
|
34 | + } |
|
35 | + public function wait($unwrap = \true) |
|
36 | + { |
|
37 | + if ($unwrap) { |
|
38 | + throw $this->exception; |
|
39 | + } |
|
40 | + return null; |
|
41 | + } |
|
42 | 42 | } |
@@ -9,6 +9,5 @@ |
||
9 | 9 | * |
10 | 10 | * @author Márk Sági-Kazár <[email protected]> |
11 | 11 | */ |
12 | -interface Exception extends PsrClientException |
|
13 | -{ |
|
12 | +interface Exception extends PsrClientException { |
|
14 | 13 | } |
@@ -10,8 +10,7 @@ |
||
10 | 10 | * |
11 | 11 | * @author Joel Wurtz <[email protected]> |
12 | 12 | */ |
13 | -interface HttpAsyncClient |
|
14 | -{ |
|
13 | +interface HttpAsyncClient { |
|
15 | 14 | /** |
16 | 15 | * Sends a PSR-7 request in an asynchronous way. |
17 | 16 | * |
@@ -11,14 +11,14 @@ |
||
11 | 11 | */ |
12 | 12 | interface HttpAsyncClient |
13 | 13 | { |
14 | - /** |
|
15 | - * Sends a PSR-7 request in an asynchronous way. |
|
16 | - * |
|
17 | - * Exceptions related to processing the request are available from the returned Promise. |
|
18 | - * |
|
19 | - * @return Promise resolves a PSR-7 Response or fails with an Http\Client\Exception |
|
20 | - * |
|
21 | - * @throws \Exception If processing the request is impossible (eg. bad configuration). |
|
22 | - */ |
|
23 | - public function sendAsyncRequest(RequestInterface $request); |
|
14 | + /** |
|
15 | + * Sends a PSR-7 request in an asynchronous way. |
|
16 | + * |
|
17 | + * Exceptions related to processing the request are available from the returned Promise. |
|
18 | + * |
|
19 | + * @return Promise resolves a PSR-7 Response or fails with an Http\Client\Exception |
|
20 | + * |
|
21 | + * @throws \Exception If processing the request is impossible (eg. bad configuration). |
|
22 | + */ |
|
23 | + public function sendAsyncRequest(RequestInterface $request); |
|
24 | 24 | } |
@@ -12,8 +12,7 @@ |
||
12 | 12 | * |
13 | 13 | * @author Márk Sági-Kazár <[email protected]> |
14 | 14 | */ |
15 | -class HttpException extends RequestException |
|
16 | -{ |
|
15 | +class HttpException extends RequestException { |
|
17 | 16 | /** |
18 | 17 | * @var ResponseInterface |
19 | 18 | */ |
@@ -13,34 +13,34 @@ |
||
13 | 13 | */ |
14 | 14 | class HttpException extends RequestException |
15 | 15 | { |
16 | - /** |
|
17 | - * @var ResponseInterface |
|
18 | - */ |
|
19 | - protected $response; |
|
20 | - /** |
|
21 | - * @param string $message |
|
22 | - */ |
|
23 | - public function __construct($message, RequestInterface $request, ResponseInterface $response, \Exception $previous = null) |
|
24 | - { |
|
25 | - parent::__construct($message, $request, $previous); |
|
26 | - $this->response = $response; |
|
27 | - $this->code = $response->getStatusCode(); |
|
28 | - } |
|
29 | - /** |
|
30 | - * Returns the response. |
|
31 | - * |
|
32 | - * @return ResponseInterface |
|
33 | - */ |
|
34 | - public function getResponse() |
|
35 | - { |
|
36 | - return $this->response; |
|
37 | - } |
|
38 | - /** |
|
39 | - * Factory method to create a new exception with a normalized error message. |
|
40 | - */ |
|
41 | - public static function create(RequestInterface $request, ResponseInterface $response, \Exception $previous = null) |
|
42 | - { |
|
43 | - $message = \sprintf('[url] %s [http method] %s [status code] %s [reason phrase] %s', $request->getRequestTarget(), $request->getMethod(), $response->getStatusCode(), $response->getReasonPhrase()); |
|
44 | - return new static($message, $request, $response, $previous); |
|
45 | - } |
|
16 | + /** |
|
17 | + * @var ResponseInterface |
|
18 | + */ |
|
19 | + protected $response; |
|
20 | + /** |
|
21 | + * @param string $message |
|
22 | + */ |
|
23 | + public function __construct($message, RequestInterface $request, ResponseInterface $response, \Exception $previous = null) |
|
24 | + { |
|
25 | + parent::__construct($message, $request, $previous); |
|
26 | + $this->response = $response; |
|
27 | + $this->code = $response->getStatusCode(); |
|
28 | + } |
|
29 | + /** |
|
30 | + * Returns the response. |
|
31 | + * |
|
32 | + * @return ResponseInterface |
|
33 | + */ |
|
34 | + public function getResponse() |
|
35 | + { |
|
36 | + return $this->response; |
|
37 | + } |
|
38 | + /** |
|
39 | + * Factory method to create a new exception with a normalized error message. |
|
40 | + */ |
|
41 | + public static function create(RequestInterface $request, ResponseInterface $response, \Exception $previous = null) |
|
42 | + { |
|
43 | + $message = \sprintf('[url] %s [http method] %s [status code] %s [reason phrase] %s', $request->getRequestTarget(), $request->getMethod(), $response->getStatusCode(), $response->getReasonPhrase()); |
|
44 | + return new static($message, $request, $response, $previous); |
|
45 | + } |
|
46 | 46 | } |