Completed
Push — master ( 4258f5...c7dbbb )
by Anton
20s
created

StreamFactory::createStreamFromResource()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * High-performance PHP process supervisor and load balancer written in Go
6
 *
7
 * @author Wolfy-J
8
 */
9
10
namespace Spiral\RoadRunner\Diactoros;
11
12
use Psr\Http\Message\StreamFactoryInterface;
13
use Psr\Http\Message\StreamInterface;
14
use Zend\Diactoros\Stream;
15
16
final class StreamFactory implements StreamFactoryInterface
17
{
18
    /**
19
     * @inheritdoc
20
     */
21
    public function createStream(string $content = ''): StreamInterface
22
    {
23
        $resource = fopen('php://temp', 'r+');
24
        fwrite($resource, $content);
25
        rewind($resource);
26
        return $this->createStreamFromResource($resource);
27
    }
28
29
    /**
30
     * @inheritdoc
31
     */
32
    public function createStreamFromFile(string $file, string $mode = 'r'): StreamInterface
33
    {
34
        $resource = fopen($file, $mode);
35
        return $this->createStreamFromResource($resource);
36
    }
37
38
    /**
39
     * @inheritdoc
40
     */
41
    public function createStreamFromResource($resource): StreamInterface
42
    {
43
        return new Stream($resource);
44
    }
45
}