Edit File by line
/home/zeestwma/redstone.../wp-inclu.../SimplePi.../src
File: File.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;
[7] Fix | Delete
[8] Fix | Delete
use SimplePie\HTTP\Response;
[9] Fix | Delete
[10] Fix | Delete
/**
[11] Fix | Delete
* Used for fetching remote files and reading local files
[12] Fix | Delete
*
[13] Fix | Delete
* Supports HTTP 1.0 via cURL or fsockopen, with spotty HTTP 1.1 support
[14] Fix | Delete
*
[15] Fix | Delete
* This class can be overloaded with {@see \SimplePie\SimplePie::set_file_class()}
[16] Fix | Delete
*
[17] Fix | Delete
* @todo Move to properly supporting RFC2616 (HTTP/1.1)
[18] Fix | Delete
*/
[19] Fix | Delete
class File implements Response
[20] Fix | Delete
{
[21] Fix | Delete
/**
[22] Fix | Delete
* @var string The final URL after following all redirects
[23] Fix | Delete
* @deprecated Use `get_final_requested_uri()` method.
[24] Fix | Delete
*/
[25] Fix | Delete
public $url;
[26] Fix | Delete
[27] Fix | Delete
/**
[28] Fix | Delete
* @var ?string User agent to use in requests
[29] Fix | Delete
* @deprecated Set the user agent in constructor.
[30] Fix | Delete
*/
[31] Fix | Delete
public $useragent;
[32] Fix | Delete
[33] Fix | Delete
/** @var bool */
[34] Fix | Delete
public $success = true;
[35] Fix | Delete
[36] Fix | Delete
/** @var array<string, non-empty-array<string>> Canonical representation of headers */
[37] Fix | Delete
private $parsed_headers = [];
[38] Fix | Delete
/** @var array<string, string> Last known value of $headers property (used to detect external modification) */
[39] Fix | Delete
private $last_headers = [];
[40] Fix | Delete
/**
[41] Fix | Delete
* @var array<string, string> Headers as string for BC
[42] Fix | Delete
* @deprecated Use `get_headers()` method.
[43] Fix | Delete
*/
[44] Fix | Delete
public $headers = [];
[45] Fix | Delete
[46] Fix | Delete
/**
[47] Fix | Delete
* @var ?string Body of the HTTP response
[48] Fix | Delete
* @deprecated Use `get_body_content()` method.
[49] Fix | Delete
*/
[50] Fix | Delete
public $body;
[51] Fix | Delete
[52] Fix | Delete
/**
[53] Fix | Delete
* @var int Status code of the HTTP response
[54] Fix | Delete
* @deprecated Use `get_status_code()` method.
[55] Fix | Delete
*/
[56] Fix | Delete
public $status_code = 0;
[57] Fix | Delete
[58] Fix | Delete
/** @var non-negative-int Number of redirect that were already performed during this request sequence. */
[59] Fix | Delete
public $redirects = 0;
[60] Fix | Delete
[61] Fix | Delete
/** @var ?string */
[62] Fix | Delete
public $error;
[63] Fix | Delete
[64] Fix | Delete
/**
[65] Fix | Delete
* @var int-mask-of<SimplePie::FILE_SOURCE_*> Bit mask representing the method used to fetch the file and whether it is a local file or remote file obtained over HTTP.
[66] Fix | Delete
* @deprecated Backend is implementation detail which you should not care about; to see if the file was retrieved over HTTP, check if `get_final_requested_uri()` with `Misc::is_remote_uri()`.
[67] Fix | Delete
*/
[68] Fix | Delete
public $method = \SimplePie\SimplePie::FILE_SOURCE_NONE;
[69] Fix | Delete
[70] Fix | Delete
/**
[71] Fix | Delete
* @var string The permanent URL or the resource (first URL after the prefix of (only) permanent redirects)
[72] Fix | Delete
* @deprecated Use `get_permanent_uri()` method.
[73] Fix | Delete
*/
[74] Fix | Delete
public $permanent_url;
[75] Fix | Delete
/** @var bool Whether the permanent URL is still writeable (prefix of permanent redirects has not ended) */
[76] Fix | Delete
private $permanentUrlMutable = true;
[77] Fix | Delete
[78] Fix | Delete
/**
[79] Fix | Delete
* @param string $url
[80] Fix | Delete
* @param int $timeout
[81] Fix | Delete
* @param int $redirects
[82] Fix | Delete
* @param ?array<string, string> $headers
[83] Fix | Delete
* @param ?string $useragent
[84] Fix | Delete
* @param bool $force_fsockopen
[85] Fix | Delete
* @param array<int, mixed> $curl_options
[86] Fix | Delete
*/
[87] Fix | Delete
public function __construct(string $url, int $timeout = 10, int $redirects = 5, ?array $headers = null, ?string $useragent = null, bool $force_fsockopen = false, array $curl_options = [])
[88] Fix | Delete
{
[89] Fix | Delete
if (function_exists('idn_to_ascii')) {
[90] Fix | Delete
$parsed = \SimplePie\Misc::parse_url($url);
[91] Fix | Delete
if ($parsed['authority'] !== '' && !ctype_print($parsed['authority'])) {
[92] Fix | Delete
$authority = (string) \idn_to_ascii($parsed['authority'], \IDNA_NONTRANSITIONAL_TO_ASCII, \INTL_IDNA_VARIANT_UTS46);
[93] Fix | Delete
$url = \SimplePie\Misc::compress_parse_url($parsed['scheme'], $authority, $parsed['path'], $parsed['query'], null);
[94] Fix | Delete
}
[95] Fix | Delete
}
[96] Fix | Delete
$this->url = $url;
[97] Fix | Delete
if ($this->permanentUrlMutable) {
[98] Fix | Delete
$this->permanent_url = $url;
[99] Fix | Delete
}
[100] Fix | Delete
$this->useragent = $useragent;
[101] Fix | Delete
if (preg_match('/^http(s)?:\/\//i', $url)) {
[102] Fix | Delete
if ($useragent === null) {
[103] Fix | Delete
$useragent = (string) ini_get('user_agent');
[104] Fix | Delete
$this->useragent = $useragent;
[105] Fix | Delete
}
[106] Fix | Delete
if (!is_array($headers)) {
[107] Fix | Delete
$headers = [];
[108] Fix | Delete
}
[109] Fix | Delete
if (!$force_fsockopen && function_exists('curl_exec')) {
[110] Fix | Delete
$this->method = \SimplePie\SimplePie::FILE_SOURCE_REMOTE | \SimplePie\SimplePie::FILE_SOURCE_CURL;
[111] Fix | Delete
$fp = curl_init();
[112] Fix | Delete
$headers2 = [];
[113] Fix | Delete
foreach ($headers as $key => $value) {
[114] Fix | Delete
$headers2[] = "$key: $value";
[115] Fix | Delete
}
[116] Fix | Delete
if (isset($curl_options[CURLOPT_HTTPHEADER])) {
[117] Fix | Delete
if (is_array($curl_options[CURLOPT_HTTPHEADER])) {
[118] Fix | Delete
$headers2 = array_merge($headers2, $curl_options[CURLOPT_HTTPHEADER]);
[119] Fix | Delete
}
[120] Fix | Delete
unset($curl_options[CURLOPT_HTTPHEADER]);
[121] Fix | Delete
}
[122] Fix | Delete
if (version_compare(\SimplePie\Misc::get_curl_version(), '7.10.5', '>=')) {
[123] Fix | Delete
curl_setopt($fp, CURLOPT_ENCODING, '');
[124] Fix | Delete
}
[125] Fix | Delete
curl_setopt($fp, CURLOPT_URL, $url);
[126] Fix | Delete
curl_setopt($fp, CURLOPT_HEADER, 1);
[127] Fix | Delete
curl_setopt($fp, CURLOPT_RETURNTRANSFER, 1);
[128] Fix | Delete
curl_setopt($fp, CURLOPT_FAILONERROR, 1);
[129] Fix | Delete
curl_setopt($fp, CURLOPT_TIMEOUT, $timeout);
[130] Fix | Delete
curl_setopt($fp, CURLOPT_CONNECTTIMEOUT, $timeout);
[131] Fix | Delete
curl_setopt($fp, CURLOPT_REFERER, \SimplePie\Misc::url_remove_credentials($url));
[132] Fix | Delete
curl_setopt($fp, CURLOPT_USERAGENT, $useragent);
[133] Fix | Delete
curl_setopt($fp, CURLOPT_HTTPHEADER, $headers2);
[134] Fix | Delete
foreach ($curl_options as $curl_param => $curl_value) {
[135] Fix | Delete
curl_setopt($fp, $curl_param, $curl_value);
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
$responseHeaders = curl_exec($fp);
[139] Fix | Delete
if (curl_errno($fp) === CURLE_WRITE_ERROR || curl_errno($fp) === CURLE_BAD_CONTENT_ENCODING) {
[140] Fix | Delete
curl_setopt($fp, CURLOPT_ENCODING, 'none');
[141] Fix | Delete
$responseHeaders = curl_exec($fp);
[142] Fix | Delete
}
[143] Fix | Delete
$this->status_code = curl_getinfo($fp, CURLINFO_HTTP_CODE);
[144] Fix | Delete
if (curl_errno($fp)) {
[145] Fix | Delete
$this->error = 'cURL error ' . curl_errno($fp) . ': ' . curl_error($fp);
[146] Fix | Delete
$this->success = false;
[147] Fix | Delete
} else {
[148] Fix | Delete
// Use the updated url provided by curl_getinfo after any redirects.
[149] Fix | Delete
if ($info = curl_getinfo($fp)) {
[150] Fix | Delete
$this->url = $info['url'];
[151] Fix | Delete
}
[152] Fix | Delete
// For PHPStan: We already checked that error did not occur.
[153] Fix | Delete
assert(is_array($info) && $info['redirect_count'] >= 0);
[154] Fix | Delete
if (\PHP_VERSION_ID < 80000) {
[155] Fix | Delete
curl_close($fp);
[156] Fix | Delete
}
[157] Fix | Delete
$responseHeaders = \SimplePie\HTTP\Parser::prepareHeaders((string) $responseHeaders, $info['redirect_count'] + 1);
[158] Fix | Delete
$parser = new \SimplePie\HTTP\Parser($responseHeaders, true);
[159] Fix | Delete
if ($parser->parse()) {
[160] Fix | Delete
$this->set_headers($parser->headers);
[161] Fix | Delete
$this->body = $parser->body;
[162] Fix | Delete
$this->status_code = $parser->status_code;
[163] Fix | Delete
if ((in_array($this->status_code, [300, 301, 302, 303, 307]) || $this->status_code > 307 && $this->status_code < 400) && ($locationHeader = $this->get_header_line('location')) !== '' && $this->redirects < $redirects) {
[164] Fix | Delete
$this->redirects++;
[165] Fix | Delete
$location = \SimplePie\Misc::absolutize_url($locationHeader, $url);
[166] Fix | Delete
if ($location === false) {
[167] Fix | Delete
$this->error = "Invalid redirect location, trying to base “{$locationHeader}” onto “{$url}”";
[168] Fix | Delete
$this->success = false;
[169] Fix | Delete
return;
[170] Fix | Delete
}
[171] Fix | Delete
$this->permanentUrlMutable = $this->permanentUrlMutable && ($this->status_code == 301 || $this->status_code == 308);
[172] Fix | Delete
$this->__construct($location, $timeout, $redirects, $headers, $useragent, $force_fsockopen, $curl_options);
[173] Fix | Delete
return;
[174] Fix | Delete
}
[175] Fix | Delete
}
[176] Fix | Delete
}
[177] Fix | Delete
} else {
[178] Fix | Delete
$this->method = \SimplePie\SimplePie::FILE_SOURCE_REMOTE | \SimplePie\SimplePie::FILE_SOURCE_FSOCKOPEN;
[179] Fix | Delete
if (($url_parts = parse_url($url)) === false) {
[180] Fix | Delete
throw new \InvalidArgumentException('Malformed URL: ' . $url);
[181] Fix | Delete
}
[182] Fix | Delete
if (!isset($url_parts['host'])) {
[183] Fix | Delete
throw new \InvalidArgumentException('Missing hostname: ' . $url);
[184] Fix | Delete
}
[185] Fix | Delete
$socket_host = $url_parts['host'];
[186] Fix | Delete
if (isset($url_parts['scheme']) && strtolower($url_parts['scheme']) === 'https') {
[187] Fix | Delete
$socket_host = 'ssl://' . $socket_host;
[188] Fix | Delete
$url_parts['port'] = 443;
[189] Fix | Delete
}
[190] Fix | Delete
if (!isset($url_parts['port'])) {
[191] Fix | Delete
$url_parts['port'] = 80;
[192] Fix | Delete
}
[193] Fix | Delete
$fp = @fsockopen($socket_host, $url_parts['port'], $errno, $errstr, $timeout);
[194] Fix | Delete
if (!$fp) {
[195] Fix | Delete
$this->error = 'fsockopen error: ' . $errstr;
[196] Fix | Delete
$this->success = false;
[197] Fix | Delete
} else {
[198] Fix | Delete
stream_set_timeout($fp, $timeout);
[199] Fix | Delete
if (isset($url_parts['path'])) {
[200] Fix | Delete
if (isset($url_parts['query'])) {
[201] Fix | Delete
$get = "$url_parts[path]?$url_parts[query]";
[202] Fix | Delete
} else {
[203] Fix | Delete
$get = $url_parts['path'];
[204] Fix | Delete
}
[205] Fix | Delete
} else {
[206] Fix | Delete
$get = '/';
[207] Fix | Delete
}
[208] Fix | Delete
$out = "GET $get HTTP/1.1\r\n";
[209] Fix | Delete
$out .= "Host: $url_parts[host]\r\n";
[210] Fix | Delete
$out .= "User-Agent: $useragent\r\n";
[211] Fix | Delete
if (extension_loaded('zlib')) {
[212] Fix | Delete
$out .= "Accept-Encoding: x-gzip,gzip,deflate\r\n";
[213] Fix | Delete
}
[214] Fix | Delete
[215] Fix | Delete
if (isset($url_parts['user']) && isset($url_parts['pass'])) {
[216] Fix | Delete
$out .= "Authorization: Basic " . base64_encode("$url_parts[user]:$url_parts[pass]") . "\r\n";
[217] Fix | Delete
}
[218] Fix | Delete
foreach ($headers as $key => $value) {
[219] Fix | Delete
$out .= "$key: $value\r\n";
[220] Fix | Delete
}
[221] Fix | Delete
$out .= "Connection: Close\r\n\r\n";
[222] Fix | Delete
fwrite($fp, $out);
[223] Fix | Delete
[224] Fix | Delete
$info = stream_get_meta_data($fp);
[225] Fix | Delete
[226] Fix | Delete
$responseHeaders = '';
[227] Fix | Delete
while (!$info['eof'] && !$info['timed_out']) {
[228] Fix | Delete
$responseHeaders .= fread($fp, 1160);
[229] Fix | Delete
$info = stream_get_meta_data($fp);
[230] Fix | Delete
}
[231] Fix | Delete
if (!$info['timed_out']) {
[232] Fix | Delete
$parser = new \SimplePie\HTTP\Parser($responseHeaders, true);
[233] Fix | Delete
if ($parser->parse()) {
[234] Fix | Delete
$this->set_headers($parser->headers);
[235] Fix | Delete
$this->body = $parser->body;
[236] Fix | Delete
$this->status_code = $parser->status_code;
[237] Fix | Delete
if ((in_array($this->status_code, [300, 301, 302, 303, 307]) || $this->status_code > 307 && $this->status_code < 400) && ($locationHeader = $this->get_header_line('location')) !== '' && $this->redirects < $redirects) {
[238] Fix | Delete
$this->redirects++;
[239] Fix | Delete
$location = \SimplePie\Misc::absolutize_url($locationHeader, $url);
[240] Fix | Delete
$this->permanentUrlMutable = $this->permanentUrlMutable && ($this->status_code == 301 || $this->status_code == 308);
[241] Fix | Delete
if ($location === false) {
[242] Fix | Delete
$this->error = "Invalid redirect location, trying to base “{$locationHeader}” onto “{$url}”";
[243] Fix | Delete
$this->success = false;
[244] Fix | Delete
return;
[245] Fix | Delete
}
[246] Fix | Delete
$this->__construct($location, $timeout, $redirects, $headers, $useragent, $force_fsockopen, $curl_options);
[247] Fix | Delete
return;
[248] Fix | Delete
}
[249] Fix | Delete
if (($contentEncodingHeader = $this->get_header_line('content-encoding')) !== '') {
[250] Fix | Delete
// Hey, we act dumb elsewhere, so let's do that here too
[251] Fix | Delete
switch (strtolower(trim($contentEncodingHeader, "\x09\x0A\x0D\x20"))) {
[252] Fix | Delete
case 'gzip':
[253] Fix | Delete
case 'x-gzip':
[254] Fix | Delete
if (($decompressed = gzdecode($this->body)) === false) {
[255] Fix | Delete
$this->error = 'Unable to decode HTTP "gzip" stream';
[256] Fix | Delete
$this->success = false;
[257] Fix | Delete
} else {
[258] Fix | Delete
$this->body = $decompressed;
[259] Fix | Delete
}
[260] Fix | Delete
break;
[261] Fix | Delete
[262] Fix | Delete
case 'deflate':
[263] Fix | Delete
if (($decompressed = gzinflate($this->body)) !== false) {
[264] Fix | Delete
$this->body = $decompressed;
[265] Fix | Delete
} elseif (($decompressed = gzuncompress($this->body)) !== false) {
[266] Fix | Delete
$this->body = $decompressed;
[267] Fix | Delete
} elseif (($decompressed = gzdecode($this->body)) !== false) {
[268] Fix | Delete
$this->body = $decompressed;
[269] Fix | Delete
} else {
[270] Fix | Delete
$this->error = 'Unable to decode HTTP "deflate" stream';
[271] Fix | Delete
$this->success = false;
[272] Fix | Delete
}
[273] Fix | Delete
break;
[274] Fix | Delete
[275] Fix | Delete
default:
[276] Fix | Delete
$this->error = 'Unknown content coding';
[277] Fix | Delete
$this->success = false;
[278] Fix | Delete
}
[279] Fix | Delete
}
[280] Fix | Delete
}
[281] Fix | Delete
} else {
[282] Fix | Delete
$this->error = 'fsocket timed out';
[283] Fix | Delete
$this->success = false;
[284] Fix | Delete
}
[285] Fix | Delete
fclose($fp);
[286] Fix | Delete
}
[287] Fix | Delete
}
[288] Fix | Delete
} else {
[289] Fix | Delete
$this->method = \SimplePie\SimplePie::FILE_SOURCE_LOCAL | \SimplePie\SimplePie::FILE_SOURCE_FILE_GET_CONTENTS;
[290] Fix | Delete
if (empty($url) || !is_readable($url) || false === $filebody = file_get_contents($url)) {
[291] Fix | Delete
$this->body = '';
[292] Fix | Delete
$this->error = sprintf('file "%s" is not readable', $url);
[293] Fix | Delete
$this->success = false;
[294] Fix | Delete
} else {
[295] Fix | Delete
$this->body = $filebody;
[296] Fix | Delete
$this->status_code = 200;
[297] Fix | Delete
}
[298] Fix | Delete
}
[299] Fix | Delete
if ($this->success) {
[300] Fix | Delete
assert($this->body !== null); // For PHPStan
[301] Fix | Delete
// Leading whitespace may cause XML parsing errors (XML declaration cannot be preceded by anything other than BOM) so we trim it.
[302] Fix | Delete
// Note that unlike built-in `trim` function’s default settings, we do not trim `\x00` to avoid breaking characters in UTF-16 or UTF-32 encoded strings.
[303] Fix | Delete
// We also only do that when the whitespace is followed by `<`, so that we do not break e.g. UTF-16LE encoded whitespace like `\n\x00` in half.
[304] Fix | Delete
$this->body = preg_replace('/^[ \n\r\t\v]+</', '<', $this->body);
[305] Fix | Delete
}
[306] Fix | Delete
}
[307] Fix | Delete
[308] Fix | Delete
public function get_permanent_uri(): string
[309] Fix | Delete
{
[310] Fix | Delete
return (string) $this->permanent_url;
[311] Fix | Delete
}
[312] Fix | Delete
[313] Fix | Delete
public function get_final_requested_uri(): string
[314] Fix | Delete
{
[315] Fix | Delete
return (string) $this->url;
[316] Fix | Delete
}
[317] Fix | Delete
[318] Fix | Delete
public function get_status_code(): int
[319] Fix | Delete
{
[320] Fix | Delete
return (int) $this->status_code;
[321] Fix | Delete
}
[322] Fix | Delete
[323] Fix | Delete
public function get_headers(): array
[324] Fix | Delete
{
[325] Fix | Delete
$this->maybe_update_headers();
[326] Fix | Delete
return $this->parsed_headers;
[327] Fix | Delete
}
[328] Fix | Delete
[329] Fix | Delete
public function has_header(string $name): bool
[330] Fix | Delete
{
[331] Fix | Delete
$this->maybe_update_headers();
[332] Fix | Delete
return $this->get_header($name) !== [];
[333] Fix | Delete
}
[334] Fix | Delete
[335] Fix | Delete
public function get_header(string $name): array
[336] Fix | Delete
{
[337] Fix | Delete
$this->maybe_update_headers();
[338] Fix | Delete
return $this->parsed_headers[strtolower($name)] ?? [];
[339] Fix | Delete
}
[340] Fix | Delete
[341] Fix | Delete
public function with_header(string $name, $value)
[342] Fix | Delete
{
[343] Fix | Delete
$this->maybe_update_headers();
[344] Fix | Delete
$new = clone $this;
[345] Fix | Delete
[346] Fix | Delete
$newHeader = [
[347] Fix | Delete
strtolower($name) => (array) $value,
[348] Fix | Delete
];
[349] Fix | Delete
$new->set_headers($newHeader + $this->get_headers());
[350] Fix | Delete
[351] Fix | Delete
return $new;
[352] Fix | Delete
}
[353] Fix | Delete
[354] Fix | Delete
public function get_header_line(string $name): string
[355] Fix | Delete
{
[356] Fix | Delete
$this->maybe_update_headers();
[357] Fix | Delete
return implode(', ', $this->get_header($name));
[358] Fix | Delete
}
[359] Fix | Delete
[360] Fix | Delete
public function get_body_content(): string
[361] Fix | Delete
{
[362] Fix | Delete
return (string) $this->body;
[363] Fix | Delete
}
[364] Fix | Delete
[365] Fix | Delete
/**
[366] Fix | Delete
* Check if the $headers property was changed and update the internal state accordingly.
[367] Fix | Delete
*/
[368] Fix | Delete
private function maybe_update_headers(): void
[369] Fix | Delete
{
[370] Fix | Delete
if ($this->headers !== $this->last_headers) {
[371] Fix | Delete
$this->parsed_headers = array_map(
[372] Fix | Delete
function (string $header_line): array {
[373] Fix | Delete
if (strpos($header_line, ',') === false) {
[374] Fix | Delete
return [$header_line];
[375] Fix | Delete
} else {
[376] Fix | Delete
return array_map('trim', explode(',', $header_line));
[377] Fix | Delete
}
[378] Fix | Delete
},
[379] Fix | Delete
$this->headers
[380] Fix | Delete
);
[381] Fix | Delete
}
[382] Fix | Delete
$this->last_headers = $this->headers;
[383] Fix | Delete
}
[384] Fix | Delete
[385] Fix | Delete
/**
[386] Fix | Delete
* Sets headers internally.
[387] Fix | Delete
*
[388] Fix | Delete
* @param array<string, non-empty-array<string>> $headers
[389] Fix | Delete
*/
[390] Fix | Delete
private function set_headers(array $headers): void
[391] Fix | Delete
{
[392] Fix | Delete
$this->parsed_headers = $headers;
[393] Fix | Delete
$this->headers = self::flatten_headers($headers);
[394] Fix | Delete
$this->last_headers = $this->headers;
[395] Fix | Delete
}
[396] Fix | Delete
[397] Fix | Delete
/**
[398] Fix | Delete
* Converts PSR-7 compatible headers into a legacy format.
[399] Fix | Delete
*
[400] Fix | Delete
* @param array<string, non-empty-array<string>> $headers
[401] Fix | Delete
*
[402] Fix | Delete
* @return array<string, string>
[403] Fix | Delete
*/
[404] Fix | Delete
private function flatten_headers(array $headers): array
[405] Fix | Delete
{
[406] Fix | Delete
return array_map(function (array $values): string {
[407] Fix | Delete
return implode(',', $values);
[408] Fix | Delete
}, $headers);
[409] Fix | Delete
}
[410] Fix | Delete
[411] Fix | Delete
/**
[412] Fix | Delete
* Create a File instance from another Response
[413] Fix | Delete
*
[414] Fix | Delete
* For BC reasons in some places there MUST be a `File` instance
[415] Fix | Delete
* instead of a `Response` implementation
[416] Fix | Delete
*
[417] Fix | Delete
* @see Locator::__construct()
[418] Fix | Delete
* @internal
[419] Fix | Delete
*/
[420] Fix | Delete
final public static function fromResponse(Response $response): self
[421] Fix | Delete
{
[422] Fix | Delete
$headers = [];
[423] Fix | Delete
[424] Fix | Delete
foreach ($response->get_headers() as $name => $header) {
[425] Fix | Delete
$headers[$name] = implode(', ', $header);
[426] Fix | Delete
}
[427] Fix | Delete
[428] Fix | Delete
/** @var File */
[429] Fix | Delete
$file = (new \ReflectionClass(File::class))->newInstanceWithoutConstructor();
[430] Fix | Delete
[431] Fix | Delete
$file->url = $response->get_final_requested_uri();
[432] Fix | Delete
$file->useragent = null;
[433] Fix | Delete
$file->headers = $headers;
[434] Fix | Delete
$file->body = $response->get_body_content();
[435] Fix | Delete
$file->status_code = $response->get_status_code();
[436] Fix | Delete
$file->permanent_url = $response->get_permanent_uri();
[437] Fix | Delete
[438] Fix | Delete
return $file;
[439] Fix | Delete
}
[440] Fix | Delete
}
[441] Fix | Delete
[442] Fix | Delete
class_alias('SimplePie\File', 'SimplePie_File');
[443] Fix | Delete
[444] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function