Skip to content

Commit

Permalink
Use full namespace in function checks
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowhand committed Jul 23, 2021
1 parent f69b581 commit 6e1efa1
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/StreamFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,37 @@
use Psr\Http\Message\StreamFactoryInterface;
use Psr\Http\Message\StreamInterface;

use function function_exists;
use function GuzzleHttp\Psr7\stream_for;
use function GuzzleHttp\Psr7\try_fopen;

class StreamFactory implements StreamFactoryInterface
{
public function createStream(string $content = ''): StreamInterface
{
if (\function_exists('stream_for')) {
if (function_exists('GuzzleHttp\Psr7\stream_for')) {
// fallback for guzzlehttp/psr7<1.7.0
return stream_for($content);
}

return Utils::streamFor($content);
}

public function createStreamFromFile(string $file, string $mode = 'r'): StreamInterface
{
if (\function_exists('try_fopen') && \function_exists('steam_for')) {
if (function_exists('GuzzleHttp\Psr7\try_fopen')) {
// fallback for guzzlehttp/psr7<1.7.0
$resource = try_fopen($file, $mode);

return stream_for($resource);
} else {
$resource = Utils::tryFopen($file, $mode);
}
$resource = Utils::tryFopen($file, $mode);

return new Stream($resource);

return $this->createStreamFromResource($resource);
}

public function createStreamFromResource($resource): StreamInterface
{
if (\function_exists('stream_for')) {
// fallback for guzzlehttp/psr7<1.7.0
return stream_for($resource);
}
return new Stream($resource);
}
}

0 comments on commit 6e1efa1

Please sign in to comment.