1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Zapheus\Bridge\Psr\Zapheus; |
4
|
|
|
|
5
|
|
|
use Psr\Http\Message\StreamInterface as PsrStreamInterface; |
6
|
|
|
use Zapheus\Http\Message\StreamInterface; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* PSR-07 to Zapheus Stream Bridge |
10
|
|
|
* |
11
|
|
|
* @package Zapheus |
12
|
|
|
* @author Rougin Gutib <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
class Stream implements StreamInterface |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var \Psr\Http\Message\StreamInterface |
18
|
|
|
*/ |
19
|
|
|
protected $stream; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Initializes the stream instance. |
23
|
|
|
* |
24
|
|
|
* @param \Psr\Http\Message\StreamInterface $stream |
25
|
|
|
*/ |
26
|
57 |
|
public function __construct(PsrStreamInterface $stream) |
27
|
|
|
{ |
28
|
57 |
|
$this->stream = $stream; |
29
|
57 |
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Reads all data from the stream into a string, from the beginning to end. |
33
|
|
|
* |
34
|
|
|
* @return string |
35
|
|
|
*/ |
36
|
6 |
|
public function __toString() |
37
|
|
|
{ |
38
|
6 |
|
return $this->stream->__toString(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Closes the stream and any underlying resources. |
43
|
|
|
* |
44
|
|
|
* @return void |
45
|
|
|
*/ |
46
|
6 |
|
public function close() |
47
|
|
|
{ |
48
|
6 |
|
$this->stream->close(); |
49
|
6 |
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Returns the remaining contents in a string. |
53
|
|
|
* |
54
|
|
|
* @return string |
55
|
|
|
* |
56
|
|
|
* @throws \RuntimeException |
57
|
|
|
*/ |
58
|
6 |
|
public function contents() |
59
|
|
|
{ |
60
|
6 |
|
return $this->stream->getContents(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Read data from the stream. |
65
|
|
|
* |
66
|
|
|
* @param integer $length |
67
|
|
|
* @return string |
68
|
|
|
* |
69
|
|
|
* @throws \RuntimeException |
70
|
|
|
*/ |
71
|
6 |
|
public function read($length) |
72
|
|
|
{ |
73
|
6 |
|
return $this->stream->read($length); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Seek to the beginning of the stream. |
78
|
|
|
* |
79
|
|
|
* @throws \RuntimeException |
80
|
|
|
*/ |
81
|
3 |
|
public function rewind() |
82
|
|
|
{ |
83
|
3 |
|
return $this->stream->rewind(); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Write data to the stream. |
88
|
|
|
* |
89
|
|
|
* @param string $string |
90
|
|
|
* @return integer |
91
|
|
|
* |
92
|
|
|
* @throws \RuntimeException |
93
|
|
|
*/ |
94
|
6 |
|
public function write($string) |
95
|
|
|
{ |
96
|
6 |
|
return $this->stream->write($string); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|