11<?php
2+
23/**
34 * A statement that prepare a request and execute them.
45 * The statement contains request, response and errors
78 * Date: 29/05/15
89 * Time: 14:21
910 */
10- namespace evaisse \SimpleHttpBundle \Http ;
1111
12+ namespace evaisse \SimpleHttpBundle \Http ;
1213
1314use evaisse \SimpleHttpBundle \Http \Exception \RequestNotSentException ;
15+ use Psr \Log \LoggerAwareInterface ;
16+ use Psr \Log \LoggerAwareTrait ;
1417use React \Promise \Deferred ;
1518use React \Promise \Promise ;
16-
17- use Symfony \Component \DependencyInjection \ContainerAwareTrait ;
18- use Symfony \Component \EventDispatcher \EventDispatcher ;
1919use Symfony \Component \HttpFoundation \File \File ;
2020use Symfony \Component \HttpFoundation \File \UploadedFile ;
2121use Symfony \Component \HttpFoundation \Request ;
2222use Symfony \Component \HttpKernel \Exception \HttpException ;
2323use Symfony \Contracts \EventDispatcher \EventDispatcherInterface ;
24+ use Throwable ;
25+
26+ use function React \Promise \set_rejection_handler ;
2427
25- class Statement
28+ class Statement implements LoggerAwareInterface
2629{
30+ use LoggerAwareTrait;
31+
2732 /** @var Kernel */
2833 protected $ httpKernel ;
29-
34+
3035 /**
3136 * $request : Service Request
3237 *
@@ -38,7 +43,7 @@ class Statement
3843 /**
3944 * $error : Error
4045 *
41- * @var Error
46+ * @var HttpException
4247 * @access protected
4348 */
4449 protected $ error ;
@@ -122,7 +127,7 @@ public function setHttpKernel(Kernel $httpKernel): void
122127 {
123128 $ this ->httpKernel = $ httpKernel ;
124129 }
125-
130+
126131 /**
127132 *
128133 * @param Request $request An http request object to send
@@ -134,6 +139,12 @@ public function __construct(Request $request, EventDispatcherInterface $eventDis
134139 $ this ->promise = $ this ->deferred ->promise ();
135140 $ this ->eventDispatcher = $ eventDispatcher ;
136141 $ this ->httpKernel = $ httpKernel ;
142+
143+ if (function_exists ('React\Promise\set_rejection_handler ' )) {
144+ set_rejection_handler (fn (Throwable $ e ) => $ this ->logger ?->warning(
145+ 'Unhandled promise rejection with ' . $ e ->getMessage (),
146+ ));
147+ }
137148 }
138149
139150
@@ -259,7 +270,6 @@ public function json($json = null)
259270 $ json = (string ) $ json ;
260271 } else {
261272 $ json = json_encode (null );
262-
263273 }
264274 $ this ->request ->setContent ($ json );
265275 }
@@ -374,7 +384,8 @@ public function attachFile($key, $filepath, $mimetype = null, $clientName = null
374384 $ file ->getRealPath (),
375385 $ clientName ,
376386 $ file ->getMimeType (),
377- 0 );
387+ 0
388+ );
378389
379390 $ this ->getRequest ()->files ->set ($ key , $ file );
380391 }
@@ -447,9 +458,9 @@ public function authorizeOAuth($consumerKey, $consumerSecret)
447458 }
448459
449460 /**
450- * @param string $key The key
451- * @param string|array $values The value or an array of values
452- * @param bool $replace Whether to replace the actual value or not (true by default)
461+ * @param string $key The key
462+ * @param string|array $values The value or an array of values
463+ * @param bool $replace Whether to replace the actual value or not (true by default)
453464 *
454465 * @return self
455466 */
@@ -458,5 +469,4 @@ public function setHeader($key, $values, $replace = true)
458469 $ this ->request ->headers ->set ($ key , $ values , $ replace );
459470 return $ this ;
460471 }
461-
462- }
472+ }
0 commit comments