Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
AppendStream.php
001 <?php
002 namespace GuzzleHttp\Stream;
003
004 use GuzzleHttp\Stream\Exception\CannotAttachException;
005
006 /**
007 * Reads from multiple streams, one after the other.
008 *
009 * This is a read-only stream decorator.
010 */
011 class AppendStream implements StreamInterface
012 {
013 /** @var StreamInterface[] Streams being decorated */
014 private $streams = [];
015
016 private $seekable = true;
017 private $current = 0;
018 private $pos = 0;
019 private $detached = false;
020
021 /**
022 * @param StreamInterface[] $streams Streams to decorate. Each stream must
023 * be readable.
024 */
025 public function __construct(array $streams = [])
026 {
027 foreach ($streams as $stream) {
028 $this->addStream($stream);
029 }
030 }
031
032 public function __toString()
033 {
034 try {
035 $this->seek(0);
036 return $this->getContents();
037 } catch (\Exception $e) {
038 return '';
039 }
040 }
041
042 /**
043 * Add a stream to the AppendStream
044 *
045 * @param StreamInterface $stream Stream to append. Must be readable.
046 *
047 * @throws \InvalidArgumentException if the stream is not readable
048 */
049 public function addStream(StreamInterface $stream)
050 {
051 if (!$stream->isReadable()) {
052 throw new \InvalidArgumentException('Each stream must be readable');
053 }
054
055 // The stream is only seekable if all streams are seekable
056 if (!$stream->isSeekable()) {
057 $this->seekable = false;
058 }
059
060 $this->streams[] = $stream;
061 }
062
063 public function getContents()
064 {
065 return Utils::copyToString($this);
066 }
067
068 /**
069 * Closes each attached stream.
070 *
071 * {@inheritdoc}
072 */
073 public function close()
074 {
075 $this->pos = $this->current = 0;
076
077 foreach ($this->streams as $stream) {
078 $stream->close();
079 }
080
081 $this->streams = [];
082 }
083
084 /**
085 * Detaches each attached stream
086 *
087 * {@inheritdoc}
088 */
089 public function detach()
090 {
091 $this->close();
092 $this->detached = true;
093 }
094
095 public function attach($stream)
096 {
097 throw new CannotAttachException();
098 }
099
100 public function tell()
101 {
102 return $this->pos;
103 }
104
105 /**
106 * Tries to calculate the size by adding the size of each stream.
107 *
108 * If any of the streams do not return a valid number, then the size of the
109 * append stream cannot be determined and null is returned.
110 *
111 * {@inheritdoc}
112 */
113 public function getSize()
114 {
115 $size = 0;
116
117 foreach ($this->streams as $stream) {
118 $s = $stream->getSize();
119 if ($s === null) {
120 return null;
121 }
122 $size += $s;
123 }
124
125 return $size;
126 }
127
128 public function eof()
129 {
130 return !$this->streams ||
131 ($this->current >= count($this->streams) - 1 &&
132 $this->streams[$this->current]->eof());
133 }
134
135 /**
136 * Attempts to seek to the given position. Only supports SEEK_SET.
137 *
138 * {@inheritdoc}
139 */
140 public function seek($offset, $whence = SEEK_SET)
141 {
142 if (!$this->seekable || $whence !== SEEK_SET) {
143 return false;
144 }
145
146 $success = true;
147 $this->pos = $this->current = 0;
148
149 // Rewind each stream
150 foreach ($this->streams as $stream) {
151 if (!$stream->seek(0)) {
152 $success = false;
153 }
154 }
155
156 if (!$success) {
157 return false;
158 }
159
160 // Seek to the actual position by reading from each stream
161 while ($this->pos < $offset && !$this->eof()) {
162 $this->read(min(8096, $offset - $this->pos));
163 }
164
165 return $this->pos == $offset;
166 }
167
168 /**
169 * Reads from all of the appended streams until the length is met or EOF.
170 *
171 * {@inheritdoc}
172 */
173 public function read($length)
174 {
175 $buffer = '';
176 $total = count($this->streams) - 1;
177 $remaining = $length;
178
179 while ($remaining > 0) {
180 // Progress to the next stream if needed.
181 if ($this->streams[$this->current]->eof()) {
182 if ($this->current == $total) {
183 break;
184 }
185 $this->current++;
186 }
187 $buffer .= $this->streams[$this->current]->read($remaining);
188 $remaining = $length - strlen($buffer);
189 }
190
191 $this->pos += strlen($buffer);
192
193 return $buffer;
194 }
195
196 public function isReadable()
197 {
198 return true;
199 }
200
201 public function isWritable()
202 {
203 return false;
204 }
205
206 public function isSeekable()
207 {
208 return $this->seekable;
209 }
210
211 public function write($string)
212 {
213 return false;
214 }
215
216 public function getMetadata($key = null)
217 {
218 return $key ? null : [];
219 }
220 }
221