summaryrefslogtreecommitdiff
path: root/vendor/guzzlehttp/psr7/src/MultipartStream.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/guzzlehttp/psr7/src/MultipartStream.php')
-rw-r--r--vendor/guzzlehttp/psr7/src/MultipartStream.php22
1 files changed, 15 insertions, 7 deletions
diff --git a/vendor/guzzlehttp/psr7/src/MultipartStream.php b/vendor/guzzlehttp/psr7/src/MultipartStream.php
index 41c48eef8..43d718f65 100644
--- a/vendor/guzzlehttp/psr7/src/MultipartStream.php
+++ b/vendor/guzzlehttp/psr7/src/MultipartStream.php
@@ -32,7 +32,7 @@ final class MultipartStream implements StreamInterface
*
* @throws \InvalidArgumentException
*/
- public function __construct(array $elements = [], string $boundary = null)
+ public function __construct(array $elements = [], ?string $boundary = null)
{
$this->boundary = $boundary ?: bin2hex(random_bytes(20));
$this->stream = $this->createStream($elements);
@@ -51,7 +51,7 @@ final class MultipartStream implements StreamInterface
/**
* Get the headers needed before transferring the content of a POST file
*
- * @param array<string, string> $headers
+ * @param string[] $headers
*/
private function getHeaders(array $headers): string
{
@@ -112,10 +112,15 @@ final class MultipartStream implements StreamInterface
$stream->addStream(Utils::streamFor("\r\n"));
}
+ /**
+ * @param string[] $headers
+ *
+ * @return array{0: StreamInterface, 1: string[]}
+ */
private function createElement(string $name, StreamInterface $stream, ?string $filename, array $headers): array
{
// Set a default content-disposition header if one was no provided
- $disposition = $this->getHeader($headers, 'content-disposition');
+ $disposition = self::getHeader($headers, 'content-disposition');
if (!$disposition) {
$headers['Content-Disposition'] = ($filename === '0' || $filename)
? sprintf(
@@ -127,7 +132,7 @@ final class MultipartStream implements StreamInterface
}
// Set a default content-length header if one was no provided
- $length = $this->getHeader($headers, 'content-length');
+ $length = self::getHeader($headers, 'content-length');
if (!$length) {
if ($length = $stream->getSize()) {
$headers['Content-Length'] = (string) $length;
@@ -135,7 +140,7 @@ final class MultipartStream implements StreamInterface
}
// Set a default Content-Type if one was not supplied
- $type = $this->getHeader($headers, 'content-type');
+ $type = self::getHeader($headers, 'content-type');
if (!$type && ($filename === '0' || $filename)) {
$headers['Content-Type'] = MimeType::fromFilename($filename) ?? 'application/octet-stream';
}
@@ -143,11 +148,14 @@ final class MultipartStream implements StreamInterface
return [$stream, $headers];
}
- private function getHeader(array $headers, string $key)
+ /**
+ * @param string[] $headers
+ */
+ private static function getHeader(array $headers, string $key): ?string
{
$lowercaseHeader = strtolower($key);
foreach ($headers as $k => $v) {
- if (strtolower($k) === $lowercaseHeader) {
+ if (strtolower((string) $k) === $lowercaseHeader) {
return $v;
}
}