Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. MultipartStream.php

function MultipartStream::addElement

1 call to MultipartStream::addElement()
MultipartStream::createStream in vendor/guzzlehttp/psr7/src/MultipartStream.php
Create the aggregate stream that will be used to upload the POST data

File

vendor/guzzlehttp/psr7/src/MultipartStream.php, line 86

Class

MultipartStream
Stream that when read returns bytes for a streaming multipart or multipart/form-data stream.

Namespace

GuzzleHttp\Psr7

Code

private function addElement(AppendStream $stream, array $element) : void {
    foreach ([
        'contents',
        'name',
    ] as $key) {
        if (!array_key_exists($key, $element)) {
            throw new \InvalidArgumentException("A '{$key}' key is required");
        }
    }
    $element['contents'] = Utils::streamFor($element['contents']);
    if (empty($element['filename'])) {
        $uri = $element['contents']->getMetadata('uri');
        if ($uri && \is_string($uri) && \substr($uri, 0, 6) !== 'php://' && \substr($uri, 0, 7) !== 'data://') {
            $element['filename'] = $uri;
        }
    }
    [
        $body,
        $headers,
    ] = $this->createElement($element['name'], $element['contents'], $element['filename'] ?? null, $element['headers'] ?? []);
    $stream->addStream(Utils::streamFor($this->getHeaders($headers)));
    $stream->addStream($body);
    $stream->addStream(Utils::streamFor("\r\n"));
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal