Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 12... Línea 12...
12
final class Utils
12
final class Utils
13
{
13
{
14
    /**
14
    /**
15
     * Remove the items given by the keys, case insensitively from the data.
15
     * Remove the items given by the keys, case insensitively from the data.
16
     *
16
     *
17
     * @param string[] $keys
17
     * @param (string|int)[] $keys
18
     */
18
     */
19
    public static function caselessRemove(array $keys, array $data): array
19
    public static function caselessRemove(array $keys, array $data): array
20
    {
20
    {
21
        $result = [];
21
        $result = [];
Línea 22... Línea 22...
22
 
22
 
23
        foreach ($keys as &$key) {
23
        foreach ($keys as &$key) {
24
            $key = strtolower($key);
24
            $key = strtolower((string) $key);
Línea 25... Línea 25...
25
        }
25
        }
26
 
26
 
27
        foreach ($data as $k => $v) {
27
        foreach ($data as $k => $v) {
28
            if (!is_string($k) || !in_array(strtolower($k), $keys)) {
28
            if (!in_array(strtolower((string) $k), $keys)) {
29
                $result[$k] = $v;
29
                $result[$k] = $v;
Línea 30... Línea 30...
30
            }
30
            }
Línea 88... Línea 88...
88
                if ($buf === '') {
88
                if ($buf === '') {
89
                    break;
89
                    break;
90
                }
90
                }
91
                $buffer .= $buf;
91
                $buffer .= $buf;
92
            }
92
            }
-
 
93
 
93
            return $buffer;
94
            return $buffer;
94
        }
95
        }
Línea 95... Línea 96...
95
 
96
 
96
        $len = 0;
97
        $len = 0;
Línea 172... Línea 173...
172
 
173
 
173
                if ($port = $changes['uri']->getPort()) {
174
                if ($port = $changes['uri']->getPort()) {
174
                    $standardPorts = ['http' => 80, 'https' => 443];
175
                    $standardPorts = ['http' => 80, 'https' => 443];
175
                    $scheme = $changes['uri']->getScheme();
176
                    $scheme = $changes['uri']->getScheme();
176
                    if (isset($standardPorts[$scheme]) && $port != $standardPorts[$scheme]) {
177
                    if (isset($standardPorts[$scheme]) && $port != $standardPorts[$scheme]) {
177
                        $changes['set_headers']['Host'] .= ':' . $port;
178
                        $changes['set_headers']['Host'] .= ':'.$port;
178
                    }
179
                    }
179
                }
180
                }
180
            }
181
            }
181
            $uri = $changes['uri'];
182
            $uri = $changes['uri'];
Línea 248... Línea 249...
248
 
249
 
249
        return $buffer;
250
        return $buffer;
Línea 250... Línea 251...
250
    }
251
    }
-
 
252
 
-
 
253
    /**
-
 
254
     * Redact the password in the user info part of a URI.
-
 
255
     */
-
 
256
    public static function redactUserInfo(UriInterface $uri): UriInterface
-
 
257
    {
-
 
258
        $userInfo = $uri->getUserInfo();
-
 
259
 
-
 
260
        if (false !== ($pos = \strpos($userInfo, ':'))) {
-
 
261
            return $uri->withUserInfo(\substr($userInfo, 0, $pos), '***');
-
 
262
        }
-
 
263
 
-
 
264
        return $uri;
-
 
265
    }
251
 
266
 
252
    /**
267
    /**
253
     * Create a new stream based on the input type.
268
     * Create a new stream based on the input type.
254
     *
269
     *
255
     * Options is an associative array that can contain the following keys:
270
     * Options is an associative array that can contain the following keys:
Línea 289... Línea 304...
289
            $stream = self::tryFopen('php://temp', 'r+');
304
            $stream = self::tryFopen('php://temp', 'r+');
290
            if ($resource !== '') {
305
            if ($resource !== '') {
291
                fwrite($stream, (string) $resource);
306
                fwrite($stream, (string) $resource);
292
                fseek($stream, 0);
307
                fseek($stream, 0);
293
            }
308
            }
-
 
309
 
294
            return new Stream($stream, $options);
310
            return new Stream($stream, $options);
295
        }
311
        }
Línea 296... Línea 312...
296
 
312
 
297
        switch (gettype($resource)) {
313
        switch (gettype($resource)) {
Línea 306... Línea 322...
306
                    $stream = self::tryFopen('php://temp', 'w+');
322
                    $stream = self::tryFopen('php://temp', 'w+');
307
                    stream_copy_to_stream($resource, $stream);
323
                    stream_copy_to_stream($resource, $stream);
308
                    fseek($stream, 0);
324
                    fseek($stream, 0);
309
                    $resource = $stream;
325
                    $resource = $stream;
310
                }
326
                }
-
 
327
 
311
                return new Stream($resource, $options);
328
                return new Stream($resource, $options);
312
            case 'object':
329
            case 'object':
313
                /** @var object $resource */
330
                /** @var object $resource */
314
                if ($resource instanceof StreamInterface) {
331
                if ($resource instanceof StreamInterface) {
315
                    return $resource;
332
                    return $resource;
Línea 318... Línea 335...
318
                        if (!$resource->valid()) {
335
                        if (!$resource->valid()) {
319
                            return false;
336
                            return false;
320
                        }
337
                        }
321
                        $result = $resource->current();
338
                        $result = $resource->current();
322
                        $resource->next();
339
                        $resource->next();
-
 
340
 
323
                        return $result;
341
                        return $result;
324
                    }, $options);
342
                    }, $options);
325
                } elseif (method_exists($resource, '__toString')) {
343
                } elseif (method_exists($resource, '__toString')) {
326
                    return self::streamFor((string) $resource, $options);
344
                    return self::streamFor((string) $resource, $options);
327
                }
345
                }
Línea 332... Línea 350...
332
 
350
 
333
        if (is_callable($resource)) {
351
        if (is_callable($resource)) {
334
            return new PumpStream($resource, $options);
352
            return new PumpStream($resource, $options);
Línea 335... Línea 353...
335
        }
353
        }
336
 
354
 
Línea 337... Línea 355...
337
        throw new \InvalidArgumentException('Invalid resource type: ' . gettype($resource));
355
        throw new \InvalidArgumentException('Invalid resource type: '.gettype($resource));
338
    }
356
    }
339
 
357