1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Zapheus\Bridge\Psr\Zapheus; |
4
|
|
|
|
5
|
|
|
use Psr\Http\Message\StreamInterface; |
6
|
|
|
use Zapheus\Bridge\Psr\Interop\Stream as AbstractStream; |
7
|
|
|
use Zapheus\Http\Message\StreamInterface as ZapheusStreamInterface; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* PSR-07 to Zapheus Stream Bridge |
11
|
|
|
* |
12
|
|
|
* @package Zapheus |
13
|
|
|
* @author Rougin Royce Gutib <[email protected]> |
14
|
|
|
*/ |
15
|
|
|
class Stream extends AbstractStream implements ZapheusStreamInterface |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var \Psr\Http\Message\StreamInterface |
19
|
|
|
*/ |
20
|
|
|
protected $stream; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Initializes the stream instance. |
24
|
|
|
* |
25
|
|
|
* @param \Psr\Http\Message\StreamInterface $stream |
26
|
|
|
*/ |
27
|
84 |
|
public function __construct(StreamInterface $stream) |
28
|
|
|
{ |
29
|
84 |
|
$this->stream = $stream; |
30
|
84 |
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Returns the remaining contents in a string |
34
|
|
|
* |
35
|
|
|
* @return string |
36
|
|
|
* |
37
|
|
|
* @throws \RuntimeException |
38
|
|
|
*/ |
39
|
6 |
|
public function contents() |
40
|
|
|
{ |
41
|
6 |
|
return $this->stream->getContents(); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Get stream metadata as an associative array or retrieve a specific key. |
46
|
|
|
* |
47
|
|
|
* @param string $key |
48
|
|
|
* @return array|mixed|null |
49
|
|
|
*/ |
50
|
3 |
|
public function metadata($key = null) |
51
|
|
|
{ |
52
|
3 |
|
return $this->stream->getMetadata($key); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Get the size of the stream if known. |
57
|
|
|
* |
58
|
|
|
* @return integer|null |
59
|
|
|
*/ |
60
|
3 |
|
public function size() |
61
|
|
|
{ |
62
|
3 |
|
return $this->stream->getSize(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Returns whether or not the stream is readable. |
67
|
|
|
* |
68
|
|
|
* @return boolean |
69
|
|
|
*/ |
70
|
3 |
|
public function readable() |
71
|
|
|
{ |
72
|
3 |
|
return $this->stream->isReadable(); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Returns whether or not the stream is seekable. |
77
|
|
|
* |
78
|
|
|
* @return boolean |
79
|
|
|
*/ |
80
|
3 |
|
public function seekable() |
81
|
|
|
{ |
82
|
3 |
|
return $this->stream->isSeekable(); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Returns whether or not the stream is writable. |
87
|
|
|
* |
88
|
|
|
* @return boolean |
89
|
|
|
*/ |
90
|
3 |
|
public function writable() |
91
|
|
|
{ |
92
|
3 |
|
return $this->stream->isWritable(); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|