Stream
in package
implements
StreamInterface
PHP stream implementation
Table of Contents
Interfaces
- StreamInterface
- OO interface to PHP streams
Constants
- IS_LOCAL = 'is_local'
- IS_READABLE = 'is_readable'
- IS_WRITABLE = 'is_writable'
- SEEKABLE = 'seekable'
- STREAM_TYPE = 'stream_type'
- WRAPPER_TYPE = 'wrapper_type'
Properties
- $cache : array<string|int, mixed>
- $customData : array<string|int, mixed>
- $readWriteHash : array<string|int, mixed>
- $size : int
- $stream : resource
Methods
- __construct() : mixed
- __destruct() : mixed
- Closes the stream when the helper is destructed
- __toString() : string
- Convert the stream to a string if the stream is readable and the stream is seekable.
- close() : mixed
- Close the underlying stream
- detachStream() : self
- Detach the current stream resource
- feof() : bool
- Alias of isConsumed
- ftell() : int|bool
- Returns the current position of the file read/write pointer
- getCustomData() : null|mixed
- Get custom data from the stream
- getHash() : bool|string
- Calculate a hash of a Stream
- getMetaData() : array<string|int, mixed>|mixed|null
- Get stream metadata
- getSize() : int|bool
- Get the size of the stream if able
- getStream() : resource
- Get the stream resource
- getStreamType() : string
- Get a label describing the underlying implementation of the stream
- getUri() : string
- Get the URI/filename associated with this stream
- getWrapper() : string
- Get the stream wrapper type
- getWrapperData() : array<string|int, mixed>
- Wrapper specific data attached to this stream.
- isConsumed() : bool
- Check if the stream has been consumed
- isLocal() : bool
- Check if the stream is a local stream vs a remote stream
- isReadable() : bool
- Check if the stream is readable
- isRepeatable() : bool
- Check if the stream is repeatable
- isSeekable() : bool
- Check if the string is repeatable
- isWritable() : bool
- Check if the stream is writable
- read() : string|bool
- Read data from the stream
- readLine() : string|bool
- Read a line from the stream up to the maximum allowed buffer length
- rewind() : bool
- Rewind to the beginning of the stream
- seek() : bool
- Seek to a position in the stream
- setCustomData() : self
- Set custom data on the stream
- setSize() : self
- Specify the size of the stream in bytes
- setStream() : self
- Set the stream that is wrapped by the object
- write() : int|bool
- Write data to the stream
- rebuildCache() : mixed
- Reprocess stream metadata
Constants
IS_LOCAL
public
mixed
IS_LOCAL
= 'is_local'
IS_READABLE
public
mixed
IS_READABLE
= 'is_readable'
IS_WRITABLE
public
mixed
IS_WRITABLE
= 'is_writable'
SEEKABLE
public
mixed
SEEKABLE
= 'seekable'
STREAM_TYPE
public
mixed
STREAM_TYPE
= 'stream_type'
WRAPPER_TYPE
public
mixed
WRAPPER_TYPE
= 'wrapper_type'
Properties
$cache
protected
array<string|int, mixed>
$cache
= array()
Stream cached data
$customData
protected
array<string|int, mixed>
$customData
= array()
Custom stream data
$readWriteHash
protected
static array<string|int, mixed>
$readWriteHash
= array('read' => array('r' => true, 'w+' => true, 'r+' => true, 'x+' => true, 'c+' => true, 'rb' => true, 'w+b' => true, 'r+b' => true, 'x+b' => true, 'c+b' => true, 'rt' => true, 'w+t' => true, 'r+t' => true, 'x+t' => true, 'c+t' => true, 'a+' => true), 'write' => array('w' => true, 'w+' => true, 'rw' => true, 'r+' => true, 'x+' => true, 'c+' => true, 'wb' => true, 'w+b' => true, 'r+b' => true, 'x+b' => true, 'c+b' => true, 'w+t' => true, 'r+t' => true, 'x+t' => true, 'c+t' => true, 'a' => true, 'a+' => true))
Hash table of readable and writeable stream types for fast lookups
$size
protected
int
$size
Size of the stream contents in bytes
$stream
protected
resource
$stream
Stream resource
Methods
__construct()
public
__construct(resource $stream[, int $size = null ]) : mixed
Parameters
- $stream : resource
-
Stream resource to wrap
- $size : int = null
-
Size of the stream in bytes. Only pass if the size cannot be obtained from the stream.
Tags
__destruct()
Closes the stream when the helper is destructed
public
__destruct() : mixed
__toString()
Convert the stream to a string if the stream is readable and the stream is seekable.
public
__toString() : string
Return values
stringclose()
Close the underlying stream
public
close() : mixed
detachStream()
Detach the current stream resource
public
detachStream() : self
Return values
selffeof()
Alias of isConsumed
public
feof() : bool
Return values
boolftell()
Returns the current position of the file read/write pointer
public
ftell() : int|bool
Return values
int|bool —Returns the position of the file pointer or false on error
getCustomData()
Get custom data from the stream
public
getCustomData(mixed $key) : null|mixed
Parameters
- $key : mixed
-
Key to retrieve
Return values
null|mixedgetHash()
Calculate a hash of a Stream
public
static getHash(StreamInterface $stream, string $algo[, bool $rawOutput = false ]) : bool|string
Parameters
- $stream : StreamInterface
-
Stream to calculate the hash for
- $algo : string
-
Hash algorithm (e.g. md5, crc32, etc)
- $rawOutput : bool = false
-
Whether or not to use raw output
Return values
bool|string —Returns false on failure or a hash string on success
getMetaData()
Get stream metadata
public
getMetaData([mixed $key = null ]) : array<string|int, mixed>|mixed|null
Parameters
- $key : mixed = null
-
Specific metadata to retrieve
Return values
array<string|int, mixed>|mixed|nullgetSize()
Get the size of the stream if able
public
getSize() : int|bool
Return values
int|boolgetStream()
Get the stream resource
public
getStream() : resource
Return values
resourcegetStreamType()
Get a label describing the underlying implementation of the stream
public
getStreamType() : string
Return values
stringgetUri()
Get the URI/filename associated with this stream
public
getUri() : string
Return values
stringgetWrapper()
Get the stream wrapper type
public
getWrapper() : string
Return values
stringgetWrapperData()
Wrapper specific data attached to this stream.
public
getWrapperData() : array<string|int, mixed>
Return values
array<string|int, mixed>isConsumed()
Check if the stream has been consumed
public
isConsumed() : bool
Return values
boolisLocal()
Check if the stream is a local stream vs a remote stream
public
isLocal() : bool
Return values
boolisReadable()
Check if the stream is readable
public
isReadable() : bool
Return values
boolisRepeatable()
Check if the stream is repeatable
public
isRepeatable() : bool
Return values
boolisSeekable()
Check if the string is repeatable
public
isSeekable() : bool
Return values
boolisWritable()
Check if the stream is writable
public
isWritable() : bool
Return values
boolread()
Read data from the stream
public
read(mixed $length) : string|bool
Parameters
- $length : mixed
-
Up to length number of bytes read.
Return values
string|bool —Returns the data read from the stream or FALSE on failure or EOF
readLine()
Read a line from the stream up to the maximum allowed buffer length
public
readLine([mixed $maxLength = null ]) : string|bool
Parameters
- $maxLength : mixed = null
-
Maximum buffer length
Return values
string|boolrewind()
Rewind to the beginning of the stream
public
rewind() : bool
Return values
bool —Returns true on success or false on failure
seek()
Seek to a position in the stream
public
seek(mixed $offset[, mixed $whence = SEEK_SET ]) : bool
Parameters
- $offset : mixed
-
Stream offset
- $whence : mixed = SEEK_SET
-
Where the offset is applied
Return values
bool —Returns TRUE on success or FALSE on failure
setCustomData()
Set custom data on the stream
public
setCustomData(mixed $key, mixed $value) : self
Parameters
- $key : mixed
-
Key to set
- $value : mixed
-
Value to set
Return values
selfsetSize()
Specify the size of the stream in bytes
public
setSize(mixed $size) : self
Parameters
- $size : mixed
-
Size of the stream contents in bytes
Return values
selfsetStream()
Set the stream that is wrapped by the object
public
setStream(mixed $stream[, mixed $size = null ]) : self
Parameters
- $stream : mixed
-
Stream resource to wrap
- $size : mixed = null
-
Size of the stream in bytes. Only pass if the size cannot be obtained from the stream.
Return values
selfwrite()
Write data to the stream
public
write(mixed $string) : int|bool
Parameters
- $string : mixed
-
The string that is to be written.
Return values
int|bool —Returns the number of bytes written to the stream on success or FALSE on failure.
rebuildCache()
Reprocess stream metadata
protected
rebuildCache() : mixed