Completed
Push — master ( 71b082...d4eb58 )
by smiley
02:29
created

StreamAbstract::__destruct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Class StreamAbstract
4
 *
5
 * @filesource   StreamAbstract.php
6
 * @created      21.12.2018
7
 * @package      chillerlan\HTTP\Psr7
8
 * @author       smiley <[email protected]>
9
 * @copyright    2018 smiley
10
 * @license      MIT
11
 */
12
13
namespace chillerlan\HTTP\Psr7;
14
15
use Psr\Http\Message\StreamInterface;
16
17
abstract class StreamAbstract implements StreamInterface{
18
19
	public const MODES_READ = [
20
		'a+'  => true,
21
		'c+'  => true,
22
		'c+b' => true,
23
		'c+t' => true,
24
		'r'   => true,
25
		'r+'  => true,
26
		'rb'  => true,
27
		'rt'  => true,
28
		'r+b' => true,
29
		'r+t' => true,
30
		'w+'  => true,
31
		'w+b' => true,
32
		'w+t' => true,
33
		'x+'  => true,
34
		'x+b' => true,
35
		'x+t' => true,
36
	];
37
38
	public const MODES_WRITE = [
39
		'a'   => true,
40
		'a+'  => true,
41
		'c+'  => true,
42
		'c+b' => true,
43
		'c+t' => true,
44
		'r+'  => true,
45
		'rw'  => true,
46
		'r+b' => true,
47
		'r+t' => true,
48
		'w'   => true,
49
		'w+'  => true,
50
		'wb'  => true,
51
		'w+b' => true,
52
		'w+t' => true,
53
		'x+'  => true,
54
		'x+b' => true,
55
		'x+t' => true,
56
	];
57
58
	/**
59
	 * @var \Psr\Http\Message\StreamInterface|resource
60
	 */
61
	protected $stream;
62
63
	/**
64
	 * Closes the stream when the destructed
65
	 *
66
	 * @return void
67
	 */
68
	public function __destruct(){
69
		$this->close();
70
	}
71
72
	/**
73
	 * @inheritdoc
74
	 */
75
	public function __toString(){
76
		return (string)$this->stream;
77
	}
78
79
	/**
80
	 * @inheritdoc
81
	 */
82
	public function close(){
83
		if($this->stream instanceof StreamInterface){
84
			$this->stream->close();
85
		}
86
	}
87
88
	/**
89
	 * @inheritdoc
90
	 */
91
	public function detach(){
92
		return $this->stream->detach();
93
	}
94
95
	/**
96
	 * @inheritdoc
97
	 */
98
	public function getSize():?int{
99
		return $this->stream->getSize();
100
	}
101
102
	/**
103
	 * @inheritdoc
104
	 */
105
	public function tell():int{
106
		return $this->stream->tell();
107
	}
108
109
	/**
110
	 * @inheritdoc
111
	 */
112
	public function eof():bool{
113
		return $this->stream->eof();
114
	}
115
116
	/**
117
	 * @inheritdoc
118
	 */
119
	public function isSeekable():bool{
120
		return $this->stream->isSeekable();
121
	}
122
123
	/**
124
	 * @inheritdoc
125
	 */
126
	public function seek($offset, $whence = SEEK_SET):void{
127
		$this->stream->seek($offset, $whence);
128
	}
129
130
	/**
131
	 * @inheritdoc
132
	 */
133
	public function rewind():void{
134
		$this->stream->rewind();
135
	}
136
137
	/**
138
	 * @inheritdoc
139
	 */
140
	public function isWritable():bool{
141
		return $this->stream->isWritable();
142
	}
143
144
	/**
145
	 * @inheritdoc
146
	 */
147
	public function write($string):int{
148
		return $this->stream->write($string);
149
	}
150
151
	/**
152
	 * @inheritdoc
153
	 */
154
	public function isReadable():bool{
155
		return $this->stream->isReadable();
156
	}
157
158
	/**
159
	 * @inheritdoc
160
	 */
161
	public function read($length):string{
162
		return $this->stream->read($length);
163
	}
164
165
	/**
166
	 * @inheritdoc
167
	 */
168
	public function getContents():string{
169
		return $this->stream->getContents();
170
	}
171
172
	/**
173
	 * @inheritdoc
174
	 */
175
	public function getMetadata($key = null){
176
		return $this->stream->getMetadata($key);
177
	}
178
179
}
180