run:R W Run
607 By
2026-03-11 16:18:52
R W Run
333 By
2026-03-11 16:18:52
R W Run
2.21 KB
2026-03-11 16:18:52
R W Run
14.85 KB
2026-03-11 16:18:52
R W Run
4.34 KB
2026-03-11 16:18:52
R W Run
2.13 KB
2026-03-11 16:18:52
R W Run
2.02 KB
2026-03-11 16:18:52
R W Run
6.78 KB
2026-03-11 16:18:52
R W Run
error_log
📄FileClient.php
1<?php
2
3// SPDX-FileCopyrightText: 2004-2023 Ryan Parman, Sam Sneddon, Ryan McCue
4// SPDX-License-Identifier: BSD-3-Clause
5
6declare(strict_types=1);
7
8namespace SimplePie\HTTP;
9
10use InvalidArgumentException;
11use SimplePie\File;
12use SimplePie\Misc;
13use SimplePie\Registry;
14use Throwable;
15
16/**
17 * HTTP Client based on \SimplePie\File
18 *
19 * @internal
20 */
21final class FileClient implements Client
22{
23 /** @var Registry */
24 private $registry;
25
26 /** @var array{timeout?: int, redirects?: int, useragent?: string, force_fsockopen?: bool, curl_options?: array<mixed>} */
27 private $options;
28
29 /**
30 * @param array{timeout?: int, redirects?: int, useragent?: string, force_fsockopen?: bool, curl_options?: array<mixed>} $options
31 */
32 public function __construct(Registry $registry, array $options = [])
33 {
34 $this->registry = $registry;
35 $this->options = $options;
36 }
37
38 /**
39 * send a request and return the response
40 *
41 * @param Client::METHOD_* $method
42 * @param array<string, string> $headers
43 *
44 * @throws ClientException if anything goes wrong requesting the data
45 */
46 public function request(string $method, string $url, array $headers = []): Response
47 {
48 // @phpstan-ignore-next-line Enforce PHPDoc type.
49 if ($method !== self::METHOD_GET) {
50 throw new InvalidArgumentException(sprintf(
51 '%s(): Argument #1 ($method) only supports method "%s".',
52 __METHOD__,
53 self::METHOD_GET
54 ), 1);
55 }
56
57 try {
58 $file = $this->registry->create(File::class, [
59 $url,
60 $this->options['timeout'] ?? 10,
61 $this->options['redirects'] ?? 5,
62 $headers,
63 $this->options['useragent'] ?? Misc::get_default_useragent(),
64 $this->options['force_fsockopen'] ?? false,
65 $this->options['curl_options'] ?? []
66 ]);
67 } catch (Throwable $th) {
68 throw new ClientException($th->getMessage(), $th->getCode(), $th);
69 }
70
71 if ($file->error !== null && $file->get_status_code() === 0) {
72 throw new ClientException($file->error);
73 }
74
75 return $file;
76 }
77}
78