Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 1441
Línea 271... Línea 271...
271
 *
271
 *
272
 * @return callable
272
 * @return callable
273
 */
273
 */
274
function default_http_handler()
274
function default_http_handler()
275
{
275
{
276
    $version = guzzle_major_version();
-
 
277
    // If Guzzle 6 or 7 installed
-
 
278
    if ($version === 6 || $version === 7) {
-
 
279
        return new \Aws\Handler\GuzzleV6\GuzzleHandler();
276
    return new \Aws\Handler\GuzzleV6\GuzzleHandler();
280
    }
-
 
281
 
-
 
282
    // If Guzzle 5 installed
-
 
283
    if ($version === 5) {
-
 
284
        return new \Aws\Handler\GuzzleV5\GuzzleHandler();
-
 
285
    }
-
 
286
 
-
 
287
    throw new \RuntimeException('Unknown Guzzle version: ' . $version);
-
 
288
}
277
}
Línea 289... Línea 278...
289
 
278
 
290
/**
279
/**
291
 * Gets the default user agent string depending on the Guzzle version
280
 * Gets the default user agent string depending on the Guzzle version
292
 *
281
 *
293
 * @return string
282
 * @return string
294
 */
283
 */
295
function default_user_agent()
284
function default_user_agent()
296
{
-
 
297
    $version = guzzle_major_version();
-
 
298
    // If Guzzle 6 or 7 installed
-
 
299
    if ($version === 6 || $version === 7) {
285
{
300
        return \GuzzleHttp\default_user_agent();
-
 
301
    }
-
 
302
 
-
 
303
    // If Guzzle 5 installed
-
 
304
    if ($version === 5) {
-
 
305
        return \GuzzleHttp\Client::getDefaultUserAgent();
-
 
306
    }
-
 
307
 
-
 
308
    throw new \RuntimeException('Unknown Guzzle version: ' . $version);
-
 
309
}
-
 
310
 
-
 
311
/**
-
 
312
 * Get the major version of guzzle that is installed.
-
 
313
 *
-
 
314
 * @internal This function is internal and should not be used outside aws/aws-sdk-php.
-
 
315
 * @return int
-
 
316
 * @throws \RuntimeException
-
 
317
 */
-
 
318
function guzzle_major_version()
-
 
319
{
-
 
320
    static $cache = null;
-
 
321
    if (null !== $cache) {
-
 
322
        return $cache;
-
 
323
    }
-
 
324
 
-
 
325
    if (defined('\GuzzleHttp\ClientInterface::VERSION')) {
-
 
326
        $version = (string) ClientInterface::VERSION;
-
 
327
        if ($version[0] === '6') {
-
 
328
            return $cache = 6;
-
 
329
        }
-
 
330
        if ($version[0] === '5') {
-
 
331
            return $cache = 5;
-
 
332
        }
-
 
333
    } elseif (defined('\GuzzleHttp\ClientInterface::MAJOR_VERSION')) {
-
 
334
        return $cache = ClientInterface::MAJOR_VERSION;
-
 
335
    }
-
 
336
 
-
 
337
    throw new \RuntimeException('Unable to determine what Guzzle version is installed.');
286
    return \GuzzleHttp\default_user_agent();
Línea 338... Línea 287...
338
}
287
}
339
 
288
 
340
/**
289
/**
Línea 502... Línea 451...
502
    }
451
    }
503
    return null;
452
    return null;
504
}
453
}
Línea 505... Línea 454...
505
 
454
 
-
 
455
/**
-
 
456
 * Parses ini sections with subsections (i.e. the service section)
-
 
457
 *
-
 
458
 * @param $filename
-
 
459
 * @param $filename
-
 
460
 * @return array
-
 
461
 */
-
 
462
function parse_ini_section_with_subsections($filename, $section_name) {
-
 
463
    $config = [];
-
 
464
    $stream = fopen($filename, 'r');
-
 
465
 
-
 
466
    if (!$stream) {
-
 
467
        return $config;
-
 
468
    }
-
 
469
 
-
 
470
    $current_subsection = '';
-
 
471
 
-
 
472
    while (!feof($stream)) {
-
 
473
        $line = trim(fgets($stream));
-
 
474
 
-
 
475
        if (empty($line) || in_array($line[0], [';', '#'])) {
-
 
476
            continue;
-
 
477
        }
-
 
478
 
-
 
479
        if (preg_match('/^\[.*\]$/', $line)
-
 
480
            && trim($line, '[]') === $section_name)
-
 
481
        {
-
 
482
            while (!feof($stream)) {
-
 
483
                $line = trim(fgets($stream));
-
 
484
 
-
 
485
                if (empty($line) || in_array($line[0], [';', '#'])) {
-
 
486
                    continue;
-
 
487
                }
-
 
488
 
-
 
489
                if (preg_match('/^\[.*\]$/', $line)
-
 
490
                    && trim($line, '[]') === $section_name)
-
 
491
                {
-
 
492
                    continue;
-
 
493
                } elseif (strpos($line, '[') === 0) {
-
 
494
                    break;
-
 
495
                }
-
 
496
 
-
 
497
                if (strpos($line, ' = ') !== false) {
-
 
498
                    list($key, $value) = explode(' = ', $line, 2);
-
 
499
                    if (empty($current_subsection)) {
-
 
500
                        $config[$key] = $value;
-
 
501
                    } else {
-
 
502
                        $config[$current_subsection][$key] = $value;
-
 
503
                    }
-
 
504
                } else {
-
 
505
                    $current_subsection = trim(str_replace('=', '', $line));
-
 
506
                    $config[$current_subsection] = [];
-
 
507
                }
-
 
508
            }
-
 
509
        }
-
 
510
    }
-
 
511
 
-
 
512
    fclose($stream);
-
 
513
    return $config;
-
 
514
}
-
 
515
 
506
/**
516
/**
507
 * Checks if an input is a valid epoch time
517
 * Checks if an input is a valid epoch time
508
 *
518
 *
509
 * @param $input
519
 * @param $input
510
 * @return bool
520
 * @return bool
Línea 540... Línea 550...
540
function strip_fips_pseudo_regions($region)
550
function strip_fips_pseudo_regions($region)
541
{
551
{
542
    return str_replace(['fips-', '-fips'], ['', ''], $region);
552
    return str_replace(['fips-', '-fips'], ['', ''], $region);
543
}
553
}
Línea -... Línea 554...
-
 
554
 
-
 
555
/**
-
 
556
 * Checks if an array is associative
-
 
557
 *
-
 
558
 * @param array $array
-
 
559
 *
-
 
560
 * @return bool
-
 
561
 */
-
 
562
function is_associative(array $array): bool
-
 
563
{
-
 
564
    if (empty($array)) {
-
 
565
        return false;
-
 
566
    }
-
 
567
 
-
 
568
    if (function_exists('array_is_list')) {
-
 
569
        return !array_is_list($array);
-
 
570
    }
-
 
571
 
-
 
572
    return array_keys($array) !== range(0, count($array) - 1);
-
 
573
}