Stream
extends AbstractStream
in package
implements
StreamInterface
Simple Stream Implementation.
Table of Contents
Interfaces
- StreamInterface
- Describes Stream interface.
Constants
- FSTAT_MODE_FIFO = 010000
- FSTAT_MODE_FILE = 0100000
- META_MODE_READABLE = ["r", "r+", "w+", "a+", "x+", "c+", "rw", "rw+", "rb", "w+b", "a+b"]
- META_MODE_WRITABLE = ["r+", "w", "w+", "a", "a+", "x", "x+", "c", "c+", "rw+", "w+b", "a+b"]
Properties
- $is_file : bool
- $is_pipe : bool
- $is_readable : bool
- $is_seekable : bool
- $is_writable : bool
- $resource : resource|null
- $uri : string
Methods
- __construct() : mixed
- __destruct() : mixed
- __toString() : string
- Reads all data from the stream into a string, from the beginning to end.
- close() : void
- Closes the stream and any underlying resources.
- detach() : resource|null
- Separates any underlying resources from the stream.
- eof() : bool
- Returns true if the stream is at the end of the stream.
- getContents() : string
- Returns the remaining contents in a string.
- getMetadata() : array<string|int, mixed>|mixed|null
- Get stream metadata as an associative array or retrieve a specific key.
- getResource() : object|null
- Retrieve resource of the stream.
- getSize() : int|null
- Get the size of the stream if known.
- getUri() : string
- Retrieve uri of the stream metadata.
- isReadable() : bool
- Returns whether or not the stream is readable.
- isSeekable() : bool
- Returns whether or not the stream is seekable.
- isWritable() : bool
- Returns whether or not the stream is writable.
- read() : string
- Read data from the stream.
- rewind() : self
- Seek to the beginning of the stream.
- seek() : self
- Seek to a position in the stream.
- tell() : int
- Returns the current position of the file read/write pointer.
- withFile() : static
- Return an instance with file stream.
- withMemory() : static
- Return an instance with memory stream.
- withPipe() : static
- Return an instance with pipe stream.
- withTemp() : static
- Return an instance with temporary stream.
- write() : int
- Write data to the stream.
- attach() : static
- Attach new resource to this object.
Constants
FSTAT_MODE_FIFO
private
mixed
FSTAT_MODE_FIFO
= 010000
FSTAT_MODE_FILE
private
mixed
FSTAT_MODE_FILE
= 0100000
META_MODE_READABLE
private
mixed
META_MODE_READABLE
= ["r", "r+", "w+", "a+", "x+", "c+", "rw", "rw+", "rb", "w+b", "a+b"]
META_MODE_WRITABLE
private
mixed
META_MODE_WRITABLE
= ["r+", "w", "w+", "a", "a+", "x", "x+", "c", "c+", "rw+", "w+b", "a+b"]
Properties
$is_file
protected
bool
$is_file
= false
$is_pipe
protected
bool
$is_pipe
= false
$is_readable
protected
bool
$is_readable
= false
$is_seekable
protected
bool
$is_seekable
= false
$is_writable
protected
bool
$is_writable
= false
$resource
protected
resource|null
$resource
= null
$uri
protected
string
$uri
= ""
Methods
__construct()
public
__construct([array<string, mixed> $Config = [] ]) : mixed
Parameters
- $Config : array<string, mixed> = []
-
The configuration.
__destruct()
public
__destruct() : mixed
__toString()
Reads all data from the stream into a string, from the beginning to end.
public
__toString() : string
This method MUST attempt to seek to the beginning of the stream before reading data and read the stream until the end is reached.
Warning: This could attempt to load a large amount of data into memory.
This method MUST NOT raise an exception in order to conform with PHP's string casting operations.
Tags
Return values
stringclose()
Closes the stream and any underlying resources.
public
close() : void
detach()
Separates any underlying resources from the stream.
public
detach() : resource|null
After the stream has been detached, the stream is in an unusable state.
Return values
resource|null —Underlying PHP stream, if any
eof()
Returns true if the stream is at the end of the stream.
public
eof() : bool
Return values
boolgetContents()
Returns the remaining contents in a string.
public
getContents() : string
Tags
Return values
stringgetMetadata()
Get stream metadata as an associative array or retrieve a specific key.
public
getMetadata([string $key = null ]) : array<string|int, mixed>|mixed|null
The keys returned are identical to the keys returned from PHP's stream_get_meta_data() function.
Parameters
- $key : string = null
-
Specific metadata to retrieve.
Tags
Return values
array<string|int, mixed>|mixed|null —Returns an associative array if no key is provided. Returns a specific key value if a key is provided and the value is found, or null if the key is not found.
getResource()
Retrieve resource of the stream.
public
getResource() : object|null
Return values
object|nullgetSize()
Get the size of the stream if known.
public
getSize() : int|null
Return values
int|null —Returns the size in bytes if known, or null if unknown.
getUri()
Retrieve uri of the stream metadata.
public
getUri() : string
Return values
stringisReadable()
Returns whether or not the stream is readable.
public
isReadable() : bool
Return values
boolisSeekable()
Returns whether or not the stream is seekable.
public
isSeekable() : bool
Return values
boolisWritable()
Returns whether or not the stream is writable.
public
isWritable() : bool
Return values
boolread()
Read data from the stream.
public
read(int $length) : string
Parameters
- $length : int
-
Read up to $length bytes from the object and return them. Fewer than $length bytes may be returned if underlying stream call returns fewer bytes.
Tags
Return values
string —Returns the data read from the stream, or an empty string if no bytes are available.
rewind()
Seek to the beginning of the stream.
public
rewind() : self
If the stream is not seekable, this method will raise an exception; otherwise, it will perform a seek(0).
Tags
Return values
selfseek()
Seek to a position in the stream.
public
seek(int $offset[, int $whence = SEEK_SET ]) : self
Parameters
- $offset : int
-
Stream offset
- $whence : int = SEEK_SET
-
Specifies how the cursor position will be calculated based on the seek offset. Valid values are identical to the built-in PHP $whence values for
fseek()
. SEEK_SET: Set position equal to offset bytes SEEK_CUR: Set position to current location plus offset SEEK_END: Set position to end-of-stream plus offset.
Tags
Return values
selftell()
Returns the current position of the file read/write pointer.
public
tell() : int
Tags
Return values
int —Position of the file pointer
withFile()
Return an instance with file stream.
public
withFile(string $Filename[, string $Mode = "w+" ]) : static
Parameters
- $Filename : string
-
The filename.
- $Mode : string = "w+"
-
The mode parameter specifies the type of access you require to the stream.
Tags
Return values
staticwithMemory()
Return an instance with memory stream.
public
withMemory([string $Mode = "w+" ]) : static
Parameters
- $Mode : string = "w+"
-
The mode parameter specifies the type of access you require to the stream.
Tags
Return values
staticwithPipe()
Return an instance with pipe stream.
public
withPipe(string $Command[, string $Mode = "w+" ]) : static
Parameters
- $Command : string
-
The command.
- $Mode : string = "w+"
-
The mode. Either 'r' for reading, or 'w' for writing.
Tags
Return values
staticwithTemp()
Return an instance with temporary stream.
public
withTemp([string $Mode = "w+" ]) : static
Parameters
- $Mode : string = "w+"
-
The mode parameter specifies the type of access you require to the stream.
Tags
Return values
staticwrite()
Write data to the stream.
public
write(string $string) : int
Parameters
- $string : string
-
The string that is to be written.
Tags
Return values
int —Returns the number of bytes written to the stream.
attach()
Attach new resource to this object.
protected
attach(mixed $Resource) : static
Parameters
- $Resource : mixed
-
Resource handle.