Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
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 |
MessageFormatter.php
001 <?php
002 namespace GuzzleHttp;
003
004 use Psr\Http\Message\MessageInterface;
005 use Psr\Http\Message\RequestInterface;
006 use Psr\Http\Message\ResponseInterface;
007
008 /**
009 * Formats log messages using variable substitutions for requests, responses,
010 * and other transactional data.
011 *
012 * The following variable substitutions are supported:
013 *
014 * - {request}: Full HTTP request message
015 * - {response}: Full HTTP response message
016 * - {ts}: ISO 8601 date in GMT
017 * - {date_iso_8601} ISO 8601 date in GMT
018 * - {date_common_log} Apache common log date using the configured timezone.
019 * - {host}: Host of the request
020 * - {method}: Method of the request
021 * - {uri}: URI of the request
022 * - {version}: Protocol version
023 * - {target}: Request target of the request (path + query + fragment)
024 * - {hostname}: Hostname of the machine that sent the request
025 * - {code}: Status code of the response (if available)
026 * - {phrase}: Reason phrase of the response (if available)
027 * - {error}: Any error messages (if available)
028 * - {req_header_*}: Replace `*` with the lowercased name of a request header to add to the message
029 * - {res_header_*}: Replace `*` with the lowercased name of a response header to add to the message
030 * - {req_headers}: Request headers
031 * - {res_headers}: Response headers
032 * - {req_body}: Request body
033 * - {res_body}: Response body
034 */
035 class MessageFormatter
036 {
037 /**
038 * Apache Common Log Format.
039 * @link http://httpd.apache.org/docs/2.4/logs.html#common
040 * @var string
041 */
042 const CLF = "{hostname} {req_header_User-Agent} - [{date_common_log}] \"{method} {target} HTTP/{version}\" {code} {res_header_Content-Length}";
043 const DEBUG = ">>>>>>>>\n{request}\n<<<<<<<<\n{response}\n--------\n{error}";
044 const SHORT = '[{ts}] "{method} {target} HTTP/{version}" {code}';
045
046 /** @var string Template used to format log messages */
047 private $template;
048
049 /**
050 * @param string $template Log message template
051 */
052 public function __construct($template = self::CLF)
053 {
054 $this->template = $template ?: self::CLF;
055 }
056
057 /**
058 * Returns a formatted message string.
059 *
060 * @param RequestInterface $request Request that was sent
061 * @param ResponseInterface $response Response that was received
062 * @param \Exception $error Exception that was received
063 *
064 * @return string
065 */
066 public function format(
067 RequestInterface $request,
068 ResponseInterface $response = null,
069 \Exception $error = null
070 ) {
071 $cache = [];
072
073 return preg_replace_callback(
074 '/{\s*([A-Za-z_\-\.0-9]+)\s*}/',
075 function (array $matches) use ($request, $response, $error, &$cache) {
076 if (isset($cache[$matches[1]])) {
077 return $cache[$matches[1]];
078 }
079
080 $result = '';
081 switch ($matches[1]) {
082 case 'request':
083 $result = Psr7\str($request);
084 break;
085 case 'response':
086 $result = $response ? Psr7\str($response) : '';
087 break;
088 case 'req_headers':
089 $result = trim($request->getMethod()
090 . ' ' . $request->getRequestTarget())
091 . ' HTTP/' . $request->getProtocolVersion() . "\r\n"
092 . $this->headers($request);
093 break;
094 case 'res_headers':
095 $result = $response ?
096 sprintf(
097 'HTTP/%s %d %s',
098 $response->getProtocolVersion(),
099 $response->getStatusCode(),
100 $response->getReasonPhrase()
101 ) . "\r\n" . $this->headers($response)
102 : 'NULL';
103 break;
104 case 'req_body':
105 $result = $request->getBody();
106 break;
107 case 'res_body':
108 $result = $response ? $response->getBody() : 'NULL';
109 break;
110 case 'ts':
111 case 'date_iso_8601':
112 $result = gmdate('c');
113 break;
114 case 'date_common_log':
115 $result = date('d/M/Y:H:i:s O');
116 break;
117 case 'method':
118 $result = $request->getMethod();
119 break;
120 case 'version':
121 $result = $request->getProtocolVersion();
122 break;
123 case 'uri':
124 case 'url':
125 $result = $request->getUri();
126 break;
127 case 'target':
128 $result = $request->getRequestTarget();
129 break;
130 case 'req_version':
131 $result = $request->getProtocolVersion();
132 break;
133 case 'res_version':
134 $result = $response
135 ? $response->getProtocolVersion()
136 : 'NULL';
137 break;
138 case 'host':
139 $result = $request->getHeaderLine('Host');
140 break;
141 case 'hostname':
142 $result = gethostname();
143 break;
144 case 'code':
145 $result = $response ? $response->getStatusCode() : 'NULL';
146 break;
147 case 'phrase':
148 $result = $response ? $response->getReasonPhrase() : 'NULL';
149 break;
150 case 'error':
151 $result = $error ? $error->getMessage() : 'NULL';
152 break;
153 default:
154 // handle prefixed dynamic headers
155 if (strpos($matches[1], 'req_header_') === 0) {
156 $result = $request->getHeaderLine(substr($matches[1], 11));
157 } elseif (strpos($matches[1], 'res_header_') === 0) {
158 $result = $response
159 ? $response->getHeaderLine(substr($matches[1], 11))
160 : 'NULL';
161 }
162 }
163
164 $cache[$matches[1]] = $result;
165 return $result;
166 },
167 $this->template
168 );
169 }
170
171 /**
172 * Get headers from message as string
173 *
174 * @return string
175 */
176 private function headers(MessageInterface $message)
177 {
178 $result = '';
179 foreach ($message->getHeaders() as $name => $values) {
180 $result .= $name . ': ' . implode(', ', $values) . "\r\n";
181 }
182
183 return trim($result);
184 }
185 }
186