Skip to content

Commit a28ea08

Browse files
committed
Added stream factory property
1 parent 035beea commit a28ea08

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/Http/CurlDispatcher.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Psr\Http\Message\RequestInterface;
88
use Psr\Http\Message\ResponseFactoryInterface;
99
use Psr\Http\Message\ResponseInterface;
10+
use Psr\Http\Message\StreamFactoryInterface;
1011
use 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

Comments
 (0)