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 |
Response.php
001 <?php
002 namespace GuzzleHttp\Message;
003
004 use GuzzleHttp\Exception\ParseException;
005 use GuzzleHttp\Exception\XmlParseException;
006 use GuzzleHttp\Stream\StreamInterface;
007 use GuzzleHttp\Utils;
008
009 /**
010 * Guzzle HTTP response object
011 */
012 class Response extends AbstractMessage implements ResponseInterface
013 {
014 /** @var array Mapping of status codes to reason phrases */
015 private static $statusTexts = [
016 100 => 'Continue',
017 101 => 'Switching Protocols',
018 102 => 'Processing',
019 200 => 'OK',
020 201 => 'Created',
021 202 => 'Accepted',
022 203 => 'Non-Authoritative Information',
023 204 => 'No Content',
024 205 => 'Reset Content',
025 206 => 'Partial Content',
026 207 => 'Multi-Status',
027 208 => 'Already Reported',
028 226 => 'IM Used',
029 300 => 'Multiple Choices',
030 301 => 'Moved Permanently',
031 302 => 'Found',
032 303 => 'See Other',
033 304 => 'Not Modified',
034 305 => 'Use Proxy',
035 307 => 'Temporary Redirect',
036 308 => 'Permanent Redirect',
037 400 => 'Bad Request',
038 401 => 'Unauthorized',
039 402 => 'Payment Required',
040 403 => 'Forbidden',
041 404 => 'Not Found',
042 405 => 'Method Not Allowed',
043 406 => 'Not Acceptable',
044 407 => 'Proxy Authentication Required',
045 408 => 'Request Timeout',
046 409 => 'Conflict',
047 410 => 'Gone',
048 411 => 'Length Required',
049 412 => 'Precondition Failed',
050 413 => 'Request Entity Too Large',
051 414 => 'Request-URI Too Long',
052 415 => 'Unsupported Media Type',
053 416 => 'Requested Range Not Satisfiable',
054 417 => 'Expectation Failed',
055 422 => 'Unprocessable Entity',
056 423 => 'Locked',
057 424 => 'Failed Dependency',
058 425 => 'Reserved for WebDAV advanced collections expired proposal',
059 426 => 'Upgrade required',
060 428 => 'Precondition Required',
061 429 => 'Too Many Requests',
062 431 => 'Request Header Fields Too Large',
063 500 => 'Internal Server Error',
064 501 => 'Not Implemented',
065 502 => 'Bad Gateway',
066 503 => 'Service Unavailable',
067 504 => 'Gateway Timeout',
068 505 => 'HTTP Version Not Supported',
069 506 => 'Variant Also Negotiates (Experimental)',
070 507 => 'Insufficient Storage',
071 508 => 'Loop Detected',
072 510 => 'Not Extended',
073 511 => 'Network Authentication Required',
074 ];
075
076 /** @var string The reason phrase of the response (human readable code) */
077 private $reasonPhrase;
078
079 /** @var string The status code of the response */
080 private $statusCode;
081
082 /** @var string The effective URL that returned this response */
083 private $effectiveUrl;
084
085 /**
086 * @param int|string $statusCode The response status code (e.g. 200)
087 * @param array $headers The response headers
088 * @param StreamInterface $body The body of the response
089 * @param array $options Response message options
090 * - reason_phrase: Set a custom reason phrase
091 * - protocol_version: Set a custom protocol version
092 */
093 public function __construct(
094 $statusCode,
095 array $headers = [],
096 StreamInterface $body = null,
097 array $options = []
098 ) {
099 $this->statusCode = (int) $statusCode;
100 $this->handleOptions($options);
101
102 // Assume a reason phrase if one was not applied as an option
103 if (!$this->reasonPhrase &&
104 isset(self::$statusTexts[$this->statusCode])
105 ) {
106 $this->reasonPhrase = self::$statusTexts[$this->statusCode];
107 }
108
109 if ($headers) {
110 $this->setHeaders($headers);
111 }
112
113 if ($body) {
114 $this->setBody($body);
115 }
116 }
117
118 public function getStatusCode()
119 {
120 return $this->statusCode;
121 }
122
123 public function setStatusCode($code)
124 {
125 return $this->statusCode = (int) $code;
126 }
127
128 public function getReasonPhrase()
129 {
130 return $this->reasonPhrase;
131 }
132
133 public function setReasonPhrase($phrase)
134 {
135 return $this->reasonPhrase = $phrase;
136 }
137
138 public function json(array $config = [])
139 {
140 try {
141 return Utils::jsonDecode(
142 (string) $this->getBody(),
143 isset($config['object']) ? !$config['object'] : true,
144 512,
145 isset($config['big_int_strings']) ? JSON_BIGINT_AS_STRING : 0
146 );
147 } catch (\InvalidArgumentException $e) {
148 throw new ParseException(
149 $e->getMessage(),
150 $this
151 );
152 }
153 }
154
155 public function xml(array $config = [])
156 {
157 $disableEntities = libxml_disable_entity_loader(true);
158 $internalErrors = libxml_use_internal_errors(true);
159
160 try {
161 // Allow XML to be retrieved even if there is no response body
162 $xml = new \SimpleXMLElement(
163 (string) $this->getBody() ?: '<root />',
164 isset($config['libxml_options']) ? $config['libxml_options'] : LIBXML_NONET,
165 false,
166 isset($config['ns']) ? $config['ns'] : '',
167 isset($config['ns_is_prefix']) ? $config['ns_is_prefix'] : false
168 );
169 libxml_disable_entity_loader($disableEntities);
170 libxml_use_internal_errors($internalErrors);
171 } catch (\Exception $e) {
172 libxml_disable_entity_loader($disableEntities);
173 libxml_use_internal_errors($internalErrors);
174 throw new XmlParseException(
175 'Unable to parse response body into XML: ' . $e->getMessage(),
176 $this,
177 $e,
178 (libxml_get_last_error()) ?: null
179 );
180 }
181
182 return $xml;
183 }
184
185 public function getEffectiveUrl()
186 {
187 return $this->effectiveUrl;
188 }
189
190 public function setEffectiveUrl($url)
191 {
192 $this->effectiveUrl = $url;
193 }
194
195 /**
196 * Accepts and modifies the options provided to the response in the
197 * constructor.
198 *
199 * @param array $options Options array passed by reference.
200 */
201 protected function handleOptions(array &$options = [])
202 {
203 parent::handleOptions($options);
204 if (isset($options['reason_phrase'])) {
205 $this->reasonPhrase = $options['reason_phrase'];
206 }
207 }
208 }
209