StreamUtil
in package
Table of Contents
Methods
- copyToStream() : int
- Copies a stream to another stream, starting from the current position of the source stream, reading to the end or until the given maxlength is hit.
- getContents() : string|null
- Reads the content from a stream and make sure we rewind
- modeAllowsRead() : bool
- Checks whether the given mode allows reading
- modeAllowsReadOnly() : bool
- Checks whether the given mode allows only reading
- modeAllowsReadWrite() : bool
- Checks whether the given mode allows reading and writing
- modeAllowsWrite() : bool
- Checks whether the given mode allows writing
- modeAllowsWriteOnly() : bool
- Checks whether the given mode allows only writing
- tryFopen() : resource
- Safely open a PHP resource, throws instead of raising warnings and errors
- tryGetContents() : string
- Safely get the contents of a stream resource, throws instead of raising warnings and errors
- validateMode() : string
- Checks if the given mode is valid for fopen().
Methods
copyToStream()
Copies a stream to another stream, starting from the current position of the source stream, reading to the end or until the given maxlength is hit.
public
static copyToStream(StreamInterface $source, StreamInterface $destination[, int|null $maxLength = null ]) : int
Throws if the source is not readable or the destination not writable.
Parameters
- $source : StreamInterface
- $destination : StreamInterface
- $maxLength : int|null = null
Tags
Return values
intgetContents()
Reads the content from a stream and make sure we rewind
public
static getContents(StreamInterface $stream) : string|null
Returns the stream content as a string, null if an error occurs, e.g. the StreamInterface throws.
Parameters
- $stream : StreamInterface
Return values
string|nullmodeAllowsRead()
Checks whether the given mode allows reading
public
static modeAllowsRead(string $mode) : bool
Parameters
- $mode : string
Return values
boolmodeAllowsReadOnly()
Checks whether the given mode allows only reading
public
static modeAllowsReadOnly(string $mode) : bool
Parameters
- $mode : string
Return values
boolmodeAllowsReadWrite()
Checks whether the given mode allows reading and writing
public
static modeAllowsReadWrite(string $mode) : bool
Parameters
- $mode : string
Return values
boolmodeAllowsWrite()
Checks whether the given mode allows writing
public
static modeAllowsWrite(string $mode) : bool
Parameters
- $mode : string
Return values
boolmodeAllowsWriteOnly()
Checks whether the given mode allows only writing
public
static modeAllowsWriteOnly(string $mode) : bool
Parameters
- $mode : string
Return values
booltryFopen()
Safely open a PHP resource, throws instead of raising warnings and errors
public
static tryFopen(string $filename, string $mode[, resource|null $context = null ]) : resource
Parameters
- $filename : string
- $mode : string
- $context : resource|null = null
Tags
Return values
resourcetryGetContents()
Safely get the contents of a stream resource, throws instead of raising warnings and errors
public
static tryGetContents(resource $stream[, int|null $length = null ][, int $offset = -1 ]) : string
Parameters
- $stream : resource
- $length : int|null = null
- $offset : int = -1
Tags
Return values
stringvalidateMode()
Checks if the given mode is valid for fopen().
public
static validateMode(string $mode) : string
Returns the first 15 characters, throws if that string doesn't match the pattern.
Note: we don't care where the modifier flags are in the string, what matters is that the first character is one of "acrwx" and the rest may contain one of "bet+" from 2nd position onwards, so "aaaaaaaaaaaaaa+b" is valid.
The documentation of fopen() says that the text-mode translation flag (b/t) should be added as last character, however, it doesn't matter as PHP internally only reads the mode from the first character and 15 characters total. and does a strchr() on it for the flags, so technically "rb+" is equivalent to "r+b" and "rrrbbbb++". Also, some libraries allow a mode "rw" which is wrong and just falls back to "r" - see above. (looking at you, Guzzle)
gzopen() adds a bunch of other flags that are hardly documented, so we'll ignore these until we get a full list.
Parameters
- $mode : string