PartStream
Implementation of a stream wrapper representing content for a specific MIME part of an email message.
Basically defines character boundaries for a "parent" stream - namely the main stream for a message - where read operations are not permitted beyond the character boundaries of a specific part. The boundaries are parsed from parameters passed as the "path" to stream_open (with fopen, etc...)
Note that only read operations are permitted.
Tags
Table of Contents
- STREAM_WRAPPER_PROTOCOL = 'mmp-mime-message'
- The protocol name used to register the stream with stream_wrapper_register
- $end : int
- $handle : resource
- $id : int
- $registry : PartStreamRegistry
- $start : int
- $position : int
- __construct() : mixed
- Constructs a PartStream.
- stream_close() : mixed
- Decreases the ref count for the underlying resource handle, which allows the PartStreamRegistry to close it once no more references to it exist.
- stream_eof() : bool
- Returns true if the end of the stream has been reached.
- stream_open() : bool
- Called in response to fopen, file_get_contents, etc... with a PartStream::STREAM_WRAPPER_PROTOCOL, e.g., fopen('mmp-mime-message://...');
- stream_read() : string
- Reads up to $count characters from the stream and returns them.
- stream_seek() : bool
- Moves the pointer to the given offset, in accordance to $whence.
- stream_stat() : array<string|int, mixed>
- Returns information about the opened stream, as would be expected by fstat.
- stream_tell() : int
- Returns the current read position.
- parseOpenPath() : mixed
- Extracts the PartStreamRegistry resource id, start, and end positions for the passed path and assigns them to the passed-by-reference parameters $id, $start and $end respectively.
- streamSeekSet() : bool
- Checks if the position is valid and seeks to it by setting $this->position
Constants
STREAM_WRAPPER_PROTOCOL
The protocol name used to register the stream with stream_wrapper_register
public
mixed
STREAM_WRAPPER_PROTOCOL
= 'mmp-mime-message'
Properties
$end
protected
int
$end
$handle
protected
resource
$handle
$id
protected
int
$id
$registry
protected
PartStreamRegistry
$registry
$start
protected
int
$start
$position
private
int
$position
Methods
__construct()
Constructs a PartStream.
public
__construct() : mixed
Return values
mixed —stream_close()
Decreases the ref count for the underlying resource handle, which allows the PartStreamRegistry to close it once no more references to it exist.
public
stream_close() : mixed
Return values
mixed —stream_eof()
Returns true if the end of the stream has been reached.
public
stream_eof() : bool
Return values
bool —stream_open()
Called in response to fopen, file_get_contents, etc... with a PartStream::STREAM_WRAPPER_PROTOCOL, e.g., fopen('mmp-mime-message://...');
public
stream_open(string $path, string $mode, int $options, string &$opened_path) : bool
The \ZBateson\MailMimeParser\Message object ID must be passed as the 'host' part in $path. The start and end boundaries of the part must be passed as query string parameters in the path, for example:
fopen('mmp-mime-message://123456?start=0&end=20');
This would open a file handle to a MIME message with the ID 123456, with a start offset of 0, and an end offset of 20.
TODO: $mode is not validated, although only read operations are implemented in PartStream. $options are not checked for error reporting mode.
Parameters
- $path : string
-
The requested path
- $mode : string
-
The requested open mode
- $options : int
-
Additional streams API flags
- $opened_path : string
-
The full path of the opened resource
Return values
bool —true if the resource was opened successfully
stream_read()
Reads up to $count characters from the stream and returns them.
public
stream_read(int $count) : string
Parameters
- $count : int
Return values
string —stream_seek()
Moves the pointer to the given offset, in accordance to $whence.
public
stream_seek(int $offset[, int $whence = SEEK_SET ]) : bool
Parameters
- $offset : int
- $whence : int = SEEK_SET
-
One of SEEK_SET, SEEK_CUR and SEEK_END.
Return values
bool —stream_stat()
Returns information about the opened stream, as would be expected by fstat.
public
stream_stat() : array<string|int, mixed>
Return values
array<string|int, mixed> —stream_tell()
Returns the current read position.
public
stream_tell() : int
Return values
int —parseOpenPath()
Extracts the PartStreamRegistry resource id, start, and end positions for the passed path and assigns them to the passed-by-reference parameters $id, $start and $end respectively.
private
parseOpenPath(string $path, string &$id, int &$start, int &$end) : mixed
Parameters
- $path : string
- $id : string
- $start : int
- $end : int
Return values
mixed —streamSeekSet()
Checks if the position is valid and seeks to it by setting $this->position
private
streamSeekSet(int $pos) : bool
Parameters
- $pos : int
Return values
bool —true if set