77use Psr \Http \Message \RequestInterface ;
88use Psr \Http \Message \ResponseFactoryInterface ;
99use Psr \Http \Message \ResponseInterface ;
10+ use Psr \Http \Message \StreamFactoryInterface ;
1011use Psr \Http \Message \StreamInterface ;
1112
1213/**
@@ -17,6 +18,7 @@ final class CurlDispatcher
1718 private static int $ contentLengthThreshold = 5000000 ;
1819
1920 private RequestInterface $ request ;
21+ private StreamFactoryInterface $ streamFactory ;
2022 private $ curl ;
2123 private $ result ;
2224 private array $ headers = [];
@@ -80,11 +82,12 @@ public static function fetch(array $settings, ResponseFactoryInterface $response
8082 );
8183 }
8284
83- private function __construct (array $ settings , RequestInterface $ request )
85+ private function __construct (array $ settings , RequestInterface $ request, StreamFactoryInterface $ streamFactory = null )
8486 {
8587 $ this ->request = $ request ;
8688 $ this ->curl = curl_init ((string ) $ request ->getUri ());
8789 $ this ->settings = $ settings ;
90+ $ this ->streamFactory = $ streamFactory ?? FactoryDiscovery::getStreamFactory ();
8891
8992 $ cookies = $ settings ['cookies_path ' ] ?? str_replace ('// ' , '/ ' , sys_get_temp_dir ().'/embed-cookies.txt ' );
9093
@@ -204,7 +207,7 @@ private function writeBody($curl, $string): int
204207 }
205208
206209 if (!$ this ->body ) {
207- $ this ->body = FactoryDiscovery:: getStreamFactory () ->createStreamFromFile ('php://temp ' , 'w+ ' );
210+ $ this ->body = $ this -> streamFactory ->createStreamFromFile ('php://temp ' , 'w+ ' );
208211 }
209212
210213 if ($ this ->body ->getSize () > self ::$ contentLengthThreshold ) {
0 commit comments