File tree Expand file tree Collapse file tree 3 files changed +20
-34
lines changed Expand file tree Collapse file tree 3 files changed +20
-34
lines changed Original file line number Diff line number Diff line change @@ -36,24 +36,24 @@ function it_creates_a_stream_from_non_seekable_resource()
36
36
->shouldHaveType ('Psr\Http\Message\StreamInterface ' );
37
37
}
38
38
39
- function it_rewinds_existing_stream ()
39
+ function it_does_not_rewind_existing_stream ()
40
40
{
41
41
$ stream = new Stream (fopen ('php://memory ' , 'rw ' ));
42
42
$ stream ->write ('abcdef ' );
43
- $ stream ->read (3 );
43
+ $ stream ->seek (3 );
44
44
45
45
$ this ->createStream ($ stream )
46
- ->shouldHaveContent ('abcdef ' );
46
+ ->shouldHaveContent ('def ' );
47
47
}
48
48
49
- function it_rewinds_existing_resource ()
49
+ function it_does_not_rewind_existing_resource ()
50
50
{
51
51
$ resource = fopen ('php://memory ' , 'rw ' );
52
52
fwrite ($ resource , 'abcdef ' );
53
- fread ($ resource , 3 );
53
+ fseek ($ resource , 3 );
54
54
55
55
$ this ->createStream ($ resource )
56
- ->shouldHaveContent ('abcdef ' );
56
+ ->shouldHaveContent ('def ' );
57
57
}
58
58
59
59
public function getMatchers ()
Original file line number Diff line number Diff line change @@ -18,26 +18,19 @@ final class DiactorosStreamFactory implements StreamFactory
18
18
*/
19
19
public function createStream ($ body = null )
20
20
{
21
- if (!$ body instanceof StreamInterface) {
22
- if (is_resource ($ body )) {
23
- $ body = new Stream ($ body );
24
- } else {
25
- $ stream = new Stream ('php://memory ' , 'rw ' );
26
-
27
- if (null === $ body || '' === $ body ) {
28
- return $ stream ;
29
- }
30
-
31
- $ stream ->write ((string ) $ body );
21
+ if ($ body instanceof StreamInterface) {
22
+ return $ body ;
23
+ }
32
24
33
- $ body = $ stream ;
34
- }
25
+ if ( is_resource ( $ body)) {
26
+ return new Stream ( $ body );
35
27
}
36
28
37
- if ($ body ->isSeekable ()) {
38
- $ body ->rewind ();
29
+ $ stream = new Stream ('php://memory ' , 'rw ' );
30
+ if (null !== $ body && '' !== $ body ) {
31
+ $ stream ->write ((string ) $ body );
39
32
}
40
33
41
- return $ body ;
34
+ return $ stream ;
42
35
}
43
36
}
Original file line number Diff line number Diff line change @@ -23,20 +23,13 @@ public function createStream($body = null)
23
23
}
24
24
25
25
if (is_resource ($ body )) {
26
- $ stream = new Stream ($ body );
27
- } else {
28
- $ resource = fopen ('php://memory ' , 'r+ ' );
29
- $ stream = new Stream ($ resource );
30
-
31
- if (null === $ body || '' === $ body ) {
32
- return $ stream ;
33
- }
34
-
35
- $ stream ->write ((string ) $ body );
26
+ return new Stream ($ body );
36
27
}
37
28
38
- if ($ stream ->isSeekable ()) {
39
- $ stream ->rewind ();
29
+ $ resource = fopen ('php://memory ' , 'r+ ' );
30
+ $ stream = new Stream ($ resource );
31
+ if (null !== $ body && '' !== $ body ) {
32
+ $ stream ->write ((string ) $ body );
40
33
}
41
34
42
35
return $ stream ;
You can’t perform that action at this time.
0 commit comments