Documentation

MultipartStreamBuilder
in package

Use PSR-7 MessageInterface to build multipart messages

Tags
link
https://datatracker.ietf.org/doc/html/rfc2046#section-5.1

Table of Contents

Properties

$boundary  : string
$messages  : array<string|int, MessageInterface>
$multipartStream  : StreamInterface
$streamFactory  : StreamFactoryInterface

Methods

__construct()  : mixed
MultipartStreamBuilder constructor
__toString()  : string
Returns the stream content (make sure to save the boundary before!)
addMessage()  : static
Adds a MessageInterface
addStream()  : static
Adds a StreamInterface
addString()  : static
Adds a message with the given content
build()  : StreamInterface|MessageInterface
Builds the multipart content from the given messages.
getBoundary()  : string
Returns the current boundary string
reset()  : static
Clears the MessageInterface array
setBoundary()  : static
Sets a boundary string
getRandomBoundary()  : string
Generates a random boundary string
setContentDispositionHeader()  : MessageInterface
Sets the "Content-Disposition" header in the given MessageInterface if a name and/or filename are given
writeBody()  : void
Writes the content of the given StreamInterface to the multipart stream
writeHeaders()  : void
Parses and writes the headers from the given message to the multipart stream

Properties

Methods

__construct()

MultipartStreamBuilder constructor

public __construct(StreamFactoryInterface $streamFactory) : mixed
Parameters
$streamFactory : StreamFactoryInterface

__toString()

Returns the stream content (make sure to save the boundary before!)

public __toString() : string
Return values
string

addMessage()

Adds a MessageInterface

public addMessage(MessageInterface $message[, string|null $fieldname = null ][, string|null $filename = null ][, bool|null $setContentLength = null ]) : static
Parameters
$message : MessageInterface
$fieldname : string|null = null
$filename : string|null = null
$setContentLength : bool|null = null
Return values
static

addStream()

Adds a StreamInterface

public addStream(StreamInterface $stream[, string|null $fieldname = null ][, string|null $filename = null ][, iterable<string|int, mixed>|null $headers = null ][, bool|null $setContentLength = null ]) : static
Parameters
$stream : StreamInterface
$fieldname : string|null = null
$filename : string|null = null
$headers : iterable<string|int, mixed>|null = null
$setContentLength : bool|null = null
Tags
phpstan-param

array<string, string>|null $headers

Return values
static

addString()

Adds a message with the given content

public addString(string $content[, string|null $fieldname = null ][, string|null $filename = null ][, iterable<string|int, mixed>|null $headers = null ][, bool|null $setContentLength = null ]) : static
Parameters
$content : string
$fieldname : string|null = null
$filename : string|null = null
$headers : iterable<string|int, mixed>|null = null
$setContentLength : bool|null = null
Tags
phpstan-param

array<string, string>|null $headers

Return values
static

build()

Builds the multipart content from the given messages.

public build([MessageInterface|null $message = null ]) : StreamInterface|MessageInterface

If a MessageInterface is given, the body and content type header with the boundary will be set and the MessageInterface is returned; returns the StreamInterface with the content otherwise.

Parameters
$message : MessageInterface|null = null
Return values
StreamInterface|MessageInterface

getBoundary()

Returns the current boundary string

public getBoundary() : string
Return values
string

getRandomBoundary()

Generates a random boundary string

protected getRandomBoundary() : string
Return values
string

setContentDispositionHeader()

Sets the "Content-Disposition" header in the given MessageInterface if a name and/or filename are given

protected setContentDispositionHeader(MessageInterface $message, string|null $fieldname, string|null $filename) : MessageInterface

If the header was already set on the message, this one will be used unmodified.

Parameters
$message : MessageInterface
$fieldname : string|null
$filename : string|null
Return values
MessageInterface

writeBody()

Writes the content of the given StreamInterface to the multipart stream

protected writeBody(StreamInterface $body) : void
Parameters
$body : StreamInterface

writeHeaders()

Parses and writes the headers from the given message to the multipart stream

protected writeHeaders(array<string, string|array<string|int, string>> $headers) : void
Parameters
$headers : array<string, string|array<string|int, string>>

        
On this page

Search results