upgraded dependencies
This commit is contained in:
		
							
								
								
									
										49
									
								
								vendor/guzzlehttp/psr7/src/MultipartStream.php
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										49
									
								
								vendor/guzzlehttp/psr7/src/MultipartStream.php
									
									
									
									
										vendored
									
									
								
							| @@ -1,5 +1,7 @@ | ||||
| <?php | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace GuzzleHttp\Psr7; | ||||
|  | ||||
| use Psr\Http\Message\StreamInterface; | ||||
| @@ -7,15 +9,17 @@ use Psr\Http\Message\StreamInterface; | ||||
| /** | ||||
|  * Stream that when read returns bytes for a streaming multipart or | ||||
|  * multipart/form-data stream. | ||||
|  * | ||||
|  * @final | ||||
|  */ | ||||
| class MultipartStream implements StreamInterface | ||||
| final class MultipartStream implements StreamInterface | ||||
| { | ||||
|     use StreamDecoratorTrait; | ||||
|  | ||||
|     /** @var string */ | ||||
|     private $boundary; | ||||
|  | ||||
|     /** @var StreamInterface */ | ||||
|     private $stream; | ||||
|  | ||||
|     /** | ||||
|      * @param array  $elements Array of associative arrays, each containing a | ||||
|      *                         required "name" key mapping to the form field, | ||||
| @@ -28,31 +32,28 @@ class MultipartStream implements StreamInterface | ||||
|      * | ||||
|      * @throws \InvalidArgumentException | ||||
|      */ | ||||
|     public function __construct(array $elements = [], $boundary = null) | ||||
|     public function __construct(array $elements = [], string $boundary = null) | ||||
|     { | ||||
|         $this->boundary = $boundary ?: sha1(uniqid('', true)); | ||||
|         $this->boundary = $boundary ?: bin2hex(random_bytes(20)); | ||||
|         $this->stream = $this->createStream($elements); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get the boundary | ||||
|      * | ||||
|      * @return string | ||||
|      */ | ||||
|     public function getBoundary() | ||||
|     public function getBoundary(): string | ||||
|     { | ||||
|         return $this->boundary; | ||||
|     } | ||||
|  | ||||
|     public function isWritable() | ||||
|     public function isWritable(): bool | ||||
|     { | ||||
|         return false; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get the headers needed before transferring the content of a POST file | ||||
|      * | ||||
|      * @param array<string, string> $headers | ||||
|      */ | ||||
|     private function getHeaders(array $headers) | ||||
|     private function getHeaders(array $headers): string | ||||
|     { | ||||
|         $str = ''; | ||||
|         foreach ($headers as $key => $value) { | ||||
| @@ -65,11 +66,14 @@ class MultipartStream implements StreamInterface | ||||
|     /** | ||||
|      * Create the aggregate stream that will be used to upload the POST data | ||||
|      */ | ||||
|     protected function createStream(array $elements) | ||||
|     protected function createStream(array $elements = []): StreamInterface | ||||
|     { | ||||
|         $stream = new AppendStream(); | ||||
|  | ||||
|         foreach ($elements as $element) { | ||||
|             if (!is_array($element)) { | ||||
|                 throw new \UnexpectedValueException("An array is expected"); | ||||
|             } | ||||
|             $this->addElement($stream, $element); | ||||
|         } | ||||
|  | ||||
| @@ -79,7 +83,7 @@ class MultipartStream implements StreamInterface | ||||
|         return $stream; | ||||
|     } | ||||
|  | ||||
|     private function addElement(AppendStream $stream, array $element) | ||||
|     private function addElement(AppendStream $stream, array $element): void | ||||
|     { | ||||
|         foreach (['contents', 'name'] as $key) { | ||||
|             if (!array_key_exists($key, $element)) { | ||||
| @@ -91,16 +95,16 @@ class MultipartStream implements StreamInterface | ||||
|  | ||||
|         if (empty($element['filename'])) { | ||||
|             $uri = $element['contents']->getMetadata('uri'); | ||||
|             if (substr($uri, 0, 6) !== 'php://') { | ||||
|             if ($uri && \is_string($uri) && \substr($uri, 0, 6) !== 'php://' && \substr($uri, 0, 7) !== 'data://') { | ||||
|                 $element['filename'] = $uri; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         list($body, $headers) = $this->createElement( | ||||
|         [$body, $headers] = $this->createElement( | ||||
|             $element['name'], | ||||
|             $element['contents'], | ||||
|             isset($element['filename']) ? $element['filename'] : null, | ||||
|             isset($element['headers']) ? $element['headers'] : [] | ||||
|             $element['filename'] ?? null, | ||||
|             $element['headers'] ?? [] | ||||
|         ); | ||||
|  | ||||
|         $stream->addStream(Utils::streamFor($this->getHeaders($headers))); | ||||
| @@ -108,10 +112,7 @@ class MultipartStream implements StreamInterface | ||||
|         $stream->addStream(Utils::streamFor("\r\n")); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return array | ||||
|      */ | ||||
|     private function createElement($name, StreamInterface $stream, $filename, array $headers) | ||||
|     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'); | ||||
| @@ -144,7 +145,7 @@ class MultipartStream implements StreamInterface | ||||
|         return [$stream, $headers]; | ||||
|     } | ||||
|  | ||||
|     private function getHeader(array $headers, $key) | ||||
|     private function getHeader(array $headers, string $key) | ||||
|     { | ||||
|         $lowercaseHeader = strtolower($key); | ||||
|         foreach ($headers as $k => $v) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 RafficMohammed
					RafficMohammed