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: MessageTrait.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\MessageInterface;
[5] Fix | Delete
use YoastSEO_Vendor\Psr\Http\Message\StreamInterface;
[6] Fix | Delete
/**
[7] Fix | Delete
* Trait implementing functionality common to requests and responses.
[8] Fix | Delete
*/
[9] Fix | Delete
trait MessageTrait
[10] Fix | Delete
{
[11] Fix | Delete
/** @var string[][] Map of all registered headers, as original name => array of values */
[12] Fix | Delete
private $headers = [];
[13] Fix | Delete
/** @var string[] Map of lowercase header name => original name at registration */
[14] Fix | Delete
private $headerNames = [];
[15] Fix | Delete
/** @var string */
[16] Fix | Delete
private $protocol = '1.1';
[17] Fix | Delete
/** @var StreamInterface|null */
[18] Fix | Delete
private $stream;
[19] Fix | Delete
public function getProtocolVersion() : string
[20] Fix | Delete
{
[21] Fix | Delete
return $this->protocol;
[22] Fix | Delete
}
[23] Fix | Delete
public function withProtocolVersion($version) : \YoastSEO_Vendor\Psr\Http\Message\MessageInterface
[24] Fix | Delete
{
[25] Fix | Delete
if ($this->protocol === $version) {
[26] Fix | Delete
return $this;
[27] Fix | Delete
}
[28] Fix | Delete
$new = clone $this;
[29] Fix | Delete
$new->protocol = $version;
[30] Fix | Delete
return $new;
[31] Fix | Delete
}
[32] Fix | Delete
public function getHeaders() : array
[33] Fix | Delete
{
[34] Fix | Delete
return $this->headers;
[35] Fix | Delete
}
[36] Fix | Delete
public function hasHeader($header) : bool
[37] Fix | Delete
{
[38] Fix | Delete
return isset($this->headerNames[\strtolower($header)]);
[39] Fix | Delete
}
[40] Fix | Delete
public function getHeader($header) : array
[41] Fix | Delete
{
[42] Fix | Delete
$header = \strtolower($header);
[43] Fix | Delete
if (!isset($this->headerNames[$header])) {
[44] Fix | Delete
return [];
[45] Fix | Delete
}
[46] Fix | Delete
$header = $this->headerNames[$header];
[47] Fix | Delete
return $this->headers[$header];
[48] Fix | Delete
}
[49] Fix | Delete
public function getHeaderLine($header) : string
[50] Fix | Delete
{
[51] Fix | Delete
return \implode(', ', $this->getHeader($header));
[52] Fix | Delete
}
[53] Fix | Delete
public function withHeader($header, $value) : \YoastSEO_Vendor\Psr\Http\Message\MessageInterface
[54] Fix | Delete
{
[55] Fix | Delete
$this->assertHeader($header);
[56] Fix | Delete
$value = $this->normalizeHeaderValue($value);
[57] Fix | Delete
$normalized = \strtolower($header);
[58] Fix | Delete
$new = clone $this;
[59] Fix | Delete
if (isset($new->headerNames[$normalized])) {
[60] Fix | Delete
unset($new->headers[$new->headerNames[$normalized]]);
[61] Fix | Delete
}
[62] Fix | Delete
$new->headerNames[$normalized] = $header;
[63] Fix | Delete
$new->headers[$header] = $value;
[64] Fix | Delete
return $new;
[65] Fix | Delete
}
[66] Fix | Delete
public function withAddedHeader($header, $value) : \YoastSEO_Vendor\Psr\Http\Message\MessageInterface
[67] Fix | Delete
{
[68] Fix | Delete
$this->assertHeader($header);
[69] Fix | Delete
$value = $this->normalizeHeaderValue($value);
[70] Fix | Delete
$normalized = \strtolower($header);
[71] Fix | Delete
$new = clone $this;
[72] Fix | Delete
if (isset($new->headerNames[$normalized])) {
[73] Fix | Delete
$header = $this->headerNames[$normalized];
[74] Fix | Delete
$new->headers[$header] = \array_merge($this->headers[$header], $value);
[75] Fix | Delete
} else {
[76] Fix | Delete
$new->headerNames[$normalized] = $header;
[77] Fix | Delete
$new->headers[$header] = $value;
[78] Fix | Delete
}
[79] Fix | Delete
return $new;
[80] Fix | Delete
}
[81] Fix | Delete
public function withoutHeader($header) : \YoastSEO_Vendor\Psr\Http\Message\MessageInterface
[82] Fix | Delete
{
[83] Fix | Delete
$normalized = \strtolower($header);
[84] Fix | Delete
if (!isset($this->headerNames[$normalized])) {
[85] Fix | Delete
return $this;
[86] Fix | Delete
}
[87] Fix | Delete
$header = $this->headerNames[$normalized];
[88] Fix | Delete
$new = clone $this;
[89] Fix | Delete
unset($new->headers[$header], $new->headerNames[$normalized]);
[90] Fix | Delete
return $new;
[91] Fix | Delete
}
[92] Fix | Delete
public function getBody() : \YoastSEO_Vendor\Psr\Http\Message\StreamInterface
[93] Fix | Delete
{
[94] Fix | Delete
if (!$this->stream) {
[95] Fix | Delete
$this->stream = \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::streamFor('');
[96] Fix | Delete
}
[97] Fix | Delete
return $this->stream;
[98] Fix | Delete
}
[99] Fix | Delete
public function withBody(\YoastSEO_Vendor\Psr\Http\Message\StreamInterface $body) : \YoastSEO_Vendor\Psr\Http\Message\MessageInterface
[100] Fix | Delete
{
[101] Fix | Delete
if ($body === $this->stream) {
[102] Fix | Delete
return $this;
[103] Fix | Delete
}
[104] Fix | Delete
$new = clone $this;
[105] Fix | Delete
$new->stream = $body;
[106] Fix | Delete
return $new;
[107] Fix | Delete
}
[108] Fix | Delete
/**
[109] Fix | Delete
* @param (string|string[])[] $headers
[110] Fix | Delete
*/
[111] Fix | Delete
private function setHeaders(array $headers) : void
[112] Fix | Delete
{
[113] Fix | Delete
$this->headerNames = $this->headers = [];
[114] Fix | Delete
foreach ($headers as $header => $value) {
[115] Fix | Delete
// Numeric array keys are converted to int by PHP.
[116] Fix | Delete
$header = (string) $header;
[117] Fix | Delete
$this->assertHeader($header);
[118] Fix | Delete
$value = $this->normalizeHeaderValue($value);
[119] Fix | Delete
$normalized = \strtolower($header);
[120] Fix | Delete
if (isset($this->headerNames[$normalized])) {
[121] Fix | Delete
$header = $this->headerNames[$normalized];
[122] Fix | Delete
$this->headers[$header] = \array_merge($this->headers[$header], $value);
[123] Fix | Delete
} else {
[124] Fix | Delete
$this->headerNames[$normalized] = $header;
[125] Fix | Delete
$this->headers[$header] = $value;
[126] Fix | Delete
}
[127] Fix | Delete
}
[128] Fix | Delete
}
[129] Fix | Delete
/**
[130] Fix | Delete
* @param mixed $value
[131] Fix | Delete
*
[132] Fix | Delete
* @return string[]
[133] Fix | Delete
*/
[134] Fix | Delete
private function normalizeHeaderValue($value) : array
[135] Fix | Delete
{
[136] Fix | Delete
if (!\is_array($value)) {
[137] Fix | Delete
return $this->trimAndValidateHeaderValues([$value]);
[138] Fix | Delete
}
[139] Fix | Delete
if (\count($value) === 0) {
[140] Fix | Delete
throw new \InvalidArgumentException('Header value can not be an empty array.');
[141] Fix | Delete
}
[142] Fix | Delete
return $this->trimAndValidateHeaderValues($value);
[143] Fix | Delete
}
[144] Fix | Delete
/**
[145] Fix | Delete
* Trims whitespace from the header values.
[146] Fix | Delete
*
[147] Fix | Delete
* Spaces and tabs ought to be excluded by parsers when extracting the field value from a header field.
[148] Fix | Delete
*
[149] Fix | Delete
* header-field = field-name ":" OWS field-value OWS
[150] Fix | Delete
* OWS = *( SP / HTAB )
[151] Fix | Delete
*
[152] Fix | Delete
* @param mixed[] $values Header values
[153] Fix | Delete
*
[154] Fix | Delete
* @return string[] Trimmed header values
[155] Fix | Delete
*
[156] Fix | Delete
* @see https://datatracker.ietf.org/doc/html/rfc7230#section-3.2.4
[157] Fix | Delete
*/
[158] Fix | Delete
private function trimAndValidateHeaderValues(array $values) : array
[159] Fix | Delete
{
[160] Fix | Delete
return \array_map(function ($value) {
[161] Fix | Delete
if (!\is_scalar($value) && null !== $value) {
[162] Fix | Delete
throw new \InvalidArgumentException(\sprintf('Header value must be scalar or null but %s provided.', \is_object($value) ? \get_class($value) : \gettype($value)));
[163] Fix | Delete
}
[164] Fix | Delete
$trimmed = \trim((string) $value, " \t");
[165] Fix | Delete
$this->assertValue($trimmed);
[166] Fix | Delete
return $trimmed;
[167] Fix | Delete
}, \array_values($values));
[168] Fix | Delete
}
[169] Fix | Delete
/**
[170] Fix | Delete
* @see https://datatracker.ietf.org/doc/html/rfc7230#section-3.2
[171] Fix | Delete
*
[172] Fix | Delete
* @param mixed $header
[173] Fix | Delete
*/
[174] Fix | Delete
private function assertHeader($header) : void
[175] Fix | Delete
{
[176] Fix | Delete
if (!\is_string($header)) {
[177] Fix | Delete
throw new \InvalidArgumentException(\sprintf('Header name must be a string but %s provided.', \is_object($header) ? \get_class($header) : \gettype($header)));
[178] Fix | Delete
}
[179] Fix | Delete
if (!\preg_match('/^[a-zA-Z0-9\'`#$%&*+.^_|~!-]+$/D', $header)) {
[180] Fix | Delete
throw new \InvalidArgumentException(\sprintf('"%s" is not valid header name.', $header));
[181] Fix | Delete
}
[182] Fix | Delete
}
[183] Fix | Delete
/**
[184] Fix | Delete
* @see https://datatracker.ietf.org/doc/html/rfc7230#section-3.2
[185] Fix | Delete
*
[186] Fix | Delete
* field-value = *( field-content / obs-fold )
[187] Fix | Delete
* field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ]
[188] Fix | Delete
* field-vchar = VCHAR / obs-text
[189] Fix | Delete
* VCHAR = %x21-7E
[190] Fix | Delete
* obs-text = %x80-FF
[191] Fix | Delete
* obs-fold = CRLF 1*( SP / HTAB )
[192] Fix | Delete
*/
[193] Fix | Delete
private function assertValue(string $value) : void
[194] Fix | Delete
{
[195] Fix | Delete
// The regular expression intentionally does not support the obs-fold production, because as
[196] Fix | Delete
// per RFC 7230#3.2.4:
[197] Fix | Delete
//
[198] Fix | Delete
// A sender MUST NOT generate a message that includes
[199] Fix | Delete
// line folding (i.e., that has any field-value that contains a match to
[200] Fix | Delete
// the obs-fold rule) unless the message is intended for packaging
[201] Fix | Delete
// within the message/http media type.
[202] Fix | Delete
//
[203] Fix | Delete
// Clients must not send a request with line folding and a server sending folded headers is
[204] Fix | Delete
// likely very rare. Line folding is a fairly obscure feature of HTTP/1.1 and thus not accepting
[205] Fix | Delete
// folding is not likely to break any legitimate use case.
[206] Fix | Delete
if (!\preg_match('/^[\\x20\\x09\\x21-\\x7E\\x80-\\xFF]*$/D', $value)) {
[207] Fix | Delete
throw new \InvalidArgumentException(\sprintf('"%s" is not valid header value.', $value));
[208] Fix | Delete
}
[209] Fix | Delete
}
[210] Fix | Delete
}
[211] Fix | Delete
[212] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function