12    use StreamDecoratorTrait;
 
   30        $this->boundary = 
$boundary ?: sha1(uniqid(
'', 
true));
 
   55        foreach ($headers as 
$key => $value) {
 
   56            $str .= 
"{$key}: {$value}\r\n";
 
   59        return "--{$this->boundary}\r\n" . trim($str) . 
"\r\n\r\n";
 
   69        foreach ($elements as $element) {
 
   81        foreach ([
'contents', 
'name'] as 
$key) {
 
   82            if (!array_key_exists(
$key, $element)) {
 
   83                throw new \InvalidArgumentException(
"A '{$key}' key is required");
 
   87        $element[
'contents'] = 
stream_for($element[
'contents']);
 
   89        if (empty($element[
'filename'])) {
 
   90            $uri = $element[
'contents']->getMetadata(
'uri');
 
   91            if (substr($uri, 0, 6) !== 
'php://') {
 
   92                $element[
'filename'] = $uri;
 
   99            isset($element[
'filename']) ? $element[
'filename'] : 
null,
 
  100            isset($element[
'headers']) ? $element[
'headers'] : []
 
  114        $disposition = $this->
getHeader($headers, 
'content-disposition');
 
  117                ? 
sprintf(
'form-data; name="%s"; filename="%s"',
 
  120                : 
"form-data; name=\"{$name}\"";
 
  124        $length = $this->
getHeader($headers, 
'content-length');
 
  126            if ($length = 
$stream->getSize()) {
 
  127                $headers[
'Content-Length'] = (string) $length;
 
  135                $headers[
'Content-Type'] = 
$type;
 
  144        $lowercaseHeader = strtolower(
$key);
 
  145        foreach ($headers as $k => $v) {
 
  146            if (strtolower($k) === $lowercaseHeader) {
 
sprintf('%.4f', $callTime)
An exception for terminatinating execution or to throw for unit testing.
Reads from multiple streams, one after the other.
Stream that when read returns bytes for a streaming multipart or multipart/form-data stream.
createStream(array $elements)
Create the aggregate stream that will be used to upload the POST data.
getHeader(array $headers, $key)
getHeaders(array $headers)
Get the headers needed before transferring the content of a POST file.
createElement($name, StreamInterface $stream, $filename, array $headers)
addElement(AppendStream $stream, array $element)
isWritable()
Returns whether or not the stream is writable.
__construct(array $elements=[], $boundary=null)
getBoundary()
Get the boundary.
$stream
PHP stream implementation.
stream_for($resource='', array $options=[])
Create a new stream based on the input type.
mimetype_from_filename($filename)
Determines the mimetype of a file by looking at its extension.