Body
in package
implements
StreamInterface
HTTP body class
Tags
Table of Contents
Interfaces
- StreamInterface
Constants
Properties
- $encoding : string|null
- Encoding
- $isEncoded : bool
- Is encoded flag
- $isFile : bool
- Is file flag
- $split : int|bool|null
- Chunk split
- $stream : resource|null
- Underlying content stream. All content - string-set or file-backed - lives here.
Methods
- __clone() : void
- Deep-duplicate the underlying stream resource so a clone never shares a read/write position with the instance it was cloned from
- __construct() : mixed
- Constructor
- __toString() : string
- Render the body
- close() : void
- Close the underlying stream
- detach() : mixed
- Detach the underlying stream resource, leaving the Body empty
- eof() : bool
- Determine if the stream is at end-of-file
- getContent() : string
- Get the body content as a string
- getContents() : string
- Get the remaining raw stream contents, per PSR-7 - bypasses render()'s encoding/split transforms, unlike __toString()
- getEncoding() : string|null
- Get the encoding
- getMetadata() : mixed
- Get stream metadata
- getSize() : int|null
- Get the content size in bytes, without reading file-backed content into memory to compute it. Per PSR-7, returns null if the stream size is not statable (e.g. php://output).
- getSplit() : int|bool|null
- Get the split
- getStream() : mixed
- Get the raw underlying stream resource, for a consumer that wants to copy bytes directly (e.g. to the network) without materializing the whole content as a PHP string.
- hasContent() : bool
- Has body content
- hasEncoding() : bool
- Has encoding
- hasSplit() : bool
- Has split
- isBase64Encoding() : bool
- Is encoding base64
- isEncoded() : bool
- Is encoded
- isFile() : bool
- Is file
- isQuotedEncoding() : bool
- Is encoding quoted-printable
- isRawUrlEncoding() : bool
- Is encoding raw URL
- isReadable() : bool
- Determine if the stream is readable
- isSeekable() : bool
- Determine if the stream is seekable
- isUrlEncoding() : bool
- Is encoding URL
- isWritable() : bool
- Determine if the stream is writable
- read() : string
- Read up to $length bytes from the stream
- render() : string
- Render the body
- rewind() : void
- Seek to the beginning of the stream
- seek() : void
- Seek to a position in the stream
- setAsEncoded() : Body
- Set as encoded
- setAsFile() : Body
- Set as file
- setContent() : Body
- Set the body content from a string
- setContentFromFile() : Body
- Set the body content from a file, without buffering it into memory
- setContentFromStream() : Body
- Set the body content directly from an existing stream resource
- setEncoding() : Body
- Set the encoding
- setSplit() : Body
- Set the split
- tell() : int
- Get the current position of the stream read/write pointer
- write() : int
- Write data to the stream
Constants
BASE64
Encoding constants
public
string
BASE64
= 'BASE64'
QUOTED
public
mixed
QUOTED
= 'QUOTED'
RAW_URL
public
mixed
RAW_URL
= 'RAW_URL'
URL
public
mixed
URL
= 'URL'
Properties
$encoding
Encoding
protected
string|null
$encoding
= null
$isEncoded
Is encoded flag
protected
bool
$isEncoded
= false
$isFile
Is file flag
protected
bool
$isFile
= false
$split
Chunk split
protected
int|bool|null
$split
= null
$stream
Underlying content stream. All content - string-set or file-backed - lives here.
protected
resource|null
$stream
= null
Methods
__clone()
Deep-duplicate the underlying stream resource so a clone never shares a read/write position with the instance it was cloned from
public
__clone() : void
__construct()
Constructor
public
__construct([string|null $content = null ][, string|null $encoding = null ][, int|bool|null $split = null ]) : mixed
Instantiate the body object
Parameters
- $content : string|null = null
- $encoding : string|null = null
- $split : int|bool|null = null
__toString()
Render the body
public
__toString() : string
Return values
stringclose()
Close the underlying stream
public
close() : void
detach()
Detach the underlying stream resource, leaving the Body empty
public
detach() : mixed
eof()
Determine if the stream is at end-of-file
public
eof() : bool
Return values
boolgetContent()
Get the body content as a string
public
getContent() : string
Reads the entire underlying stream and restores its read position afterward, so repeated calls return the same content.
Return values
stringgetContents()
Get the remaining raw stream contents, per PSR-7 - bypasses render()'s encoding/split transforms, unlike __toString()
public
getContents() : string
Tags
Return values
stringgetEncoding()
Get the encoding
public
getEncoding() : string|null
Return values
string|nullgetMetadata()
Get stream metadata
public
getMetadata([string|null $key = null ]) : mixed
Parameters
- $key : string|null = null
getSize()
Get the content size in bytes, without reading file-backed content into memory to compute it. Per PSR-7, returns null if the stream size is not statable (e.g. php://output).
public
getSize() : int|null
Return values
int|nullgetSplit()
Get the split
public
getSplit() : int|bool|null
Return values
int|bool|nullgetStream()
Get the raw underlying stream resource, for a consumer that wants to copy bytes directly (e.g. to the network) without materializing the whole content as a PHP string.
public
getStream() : mixed
hasContent()
Has body content
public
hasContent() : bool
Return values
boolhasEncoding()
Has encoding
public
hasEncoding() : bool
Return values
boolhasSplit()
Has split
public
hasSplit() : bool
Return values
boolisBase64Encoding()
Is encoding base64
public
isBase64Encoding() : bool
Return values
boolisEncoded()
Is encoded
public
isEncoded() : bool
Return values
boolisFile()
Is file
public
isFile() : bool
Return values
boolisQuotedEncoding()
Is encoding quoted-printable
public
isQuotedEncoding() : bool
Return values
boolisRawUrlEncoding()
Is encoding raw URL
public
isRawUrlEncoding() : bool
Return values
boolisReadable()
Determine if the stream is readable
public
isReadable() : bool
Return values
boolisSeekable()
Determine if the stream is seekable
public
isSeekable() : bool
Return values
boolisUrlEncoding()
Is encoding URL
public
isUrlEncoding() : bool
Return values
boolisWritable()
Determine if the stream is writable
public
isWritable() : bool
Return values
boolread()
Read up to $length bytes from the stream
public
read(int $length) : string
Parameters
- $length : int
Tags
Return values
stringrender()
Render the body
public
render() : string
Return values
stringrewind()
Seek to the beginning of the stream
public
rewind() : void
Tags
seek()
Seek to a position in the stream
public
seek(int $offset[, int $whence = SEEK_SET ]) : void
Parameters
- $offset : int
- $whence : int = SEEK_SET
Tags
setAsEncoded()
Set as encoded
public
setAsEncoded(bool $isEncoded) : Body
Parameters
- $isEncoded : bool
Return values
BodysetAsFile()
Set as file
public
setAsFile(bool $isFile) : Body
Parameters
- $isFile : bool
Return values
BodysetContent()
Set the body content from a string
public
setContent(string $content) : Body
Parameters
- $content : string
Return values
BodysetContentFromFile()
Set the body content from a file, without buffering it into memory
public
setContentFromFile(string $file[, string|null $encoding = null ][, int|bool|null $split = null ]) : Body
Parameters
- $file : string
- $encoding : string|null = null
- $split : int|bool|null = null
Tags
Return values
BodysetContentFromStream()
Set the body content directly from an existing stream resource
public
setContentFromStream(mixed $stream) : Body
If the given stream is known to be backed by a real file (e.g. a handle returned from fopen() on a local file), chain ->setAsFile(true) afterward to flag it as such, since this method has no reliable way to detect that on its own.
Parameters
- $stream : mixed
Return values
BodysetEncoding()
Set the encoding
public
setEncoding(string $encoding) : Body
Parameters
- $encoding : string
Return values
BodysetSplit()
Set the split
public
setSplit(int|bool $split) : Body
Parameters
- $split : int|bool
Return values
Bodytell()
Get the current position of the stream read/write pointer
public
tell() : int
Tags
Return values
intwrite()
Write data to the stream
public
write(string $string) : int
Parameters
- $string : string