1111
1212namespace  Discord \Http ;
1313
14+ use  Composer \InstalledVersions ;
1415use  Discord \Http \Exceptions \BadRequestException ;
1516use  Discord \Http \Exceptions \ContentTooLongException ;
1617use  Discord \Http \Exceptions \InvalidTokenException ;
2425use  Psr \Log \LoggerInterface ;
2526use  React \EventLoop \LoopInterface ;
2627use  React \Promise \Deferred ;
27- use  React \Promise \ExtendedPromiseInterface ;
28+ use  React \Promise \PromiseInterface ;
2829use  SplQueue ;
2930
3031/** 
@@ -127,6 +128,12 @@ class Http
127128     */ 
128129    protected  $ waiting0 ;
129130
131+ 
132+     /** 
133+      * Whether react/promise v3 is used, if false, using v2 
134+      */ 
135+     protected  $ promiseV3true ;
136+ 
130137    /** 
131138     * Http wrapper constructor. 
132139     * 
@@ -141,6 +148,8 @@ public function __construct(string $token, LoopInterface $loop, LoggerInterface
141148        $ this logger  = $ logger
142149        $ this driver  = $ driver
143150        $ this queue  = new  SplQueue ;
151+ 
152+         $ this promiseV3  = str_starts_with (InstalledVersions::getVersion ('react/promise ' ), '0.3. ' );
144153    }
145154
146155    /** 
@@ -160,9 +169,9 @@ public function setDriver(DriverInterface $driver): void
160169     * @param mixed           $content 
161170     * @param array           $headers 
162171     * 
163-      * @return ExtendedPromiseInterface  
172+      * @return PromiseInterface  
164173     */ 
165-     public  function  get ($ url$ contentnull , array  $ headersExtendedPromiseInterface 
174+     public  function  get ($ url$ contentnull , array  $ headersPromiseInterface 
166175    {
167176        if  (! ($ urlinstanceof  Endpoint)) {
168177            $ urlbind ($ url
@@ -178,9 +187,9 @@ public function get($url, $content = null, array $headers = []): ExtendedPromise
178187     * @param mixed           $content 
179188     * @param array           $headers 
180189     * 
181-      * @return ExtendedPromiseInterface  
190+      * @return PromiseInterface  
182191     */ 
183-     public  function  post ($ url$ contentnull , array  $ headersExtendedPromiseInterface 
192+     public  function  post ($ url$ contentnull , array  $ headersPromiseInterface 
184193    {
185194        if  (! ($ urlinstanceof  Endpoint)) {
186195            $ urlbind ($ url
@@ -196,9 +205,9 @@ public function post($url, $content = null, array $headers = []): ExtendedPromis
196205     * @param mixed           $content 
197206     * @param array           $headers 
198207     * 
199-      * @return ExtendedPromiseInterface  
208+      * @return PromiseInterface  
200209     */ 
201-     public  function  put ($ url$ contentnull , array  $ headersExtendedPromiseInterface 
210+     public  function  put ($ url$ contentnull , array  $ headersPromiseInterface 
202211    {
203212        if  (! ($ urlinstanceof  Endpoint)) {
204213            $ urlbind ($ url
@@ -214,9 +223,9 @@ public function put($url, $content = null, array $headers = []): ExtendedPromise
214223     * @param mixed           $content 
215224     * @param array           $headers 
216225     * 
217-      * @return ExtendedPromiseInterface  
226+      * @return PromiseInterface  
218227     */ 
219-     public  function  patch ($ url$ contentnull , array  $ headersExtendedPromiseInterface 
228+     public  function  patch ($ url$ contentnull , array  $ headersPromiseInterface 
220229    {
221230        if  (! ($ urlinstanceof  Endpoint)) {
222231            $ urlbind ($ url
@@ -232,9 +241,9 @@ public function patch($url, $content = null, array $headers = []): ExtendedPromi
232241     * @param mixed           $content 
233242     * @param array           $headers 
234243     * 
235-      * @return ExtendedPromiseInterface  
244+      * @return PromiseInterface  
236245     */ 
237-     public  function  delete ($ url$ contentnull , array  $ headersExtendedPromiseInterface 
246+     public  function  delete ($ url$ contentnull , array  $ headersPromiseInterface 
238247    {
239248        if  (! ($ urlinstanceof  Endpoint)) {
240249            $ urlbind ($ url
@@ -251,9 +260,9 @@ public function delete($url, $content = null, array $headers = []): ExtendedProm
251260     * @param mixed    $content 
252261     * @param array    $headers 
253262     * 
254-      * @return ExtendedPromiseInterface  
263+      * @return PromiseInterface  
255264     */ 
256-     public  function  queueRequest (string  $ methodEndpoint $ url$ contentarray  $ headersExtendedPromiseInterface 
265+     public  function  queueRequest (string  $ methodEndpoint $ url$ contentarray  $ headersPromiseInterface 
257266    {
258267        $ deferrednew  Deferred ();
259268
@@ -318,9 +327,9 @@ protected function guessContent(&$content)
318327     * @param Request  $request 
319328     * @param Deferred $deferred 
320329     * 
321-      * @return ExtendedPromiseInterface  
330+      * @return PromiseInterface  
322331     */ 
323-     protected  function  executeRequest (Request $ requestDeferred $ deferrednull ): ExtendedPromiseInterface 
332+     protected  function  executeRequest (Request $ requestDeferred $ deferrednull ): PromiseInterface 
324333    {
325334        if  ($ deferrednull ) {
326335            $ deferrednew  Deferred ();
@@ -332,7 +341,8 @@ protected function executeRequest(Request $request, Deferred $deferred = null):
332341            return  $ deferredpromise ();
333342        }
334343
335-         $ this driver ->runRequest ($ requestdone (function  (ResponseInterface $ responseuse  ($ request$ deferred
344+         // Promises v3 changed `->then` to behave as `->done` and removed `->then`. We still need the behaviour of `->done` in projects using v2 
345+         $ this driver ->runRequest ($ request$ this promiseV3  ? 'then '  : 'done ' }(function  (ResponseInterface $ responseuse  ($ request$ deferred
336346            $ datajson_decode ((string ) $ responsegetBody ());
337347            $ statusCode$ responsegetStatusCode ();
338348
0 commit comments