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 |
PostBody.php
001 <?php
002 namespace GuzzleHttp\Post;
003
004 use GuzzleHttp\Message\RequestInterface;
005 use GuzzleHttp\Stream\Exception\CannotAttachException;
006 use GuzzleHttp\Stream\StreamInterface;
007 use GuzzleHttp\Stream\Stream;
008 use GuzzleHttp\Query;
009
010 /**
011 * Holds POST fields and files and creates a streaming body when read methods
012 * are called on the object.
013 */
014 class PostBody implements PostBodyInterface
015 {
016 /** @var StreamInterface */
017 private $body;
018
019 /** @var callable */
020 private $aggregator;
021
022 private $fields = [];
023
024 /** @var PostFileInterface[] */
025 private $files = [];
026 private $forceMultipart = false;
027 private $detached = false;
028
029 /**
030 * Applies request headers to a request based on the POST state
031 *
032 * @param RequestInterface $request Request to update
033 */
034 public function applyRequestHeaders(RequestInterface $request)
035 {
036 if ($this->files || $this->forceMultipart) {
037 $request->setHeader(
038 'Content-Type',
039 'multipart/form-data; boundary=' . $this->getBody()->getBoundary()
040 );
041 } elseif ($this->fields && !$request->hasHeader('Content-Type')) {
042 $request->setHeader(
043 'Content-Type',
044 'application/x-www-form-urlencoded'
045 );
046 }
047
048 if ($size = $this->getSize()) {
049 $request->setHeader('Content-Length', $size);
050 }
051 }
052
053 public function forceMultipartUpload($force)
054 {
055 $this->forceMultipart = $force;
056 }
057
058 public function setAggregator(callable $aggregator)
059 {
060 $this->aggregator = $aggregator;
061 }
062
063 public function setField($name, $value)
064 {
065 $this->fields[$name] = $value;
066 $this->mutate();
067 }
068
069 public function replaceFields(array $fields)
070 {
071 $this->fields = $fields;
072 $this->mutate();
073 }
074
075 public function getField($name)
076 {
077 return isset($this->fields[$name]) ? $this->fields[$name] : null;
078 }
079
080 public function removeField($name)
081 {
082 unset($this->fields[$name]);
083 $this->mutate();
084 }
085
086 public function getFields($asString = false)
087 {
088 if (!$asString) {
089 return $this->fields;
090 }
091
092 $query = new Query($this->fields);
093 $query->setEncodingType(Query::RFC1738);
094 $query->setAggregator($this->getAggregator());
095
096 return (string) $query;
097 }
098
099 public function hasField($name)
100 {
101 return isset($this->fields[$name]);
102 }
103
104 public function getFile($name)
105 {
106 foreach ($this->files as $file) {
107 if ($file->getName() == $name) {
108 return $file;
109 }
110 }
111
112 return null;
113 }
114
115 public function getFiles()
116 {
117 return $this->files;
118 }
119
120 public function addFile(PostFileInterface $file)
121 {
122 $this->files[] = $file;
123 $this->mutate();
124 }
125
126 public function clearFiles()
127 {
128 $this->files = [];
129 $this->mutate();
130 }
131
132 /**
133 * Returns the numbers of fields + files
134 *
135 * @return int
136 */
137 public function count()
138 {
139 return count($this->files) + count($this->fields);
140 }
141
142 public function __toString()
143 {
144 return (string) $this->getBody();
145 }
146
147 public function getContents($maxLength = -1)
148 {
149 return $this->getBody()->getContents();
150 }
151
152 public function close()
153 {
154 $this->detach();
155 }
156
157 public function detach()
158 {
159 $this->detached = true;
160 $this->fields = $this->files = [];
161
162 if ($this->body) {
163 $this->body->close();
164 $this->body = null;
165 }
166 }
167
168 public function attach($stream)
169 {
170 throw new CannotAttachException();
171 }
172
173 public function eof()
174 {
175 return $this->getBody()->eof();
176 }
177
178 public function tell()
179 {
180 return $this->body ? $this->body->tell() : 0;
181 }
182
183 public function isSeekable()
184 {
185 return true;
186 }
187
188 public function isReadable()
189 {
190 return true;
191 }
192
193 public function isWritable()
194 {
195 return false;
196 }
197
198 public function getSize()
199 {
200 return $this->getBody()->getSize();
201 }
202
203 public function seek($offset, $whence = SEEK_SET)
204 {
205 return $this->getBody()->seek($offset, $whence);
206 }
207
208 public function read($length)
209 {
210 return $this->getBody()->read($length);
211 }
212
213 public function write($string)
214 {
215 return false;
216 }
217
218 public function getMetadata($key = null)
219 {
220 return $key ? null : [];
221 }
222
223 /**
224 * Return a stream object that is built from the POST fields and files.
225 *
226 * If one has already been created, the previously created stream will be
227 * returned.
228 */
229 private function getBody()
230 {
231 if ($this->body) {
232 return $this->body;
233 } elseif ($this->files || $this->forceMultipart) {
234 return $this->body = $this->createMultipart();
235 } elseif ($this->fields) {
236 return $this->body = $this->createUrlEncoded();
237 } else {
238 return $this->body = Stream::factory();
239 }
240 }
241
242 /**
243 * Get the aggregator used to join multi-valued field parameters
244 *
245 * @return callable
246 */
247 final protected function getAggregator()
248 {
249 if (!$this->aggregator) {
250 $this->aggregator = Query::phpAggregator();
251 }
252
253 return $this->aggregator;
254 }
255
256 /**
257 * Creates a multipart/form-data body stream
258 *
259 * @return MultipartBody
260 */
261 private function createMultipart()
262 {
263 // Flatten the nested query string values using the correct aggregator
264 return new MultipartBody(
265 call_user_func($this->getAggregator(), $this->fields),
266 $this->files
267 );
268 }
269
270 /**
271 * Creates an application/x-www-form-urlencoded stream body
272 *
273 * @return StreamInterface
274 */
275 private function createUrlEncoded()
276 {
277 return Stream::factory($this->getFields(true));
278 }
279
280 /**
281 * Get rid of any cached data
282 */
283 private function mutate()
284 {
285 $this->body = null;
286 }
287 }
288