Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/wordpres.../vendor_p.../guzzleht.../psr7/src
File: MultipartStream.php
<?php
[0] Fix | Delete
[1] Fix | Delete
declare (strict_types=1);
[2] Fix | Delete
namespace YoastSEO_Vendor\GuzzleHttp\Psr7;
[3] Fix | Delete
[4] Fix | Delete
use YoastSEO_Vendor\Psr\Http\Message\StreamInterface;
[5] Fix | Delete
/**
[6] Fix | Delete
* Stream that when read returns bytes for a streaming multipart or
[7] Fix | Delete
* multipart/form-data stream.
[8] Fix | Delete
*/
[9] Fix | Delete
final class MultipartStream implements \YoastSEO_Vendor\Psr\Http\Message\StreamInterface
[10] Fix | Delete
{
[11] Fix | Delete
use StreamDecoratorTrait;
[12] Fix | Delete
/** @var string */
[13] Fix | Delete
private $boundary;
[14] Fix | Delete
/** @var StreamInterface */
[15] Fix | Delete
private $stream;
[16] Fix | Delete
/**
[17] Fix | Delete
* @param array $elements Array of associative arrays, each containing a
[18] Fix | Delete
* required "name" key mapping to the form field,
[19] Fix | Delete
* name, a required "contents" key mapping to a
[20] Fix | Delete
* StreamInterface/resource/string, an optional
[21] Fix | Delete
* "headers" associative array of custom headers,
[22] Fix | Delete
* and an optional "filename" key mapping to a
[23] Fix | Delete
* string to send as the filename in the part.
[24] Fix | Delete
* @param string $boundary You can optionally provide a specific boundary
[25] Fix | Delete
*
[26] Fix | Delete
* @throws \InvalidArgumentException
[27] Fix | Delete
*/
[28] Fix | Delete
public function __construct(array $elements = [], string $boundary = null)
[29] Fix | Delete
{
[30] Fix | Delete
$this->boundary = $boundary ?: \bin2hex(\random_bytes(20));
[31] Fix | Delete
$this->stream = $this->createStream($elements);
[32] Fix | Delete
}
[33] Fix | Delete
public function getBoundary() : string
[34] Fix | Delete
{
[35] Fix | Delete
return $this->boundary;
[36] Fix | Delete
}
[37] Fix | Delete
public function isWritable() : bool
[38] Fix | Delete
{
[39] Fix | Delete
return \false;
[40] Fix | Delete
}
[41] Fix | Delete
/**
[42] Fix | Delete
* Get the headers needed before transferring the content of a POST file
[43] Fix | Delete
*
[44] Fix | Delete
* @param string[] $headers
[45] Fix | Delete
*/
[46] Fix | Delete
private function getHeaders(array $headers) : string
[47] Fix | Delete
{
[48] Fix | Delete
$str = '';
[49] Fix | Delete
foreach ($headers as $key => $value) {
[50] Fix | Delete
$str .= "{$key}: {$value}\r\n";
[51] Fix | Delete
}
[52] Fix | Delete
return "--{$this->boundary}\r\n" . \trim($str) . "\r\n\r\n";
[53] Fix | Delete
}
[54] Fix | Delete
/**
[55] Fix | Delete
* Create the aggregate stream that will be used to upload the POST data
[56] Fix | Delete
*/
[57] Fix | Delete
protected function createStream(array $elements = []) : \YoastSEO_Vendor\Psr\Http\Message\StreamInterface
[58] Fix | Delete
{
[59] Fix | Delete
$stream = new \YoastSEO_Vendor\GuzzleHttp\Psr7\AppendStream();
[60] Fix | Delete
foreach ($elements as $element) {
[61] Fix | Delete
if (!\is_array($element)) {
[62] Fix | Delete
throw new \UnexpectedValueException('An array is expected');
[63] Fix | Delete
}
[64] Fix | Delete
$this->addElement($stream, $element);
[65] Fix | Delete
}
[66] Fix | Delete
// Add the trailing boundary with CRLF
[67] Fix | Delete
$stream->addStream(\YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::streamFor("--{$this->boundary}--\r\n"));
[68] Fix | Delete
return $stream;
[69] Fix | Delete
}
[70] Fix | Delete
private function addElement(\YoastSEO_Vendor\GuzzleHttp\Psr7\AppendStream $stream, array $element) : void
[71] Fix | Delete
{
[72] Fix | Delete
foreach (['contents', 'name'] as $key) {
[73] Fix | Delete
if (!\array_key_exists($key, $element)) {
[74] Fix | Delete
throw new \InvalidArgumentException("A '{$key}' key is required");
[75] Fix | Delete
}
[76] Fix | Delete
}
[77] Fix | Delete
$element['contents'] = \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::streamFor($element['contents']);
[78] Fix | Delete
if (empty($element['filename'])) {
[79] Fix | Delete
$uri = $element['contents']->getMetadata('uri');
[80] Fix | Delete
if ($uri && \is_string($uri) && \substr($uri, 0, 6) !== 'php://' && \substr($uri, 0, 7) !== 'data://') {
[81] Fix | Delete
$element['filename'] = $uri;
[82] Fix | Delete
}
[83] Fix | Delete
}
[84] Fix | Delete
[$body, $headers] = $this->createElement($element['name'], $element['contents'], $element['filename'] ?? null, $element['headers'] ?? []);
[85] Fix | Delete
$stream->addStream(\YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::streamFor($this->getHeaders($headers)));
[86] Fix | Delete
$stream->addStream($body);
[87] Fix | Delete
$stream->addStream(\YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::streamFor("\r\n"));
[88] Fix | Delete
}
[89] Fix | Delete
/**
[90] Fix | Delete
* @param string[] $headers
[91] Fix | Delete
*
[92] Fix | Delete
* @return array{0: StreamInterface, 1: string[]}
[93] Fix | Delete
*/
[94] Fix | Delete
private function createElement(string $name, \YoastSEO_Vendor\Psr\Http\Message\StreamInterface $stream, ?string $filename, array $headers) : array
[95] Fix | Delete
{
[96] Fix | Delete
// Set a default content-disposition header if one was no provided
[97] Fix | Delete
$disposition = self::getHeader($headers, 'content-disposition');
[98] Fix | Delete
if (!$disposition) {
[99] Fix | Delete
$headers['Content-Disposition'] = $filename === '0' || $filename ? \sprintf('form-data; name="%s"; filename="%s"', $name, \basename($filename)) : "form-data; name=\"{$name}\"";
[100] Fix | Delete
}
[101] Fix | Delete
// Set a default content-length header if one was no provided
[102] Fix | Delete
$length = self::getHeader($headers, 'content-length');
[103] Fix | Delete
if (!$length) {
[104] Fix | Delete
if ($length = $stream->getSize()) {
[105] Fix | Delete
$headers['Content-Length'] = (string) $length;
[106] Fix | Delete
}
[107] Fix | Delete
}
[108] Fix | Delete
// Set a default Content-Type if one was not supplied
[109] Fix | Delete
$type = self::getHeader($headers, 'content-type');
[110] Fix | Delete
if (!$type && ($filename === '0' || $filename)) {
[111] Fix | Delete
$headers['Content-Type'] = \YoastSEO_Vendor\GuzzleHttp\Psr7\MimeType::fromFilename($filename) ?? 'application/octet-stream';
[112] Fix | Delete
}
[113] Fix | Delete
return [$stream, $headers];
[114] Fix | Delete
}
[115] Fix | Delete
/**
[116] Fix | Delete
* @param string[] $headers
[117] Fix | Delete
*/
[118] Fix | Delete
private static function getHeader(array $headers, string $key) : ?string
[119] Fix | Delete
{
[120] Fix | Delete
$lowercaseHeader = \strtolower($key);
[121] Fix | Delete
foreach ($headers as $k => $v) {
[122] Fix | Delete
if (\strtolower((string) $k) === $lowercaseHeader) {
[123] Fix | Delete
return $v;
[124] Fix | Delete
}
[125] Fix | Delete
}
[126] Fix | Delete
return null;
[127] Fix | Delete
}
[128] Fix | Delete
}
[129] Fix | Delete
[130] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function