Edit File by line
/home/barbar84/www/wp-conte.../plugins/updraftp.../vendor/guzzleht.../psr7/src
File: MessageTrait.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace GuzzleHttp\Psr7;
[2] Fix | Delete
[3] Fix | Delete
use Psr\Http\Message\StreamInterface;
[4] Fix | Delete
[5] Fix | Delete
/**
[6] Fix | Delete
* Trait implementing functionality common to requests and responses.
[7] Fix | Delete
*/
[8] Fix | Delete
trait MessageTrait
[9] Fix | Delete
{
[10] Fix | Delete
/** @var array Map of all registered headers, as original name => array of values */
[11] Fix | Delete
private $headers = [];
[12] Fix | Delete
[13] Fix | Delete
/** @var array Map of lowercase header name => original name at registration */
[14] Fix | Delete
private $headerNames = [];
[15] Fix | Delete
[16] Fix | Delete
/** @var string */
[17] Fix | Delete
private $protocol = '1.1';
[18] Fix | Delete
[19] Fix | Delete
/** @var StreamInterface|null */
[20] Fix | Delete
private $stream;
[21] Fix | Delete
[22] Fix | Delete
public function getProtocolVersion()
[23] Fix | Delete
{
[24] Fix | Delete
return $this->protocol;
[25] Fix | Delete
}
[26] Fix | Delete
[27] Fix | Delete
public function withProtocolVersion($version)
[28] Fix | Delete
{
[29] Fix | Delete
if ($this->protocol === $version) {
[30] Fix | Delete
return $this;
[31] Fix | Delete
}
[32] Fix | Delete
[33] Fix | Delete
$new = clone $this;
[34] Fix | Delete
$new->protocol = $version;
[35] Fix | Delete
return $new;
[36] Fix | Delete
}
[37] Fix | Delete
[38] Fix | Delete
public function getHeaders()
[39] Fix | Delete
{
[40] Fix | Delete
return $this->headers;
[41] Fix | Delete
}
[42] Fix | Delete
[43] Fix | Delete
public function hasHeader($header)
[44] Fix | Delete
{
[45] Fix | Delete
return isset($this->headerNames[strtolower($header)]);
[46] Fix | Delete
}
[47] Fix | Delete
[48] Fix | Delete
public function getHeader($header)
[49] Fix | Delete
{
[50] Fix | Delete
$header = strtolower($header);
[51] Fix | Delete
[52] Fix | Delete
if (!isset($this->headerNames[$header])) {
[53] Fix | Delete
return [];
[54] Fix | Delete
}
[55] Fix | Delete
[56] Fix | Delete
$header = $this->headerNames[$header];
[57] Fix | Delete
[58] Fix | Delete
return $this->headers[$header];
[59] Fix | Delete
}
[60] Fix | Delete
[61] Fix | Delete
public function getHeaderLine($header)
[62] Fix | Delete
{
[63] Fix | Delete
return implode(', ', $this->getHeader($header));
[64] Fix | Delete
}
[65] Fix | Delete
[66] Fix | Delete
public function withHeader($header, $value)
[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
[72] Fix | Delete
$new = clone $this;
[73] Fix | Delete
if (isset($new->headerNames[$normalized])) {
[74] Fix | Delete
unset($new->headers[$new->headerNames[$normalized]]);
[75] Fix | Delete
}
[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
[82] Fix | Delete
public function withAddedHeader($header, $value)
[83] Fix | Delete
{
[84] Fix | Delete
$this->assertHeader($header);
[85] Fix | Delete
$value = $this->normalizeHeaderValue($value);
[86] Fix | Delete
$normalized = strtolower($header);
[87] Fix | Delete
[88] Fix | Delete
$new = clone $this;
[89] Fix | Delete
if (isset($new->headerNames[$normalized])) {
[90] Fix | Delete
$header = $this->headerNames[$normalized];
[91] Fix | Delete
$new->headers[$header] = array_merge($this->headers[$header], $value);
[92] Fix | Delete
} else {
[93] Fix | Delete
$new->headerNames[$normalized] = $header;
[94] Fix | Delete
$new->headers[$header] = $value;
[95] Fix | Delete
}
[96] Fix | Delete
[97] Fix | Delete
return $new;
[98] Fix | Delete
}
[99] Fix | Delete
[100] Fix | Delete
public function withoutHeader($header)
[101] Fix | Delete
{
[102] Fix | Delete
$normalized = strtolower($header);
[103] Fix | Delete
[104] Fix | Delete
if (!isset($this->headerNames[$normalized])) {
[105] Fix | Delete
return $this;
[106] Fix | Delete
}
[107] Fix | Delete
[108] Fix | Delete
$header = $this->headerNames[$normalized];
[109] Fix | Delete
[110] Fix | Delete
$new = clone $this;
[111] Fix | Delete
unset($new->headers[$header], $new->headerNames[$normalized]);
[112] Fix | Delete
[113] Fix | Delete
return $new;
[114] Fix | Delete
}
[115] Fix | Delete
[116] Fix | Delete
public function getBody()
[117] Fix | Delete
{
[118] Fix | Delete
if (!$this->stream) {
[119] Fix | Delete
$this->stream = Utils::streamFor('');
[120] Fix | Delete
}
[121] Fix | Delete
[122] Fix | Delete
return $this->stream;
[123] Fix | Delete
}
[124] Fix | Delete
[125] Fix | Delete
public function withBody(StreamInterface $body)
[126] Fix | Delete
{
[127] Fix | Delete
if ($body === $this->stream) {
[128] Fix | Delete
return $this;
[129] Fix | Delete
}
[130] Fix | Delete
[131] Fix | Delete
$new = clone $this;
[132] Fix | Delete
$new->stream = $body;
[133] Fix | Delete
return $new;
[134] Fix | Delete
}
[135] Fix | Delete
[136] Fix | Delete
private function setHeaders(array $headers)
[137] Fix | Delete
{
[138] Fix | Delete
$this->headerNames = $this->headers = [];
[139] Fix | Delete
foreach ($headers as $header => $value) {
[140] Fix | Delete
if (is_int($header)) {
[141] Fix | Delete
// Numeric array keys are converted to int by PHP but having a header name '123' is not forbidden by the spec
[142] Fix | Delete
// and also allowed in withHeader(). So we need to cast it to string again for the following assertion to pass.
[143] Fix | Delete
$header = (string) $header;
[144] Fix | Delete
}
[145] Fix | Delete
$this->assertHeader($header);
[146] Fix | Delete
$value = $this->normalizeHeaderValue($value);
[147] Fix | Delete
$normalized = strtolower($header);
[148] Fix | Delete
if (isset($this->headerNames[$normalized])) {
[149] Fix | Delete
$header = $this->headerNames[$normalized];
[150] Fix | Delete
$this->headers[$header] = array_merge($this->headers[$header], $value);
[151] Fix | Delete
} else {
[152] Fix | Delete
$this->headerNames[$normalized] = $header;
[153] Fix | Delete
$this->headers[$header] = $value;
[154] Fix | Delete
}
[155] Fix | Delete
}
[156] Fix | Delete
}
[157] Fix | Delete
[158] Fix | Delete
private function normalizeHeaderValue($value)
[159] Fix | Delete
{
[160] Fix | Delete
if (!is_array($value)) {
[161] Fix | Delete
return $this->trimHeaderValues([$value]);
[162] Fix | Delete
}
[163] Fix | Delete
[164] Fix | Delete
if (count($value) === 0) {
[165] Fix | Delete
throw new \InvalidArgumentException('Header value can not be an empty array.');
[166] Fix | Delete
}
[167] Fix | Delete
[168] Fix | Delete
return $this->trimHeaderValues($value);
[169] Fix | Delete
}
[170] Fix | Delete
[171] Fix | Delete
/**
[172] Fix | Delete
* Trims whitespace from the header values.
[173] Fix | Delete
*
[174] Fix | Delete
* Spaces and tabs ought to be excluded by parsers when extracting the field value from a header field.
[175] Fix | Delete
*
[176] Fix | Delete
* header-field = field-name ":" OWS field-value OWS
[177] Fix | Delete
* OWS = *( SP / HTAB )
[178] Fix | Delete
*
[179] Fix | Delete
* @param string[] $values Header values
[180] Fix | Delete
*
[181] Fix | Delete
* @return string[] Trimmed header values
[182] Fix | Delete
*
[183] Fix | Delete
* @see https://tools.ietf.org/html/rfc7230#section-3.2.4
[184] Fix | Delete
*/
[185] Fix | Delete
private function trimHeaderValues(array $values)
[186] Fix | Delete
{
[187] Fix | Delete
return array_map(function ($value) {
[188] Fix | Delete
if (!is_scalar($value) && null !== $value) {
[189] Fix | Delete
throw new \InvalidArgumentException(sprintf(
[190] Fix | Delete
'Header value must be scalar or null but %s provided.',
[191] Fix | Delete
is_object($value) ? get_class($value) : gettype($value)
[192] Fix | Delete
));
[193] Fix | Delete
}
[194] Fix | Delete
[195] Fix | Delete
return trim((string) $value, " \t");
[196] Fix | Delete
}, array_values($values));
[197] Fix | Delete
}
[198] Fix | Delete
[199] Fix | Delete
private function assertHeader($header)
[200] Fix | Delete
{
[201] Fix | Delete
if (!is_string($header)) {
[202] Fix | Delete
throw new \InvalidArgumentException(sprintf(
[203] Fix | Delete
'Header name must be a string but %s provided.',
[204] Fix | Delete
is_object($header) ? get_class($header) : gettype($header)
[205] Fix | Delete
));
[206] Fix | Delete
}
[207] Fix | Delete
[208] Fix | Delete
if ($header === '') {
[209] Fix | Delete
throw new \InvalidArgumentException('Header name can not be empty.');
[210] Fix | Delete
}
[211] Fix | Delete
}
[212] Fix | Delete
}
[213] Fix | Delete
[214] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function