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 |
PumpStream.php
001 <?php
002 namespace GuzzleHttp\Stream;
003
004 use GuzzleHttp\Stream\Exception\CannotAttachException;
005
006 /**
007 * Provides a read only stream that pumps data from a PHP callable.
008 *
009 * When invoking the provided callable, the PumpStream will pass the amount of
010 * data requested to read to the callable. The callable can choose to ignore
011 * this value and return fewer or more bytes than requested. Any extra data
012 * returned by the provided callable is buffered internally until drained using
013 * the read() function of the PumpStream. The provided callable MUST return
014 * false when there is no more data to read.
015 */
016 class PumpStream implements StreamInterface
017 {
018 /** @var callable */
019 private $source;
020
021 /** @var int */
022 private $size;
023
024 /** @var int */
025 private $tellPos = 0;
026
027 /** @var array */
028 private $metadata;
029
030 /** @var BufferStream */
031 private $buffer;
032
033 /**
034 * @param callable $source Source of the stream data. The callable MAY
035 * accept an integer argument used to control the
036 * amount of data to return. The callable MUST
037 * return a string when called, or false on error
038 * or EOF.
039 * @param array $options Stream options:
040 * - metadata: Hash of metadata to use with stream.
041 * - size: Size of the stream, if known.
042 */
043 public function __construct(callable $source, array $options = [])
044 {
045 $this->source = $source;
046 $this->size = isset($options['size']) ? $options['size'] : null;
047 $this->metadata = isset($options['metadata']) ? $options['metadata'] : [];
048 $this->buffer = new BufferStream();
049 }
050
051 public function __toString()
052 {
053 return Utils::copyToString($this);
054 }
055
056 public function close()
057 {
058 $this->detach();
059 }
060
061 public function detach()
062 {
063 $this->tellPos = false;
064 $this->source = null;
065 }
066
067 public function attach($stream)
068 {
069 throw new CannotAttachException();
070 }
071
072 public function getSize()
073 {
074 return $this->size;
075 }
076
077 public function tell()
078 {
079 return $this->tellPos;
080 }
081
082 public function eof()
083 {
084 return !$this->source;
085 }
086
087 public function isSeekable()
088 {
089 return false;
090 }
091
092 public function seek($offset, $whence = SEEK_SET)
093 {
094 return false;
095 }
096
097 public function isWritable()
098 {
099 return false;
100 }
101
102 public function write($string)
103 {
104 return false;
105 }
106
107 public function isReadable()
108 {
109 return true;
110 }
111
112 public function read($length)
113 {
114 $data = $this->buffer->read($length);
115 $readLen = strlen($data);
116 $this->tellPos += $readLen;
117 $remaining = $length - $readLen;
118
119 if ($remaining) {
120 $this->pump($remaining);
121 $data .= $this->buffer->read($remaining);
122 $this->tellPos += strlen($data) - $readLen;
123 }
124
125 return $data;
126 }
127
128 public function getContents()
129 {
130 $result = '';
131 while (!$this->eof()) {
132 $result .= $this->read(1000000);
133 }
134
135 return $result;
136 }
137
138 public function getMetadata($key = null)
139 {
140 if (!$key) {
141 return $this->metadata;
142 }
143
144 return isset($this->metadata[$key]) ? $this->metadata[$key] : null;
145 }
146
147 private function pump($length)
148 {
149 if ($this->source) {
150 do {
151 $data = call_user_func($this->source, $length);
152 if ($data === false || $data === null) {
153 $this->source = null;
154 return;
155 }
156 $this->buffer->write($data);
157 $length -= strlen($data);
158 } while ($length > 0);
159 }
160 }
161 }
162