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 |
functions.php
001 <?php
002 namespace GuzzleHttp;
003
004 use GuzzleHttp\Handler\CurlHandler;
005 use GuzzleHttp\Handler\CurlMultiHandler;
006 use GuzzleHttp\Handler\Proxy;
007 use GuzzleHttp\Handler\StreamHandler;
008
009 /**
010 * Expands a URI template
011 *
012 * @param string $template URI template
013 * @param array $variables Template variables
014 *
015 * @return string
016 */
017 function uri_template($template, array $variables)
018 {
019 if (extension_loaded('uri_template')) {
020 // @codeCoverageIgnoreStart
021 return \uri_template($template, $variables);
022 // @codeCoverageIgnoreEnd
023 }
024
025 static $uriTemplate;
026 if (!$uriTemplate) {
027 $uriTemplate = new UriTemplate();
028 }
029
030 return $uriTemplate->expand($template, $variables);
031 }
032
033 /**
034 * Debug function used to describe the provided value type and class.
035 *
036 * @param mixed $input
037 *
038 * @return string Returns a string containing the type of the variable and
039 * if a class is provided, the class name.
040 */
041 function describe_type($input)
042 {
043 switch (gettype($input)) {
044 case 'object':
045 return 'object(' . get_class($input) . ')';
046 case 'array':
047 return 'array(' . count($input) . ')';
048 default:
049 ob_start();
050 var_dump($input);
051 // normalize float vs double
052 return str_replace('double(', 'float(', rtrim(ob_get_clean()));
053 }
054 }
055
056 /**
057 * Parses an array of header lines into an associative array of headers.
058 *
059 * @param iterable $lines Header lines array of strings in the following
060 * format: "Name: Value"
061 * @return array
062 */
063 function headers_from_lines($lines)
064 {
065 $headers = [];
066
067 foreach ($lines as $line) {
068 $parts = explode(':', $line, 2);
069 $headers[trim($parts[0])][] = isset($parts[1])
070 ? trim($parts[1])
071 : null;
072 }
073
074 return $headers;
075 }
076
077 /**
078 * Returns a debug stream based on the provided variable.
079 *
080 * @param mixed $value Optional value
081 *
082 * @return resource
083 */
084 function debug_resource($value = null)
085 {
086 if (is_resource($value)) {
087 return $value;
088 } elseif (defined('STDOUT')) {
089 return STDOUT;
090 }
091
092 return fopen('php://output', 'w');
093 }
094
095 /**
096 * Chooses and creates a default handler to use based on the environment.
097 *
098 * The returned handler is not wrapped by any default middlewares.
099 *
100 * @return callable Returns the best handler for the given system.
101 * @throws \RuntimeException if no viable Handler is available.
102 */
103 function choose_handler()
104 {
105 $handler = null;
106 if (function_exists('curl_multi_exec') && function_exists('curl_exec')) {
107 $handler = Proxy::wrapSync(new CurlMultiHandler(), new CurlHandler());
108 } elseif (function_exists('curl_exec')) {
109 $handler = new CurlHandler();
110 } elseif (function_exists('curl_multi_exec')) {
111 $handler = new CurlMultiHandler();
112 }
113
114 if (ini_get('allow_url_fopen')) {
115 $handler = $handler
116 ? Proxy::wrapStreaming($handler, new StreamHandler())
117 : new StreamHandler();
118 } elseif (!$handler) {
119 throw new \RuntimeException('GuzzleHttp requires cURL, the '
120 . 'allow_url_fopen ini setting, or a custom HTTP handler.');
121 }
122
123 return $handler;
124 }
125
126 /**
127 * Get the default User-Agent string to use with Guzzle
128 *
129 * @return string
130 */
131 function default_user_agent()
132 {
133 static $defaultAgent = '';
134
135 if (!$defaultAgent) {
136 $defaultAgent = 'GuzzleHttp/' . Client::VERSION;
137 if (extension_loaded('curl') && function_exists('curl_version')) {
138 $defaultAgent .= ' curl/' . \curl_version()['version'];
139 }
140 $defaultAgent .= ' PHP/' . PHP_VERSION;
141 }
142
143 return $defaultAgent;
144 }
145
146 /**
147 * Returns the default cacert bundle for the current system.
148 *
149 * First, the openssl.cafile and curl.cainfo php.ini settings are checked.
150 * If those settings are not configured, then the common locations for
151 * bundles found on Red Hat, CentOS, Fedora, Ubuntu, Debian, FreeBSD, OS X
152 * and Windows are checked. If any of these file locations are found on
153 * disk, they will be utilized.
154 *
155 * Note: the result of this function is cached for subsequent calls.
156 *
157 * @return string
158 * @throws \RuntimeException if no bundle can be found.
159 */
160 function default_ca_bundle()
161 {
162 static $cached = null;
163 static $cafiles = [
164 // Red Hat, CentOS, Fedora (provided by the ca-certificates package)
165 '/etc/pki/tls/certs/ca-bundle.crt',
166 // Ubuntu, Debian (provided by the ca-certificates package)
167 '/etc/ssl/certs/ca-certificates.crt',
168 // FreeBSD (provided by the ca_root_nss package)
169 '/usr/local/share/certs/ca-root-nss.crt',
170 // SLES 12 (provided by the ca-certificates package)
171 '/var/lib/ca-certificates/ca-bundle.pem',
172 // OS X provided by homebrew (using the default path)
173 '/usr/local/etc/openssl/cert.pem',
174 // Google app engine
175 '/etc/ca-certificates.crt',
176 // Windows?
177 'C:\\windows\\system32\\curl-ca-bundle.crt',
178 'C:\\windows\\curl-ca-bundle.crt',
179 ];
180
181 if ($cached) {
182 return $cached;
183 }
184
185 if ($ca = ini_get('openssl.cafile')) {
186 return $cached = $ca;
187 }
188
189 if ($ca = ini_get('curl.cainfo')) {
190 return $cached = $ca;
191 }
192
193 foreach ($cafiles as $filename) {
194 if (file_exists($filename)) {
195 return $cached = $filename;
196 }
197 }
198
199 throw new \RuntimeException(
200 <<< EOT
201 No system CA bundle could be found in any of the the common system locations.
202 PHP versions earlier than 5.6 are not properly configured to use the system's
203 CA bundle by default. In order to verify peer certificates, you will need to
204 supply the path on disk to a certificate bundle to the 'verify' request
205 option: http://docs.guzzlephp.org/en/latest/clients.html#verify. If you do not
206 need a specific certificate bundle, then Mozilla provides a commonly used CA
207 bundle which can be downloaded here (provided by the maintainer of cURL):
208 https://raw.githubusercontent.com/bagder/ca-bundle/master/ca-bundle.crt. Once
209 you have a CA bundle available on disk, you can set the 'openssl.cafile' PHP
210 ini setting to point to the path to the file, allowing you to omit the 'verify'
211 request option. See http://curl.haxx.se/docs/sslcerts.html for more
212 information.
213 EOT
214 );
215 }
216
217 /**
218 * Creates an associative array of lowercase header names to the actual
219 * header casing.
220 *
221 * @param array $headers
222 *
223 * @return array
224 */
225 function normalize_header_keys(array $headers)
226 {
227 $result = [];
228 foreach (array_keys($headers) as $key) {
229 $result[strtolower($key)] = $key;
230 }
231
232 return $result;
233 }
234
235 /**
236 * Returns true if the provided host matches any of the no proxy areas.
237 *
238 * This method will strip a port from the host if it is present. Each pattern
239 * can be matched with an exact match (e.g., "foo.com" == "foo.com") or a
240 * partial match: (e.g., "foo.com" == "baz.foo.com" and ".foo.com" ==
241 * "baz.foo.com", but ".foo.com" != "foo.com").
242 *
243 * Areas are matched in the following cases:
244 * 1. "*" (without quotes) always matches any hosts.
245 * 2. An exact match.
246 * 3. The area starts with "." and the area is the last part of the host. e.g.
247 * '.mit.edu' will match any host that ends with '.mit.edu'.
248 *
249 * @param string $host Host to check against the patterns.
250 * @param array $noProxyArray An array of host patterns.
251 *
252 * @return bool
253 */
254 function is_host_in_noproxy($host, array $noProxyArray)
255 {
256 if (strlen($host) === 0) {
257 throw new \InvalidArgumentException('Empty host provided');
258 }
259
260 // Strip port if present.
261 if (strpos($host, ':')) {
262 $host = explode($host, ':', 2)[0];
263 }
264
265 foreach ($noProxyArray as $area) {
266 // Always match on wildcards.
267 if ($area === '*') {
268 return true;
269 } elseif (empty($area)) {
270 // Don't match on empty values.
271 continue;
272 } elseif ($area === $host) {
273 // Exact matches.
274 return true;
275 } else {
276 // Special match if the area when prefixed with ".". Remove any
277 // existing leading "." and add a new leading ".".
278 $area = '.' . ltrim($area, '.');
279 if (substr($host, -(strlen($area))) === $area) {
280 return true;
281 }
282 }
283 }
284
285 return false;
286 }
287
288 /**
289 * Wrapper for json_decode that throws when an error occurs.
290 *
291 * @param string $json JSON data to parse
292 * @param bool $assoc When true, returned objects will be converted
293 * into associative arrays.
294 * @param int $depth User specified recursion depth.
295 * @param int $options Bitmask of JSON decode options.
296 *
297 * @return mixed
298 * @throws Exception\InvalidArgumentException if the JSON cannot be decoded.
299 * @link http://www.php.net/manual/en/function.json-decode.php
300 */
301 function json_decode($json, $assoc = false, $depth = 512, $options = 0)
302 {
303 $data = \json_decode($json, $assoc, $depth, $options);
304 if (JSON_ERROR_NONE !== json_last_error()) {
305 throw new Exception\InvalidArgumentException(
306 'json_decode error: ' . json_last_error_msg()
307 );
308 }
309
310 return $data;
311 }
312
313 /**
314 * Wrapper for JSON encoding that throws when an error occurs.
315 *
316 * @param mixed $value The value being encoded
317 * @param int $options JSON encode option bitmask
318 * @param int $depth Set the maximum depth. Must be greater than zero.
319 *
320 * @return string
321 * @throws Exception\InvalidArgumentException if the JSON cannot be encoded.
322 * @link http://www.php.net/manual/en/function.json-encode.php
323 */
324 function json_encode($value, $options = 0, $depth = 512)
325 {
326 $json = \json_encode($value, $options, $depth);
327 if (JSON_ERROR_NONE !== json_last_error()) {
328 throw new Exception\InvalidArgumentException(
329 'json_encode error: ' . json_last_error_msg()
330 );
331 }
332
333 return $json;
334 }
335