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