Skip to content

Commit

Permalink
Added stream factory property
Browse files Browse the repository at this point in the history
  • Loading branch information
nerg4l committed Nov 30, 2023
1 parent 035beea commit a28ea08
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Http/CurlDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\StreamFactoryInterface;
use Psr\Http\Message\StreamInterface;

/**
Expand All @@ -17,6 +18,7 @@ final class CurlDispatcher
private static int $contentLengthThreshold = 5000000;

private RequestInterface $request;
private StreamFactoryInterface $streamFactory;
private $curl;
private $result;
private array $headers = [];
Expand Down Expand Up @@ -80,11 +82,12 @@ public static function fetch(array $settings, ResponseFactoryInterface $response
);
}

private function __construct(array $settings, RequestInterface $request)
private function __construct(array $settings, RequestInterface $request, StreamFactoryInterface $streamFactory = null)
{
$this->request = $request;
$this->curl = curl_init((string) $request->getUri());
$this->settings = $settings;
$this->streamFactory = $streamFactory ?? FactoryDiscovery::getStreamFactory();

$cookies = $settings['cookies_path'] ?? str_replace('//', '/', sys_get_temp_dir().'/embed-cookies.txt');

Expand Down Expand Up @@ -204,7 +207,7 @@ private function writeBody($curl, $string): int
}

if (!$this->body) {
$this->body = FactoryDiscovery::getStreamFactory()->createStreamFromFile('php://temp', 'w+');
$this->body = $this->streamFactory->createStreamFromFile('php://temp', 'w+');
}

if ($this->body->getSize() > self::$contentLengthThreshold) {
Expand Down

0 comments on commit a28ea08

Please sign in to comment.