MultipartStreamBuilder
in package
Use PSR-7 MessageInterface to build multipart messages
Tags
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
$boundary
protected
string
$boundary
$messages
protected
array<string|int, MessageInterface>
$messages
$multipartStream
protected
StreamInterface
$multipartStream
$streamFactory
protected
StreamFactoryInterface
$streamFactory
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
stringaddMessage()
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
staticaddStream()
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
Return values
staticaddString()
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
Return values
staticbuild()
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|MessageInterfacegetBoundary()
Returns the current boundary string
public
getBoundary() : string
Return values
stringreset()
Clears the MessageInterface array
public
reset() : static
Return values
staticsetBoundary()
Sets a boundary string
public
setBoundary(string $boundary) : static
permitted characters: DIGIT ALPHA '()+_,-./:=?
Parameters
- $boundary : string
Tags
Return values
staticgetRandomBoundary()
Generates a random boundary string
protected
getRandomBoundary() : string
Return values
stringsetContentDispositionHeader()
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
MessageInterfacewriteBody()
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>>