|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Class StreamAbstract |
|
4
|
|
|
* |
|
5
|
|
|
* @created 21.12.2018 |
|
6
|
|
|
* @author smiley <[email protected]> |
|
7
|
|
|
* @copyright 2018 smiley |
|
8
|
|
|
* @license MIT |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace chillerlan\HTTP\Psr7; |
|
12
|
|
|
|
|
13
|
|
|
use Psr\Http\Message\StreamInterface; |
|
14
|
|
|
|
|
15
|
|
|
use const SEEK_SET; |
|
16
|
|
|
|
|
17
|
|
|
abstract class StreamAbstract implements StreamInterface{ |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var \Psr\Http\Message\StreamInterface|resource|null |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $stream = null; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Closes the stream when the destructed |
|
26
|
|
|
* |
|
27
|
|
|
* @return void |
|
28
|
|
|
*/ |
|
29
|
|
|
public function __destruct(){ |
|
30
|
|
|
$this->close(); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @inheritDoc |
|
35
|
|
|
* @codeCoverageIgnore |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __toString(){ |
|
38
|
|
|
return (string)$this->stream; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @inheritDoc |
|
43
|
|
|
*/ |
|
44
|
|
|
public function close(){ |
|
45
|
|
|
if($this->stream instanceof StreamInterface){ |
|
46
|
|
|
$this->stream->close(); |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @inheritDoc |
|
52
|
|
|
* @codeCoverageIgnore |
|
53
|
|
|
*/ |
|
54
|
|
|
public function detach(){ |
|
55
|
|
|
return $this->stream->detach(); |
|
|
|
|
|
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @inheritDoc |
|
60
|
|
|
* @codeCoverageIgnore |
|
61
|
|
|
*/ |
|
62
|
|
|
public function getSize():?int{ |
|
63
|
|
|
return $this->stream->getSize(); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @inheritDoc |
|
68
|
|
|
* @codeCoverageIgnore |
|
69
|
|
|
*/ |
|
70
|
|
|
public function tell():int{ |
|
71
|
|
|
return $this->stream->tell(); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @inheritDoc |
|
76
|
|
|
* @codeCoverageIgnore |
|
77
|
|
|
*/ |
|
78
|
|
|
public function eof():bool{ |
|
79
|
|
|
return $this->stream->eof(); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @inheritDoc |
|
84
|
|
|
* @codeCoverageIgnore |
|
85
|
|
|
*/ |
|
86
|
|
|
public function isSeekable():bool{ |
|
87
|
|
|
return $this->stream->isSeekable(); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @inheritDoc |
|
92
|
|
|
* @codeCoverageIgnore |
|
93
|
|
|
*/ |
|
94
|
|
|
public function seek($offset, $whence = SEEK_SET):void{ |
|
95
|
|
|
$this->stream->seek($offset, $whence); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @inheritDoc |
|
100
|
|
|
* @codeCoverageIgnore |
|
101
|
|
|
*/ |
|
102
|
|
|
public function rewind():void{ |
|
103
|
|
|
$this->stream->rewind(); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @inheritDoc |
|
108
|
|
|
* @codeCoverageIgnore |
|
109
|
|
|
*/ |
|
110
|
|
|
public function isWritable():bool{ |
|
111
|
|
|
return $this->stream->isWritable(); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @inheritDoc |
|
116
|
|
|
* @codeCoverageIgnore |
|
117
|
|
|
*/ |
|
118
|
|
|
public function write($string):int{ |
|
119
|
|
|
return $this->stream->write($string); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* @inheritDoc |
|
124
|
|
|
* @codeCoverageIgnore |
|
125
|
|
|
*/ |
|
126
|
|
|
public function isReadable():bool{ |
|
127
|
|
|
return $this->stream->isReadable(); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* @inheritDoc |
|
132
|
|
|
* @codeCoverageIgnore |
|
133
|
|
|
*/ |
|
134
|
|
|
public function read($length):string{ |
|
135
|
|
|
return $this->stream->read($length); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* @inheritDoc |
|
140
|
|
|
* @codeCoverageIgnore |
|
141
|
|
|
*/ |
|
142
|
|
|
public function getContents():string{ |
|
143
|
|
|
return $this->stream->getContents(); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* @inheritDoc |
|
148
|
|
|
* @codeCoverageIgnore |
|
149
|
|
|
*/ |
|
150
|
|
|
public function getMetadata($key = null){ |
|
151
|
|
|
return $this->stream->getMetadata($key); |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
} |
|
155
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.