7
7
use Psr \Http \Message \RequestFactoryInterface ;
8
8
use Psr \Http \Message \RequestInterface ;
9
9
use Psr \Http \Message \StreamFactoryInterface ;
10
+ use Psr \Http \Message \UriFactoryInterface ;
11
+ use Psr \Http \Message \UriInterface ;
10
12
11
13
use function http_build_query ;
14
+ use function is_string ;
12
15
13
16
use const PHP_QUERY_RFC3986 ;
14
17
@@ -17,6 +20,8 @@ final class RequestFactory
17
20
public function __construct (
18
21
private RequestFactoryInterface $ requestFactory ,
19
22
private StreamFactoryInterface $ streamFactory ,
23
+ private UriFactoryInterface |null $ uriFactory = null ,
24
+ private UriInterface |string $ uri = '' ,
20
25
) {
21
26
}
22
27
@@ -29,7 +34,20 @@ public function prepareRequest(RequestOptions $requestOptions): RequestInterface
29
34
PHP_QUERY_RFC3986 ,
30
35
);
31
36
32
- return $ this ->requestFactory ->createRequest ('POST ' , $ query === '' ? '' : '? ' . $ query )
37
+ if ($ this ->uriFactory === null ) {
38
+ return $ this ->requestFactory ->createRequest ('POST ' , $ query === '' ? '' : '? ' . $ query )
39
+ ->withBody ($ this ->streamFactory ->createStream ($ requestOptions ->sql ));
40
+ }
41
+
42
+ $ uri = $ this ->uri ;
43
+ if (is_string ($ uri )) {
44
+ $ uri = $ this ->uriFactory ->createUri ($ uri );
45
+ }
46
+
47
+ $ uriQuery = $ uri ->getQuery ();
48
+ $ uri = $ uri ->withQuery ($ uriQuery . ($ uriQuery !== '' && $ query !== '' ? '& ' : '' ) . $ query );
49
+
50
+ return $ this ->requestFactory ->createRequest ('POST ' , $ uri )
33
51
->withBody ($ this ->streamFactory ->createStream ($ requestOptions ->sql ));
34
52
}
35
53
}
0 commit comments