IWrapper
extends
File, Stream
in
Interface \Hoa\Stream\Wrapper\IWrapper.
Interface for stream wrapper class.
Tags
Table of Contents
Methods
- __construct() : mixed
- Constructs a new stream wrapper.
- dir_closedir() : bool
- Close directory handle.
- dir_opendir() : bool
- Open directory handle.
- dir_readdir() : mixed
- Read entry from directory handle.
- dir_rewinddir() : bool
- Rewind directory handle.
- mkdir() : bool
- Create a directory.
- rename() : bool
- Rename a file or directory.
- rmdir() : bool
- Remove a directory.
- stream_cast() : resource
- Retrieve the underlaying resource.
- stream_close() : void
- Close a resource.
- stream_eof() : bool
- Tests for end-of-file on a file pointer.
- stream_flush() : bool
- Flush the output.
- stream_lock() : bool
- Advisory file locking.
- stream_metadata() : bool
- Change stream options.
- stream_open() : bool
- Open file or URL.
- stream_read() : string
- Read from stream.
- stream_seek() : bool
- Seek to specific location in a stream.
- stream_set_option() : bool
- Change stream options.
- stream_stat() : array<string|int, mixed>
- Retrieve information about a file resource.
- stream_tell() : int
- Retrieve the current position of a stream.
- stream_truncate() : bool
- Truncate a stream to a given length.
- stream_write() : int
- Write to stream.
- unlink() : bool
- Delete a file.
- url_stat() : array<string|int, mixed>
- Retrieve information about a file.
Methods
__construct()
Constructs a new stream wrapper.
public
__construct() : mixed
Called when opening the stream wrapper, right before self::stream_open().
dir_closedir()
Close directory handle.
public
dir_closedir() : bool
This method is called in to closedir(). Any resources which were locked, or allocated, during opening and use of the directory stream should be released.
Return values
booldir_opendir()
Open directory handle.
public
dir_opendir(string $path, int $options) : bool
This method is called in response to opendir().
Parameters
- $path : string
-
Specifies the URL that was passed to opendir().
- $options : int
-
Whether or not to enforce safe_mode (0x04).
Return values
booldir_readdir()
Read entry from directory handle.
public
dir_readdir() : mixed
This method is called in response to readdir().
dir_rewinddir()
Rewind directory handle.
public
dir_rewinddir() : bool
This method is called in response to rewinddir(). Should reset the output generated by self::dir_readdir, i.e. the next call to self::dir_readdir should return the first entry in the location returned by self::dir_opendir.
Return values
boolmkdir()
Create a directory.
public
mkdir(string $path, int $mode, int $options) : bool
This method is called in response to mkdir().
Parameters
- $path : string
-
Directory which should be created.
- $mode : int
-
The value passed to mkdir().
- $options : int
-
A bitwise mask of values.
Return values
boolrename()
Rename a file or directory.
public
rename(string $from, string $to) : bool
This method is called in response to rename(). Should attempt to rename $from to $to.
Parameters
- $from : string
-
The URL to current file.
- $to : string
-
The URL which $from should be renamed to.
Return values
boolrmdir()
Remove a directory.
public
rmdir(string $path, int $options) : bool
This method is called in response to rmdir().
Parameters
- $path : string
-
The directory URL which should be removed.
- $options : int
-
A bitwise mask of values.
Return values
boolstream_cast()
Retrieve the underlaying resource.
public
stream_cast(int $castAs) : resource
Parameters
- $castAs : int
-
Can be STREAM_CAST_FOR_SELECT when stream_select() is calling stream_cast() or STREAM_CAST_AS_STREAM when stream_cast() is called for other uses.
Return values
resourcestream_close()
Close a resource.
public
stream_close() : void
This method is called in response to fclose(). All resources that were locked, or allocated, by the wrapper should be released.
stream_eof()
Tests for end-of-file on a file pointer.
public
stream_eof() : bool
This method is called in response to feof().
Return values
boolstream_flush()
Flush the output.
public
stream_flush() : bool
This method is called in response to fflush(). If we have cached data in our stream but not yet stored it into the underlying storage, we should do so now.
Return values
boolstream_lock()
Advisory file locking.
public
stream_lock(int $operation) : bool
This method is called in response to flock(), when file_put_contents() (when flags contains LOCK_EX), stream_set_blocking() and when closing the stream (LOCK_UN).
Parameters
- $operation : int
-
Operation is one the following:
- LOCK_SH to acquire a shared lock (reader) ;
- LOCK_EX to acquire an exclusive lock (writer) ;
- LOCK_UN to release a lock (shared or exclusive) ;
- LOCK_NB if we don't want flock() to block while locking (not supported on Windows).
Return values
boolstream_metadata()
Change stream options.
public
stream_metadata(string $path, int $option, mixed $value) : bool
This method is called to set metadata on the stream. It is called when one of the following functions is called one a stream URL: touch, chmod, chown or chgrp.
Parameters
- $path : string
-
The file path or URL to set metadata.
- $option : int
-
One of the following:
- STREAM_META_TOUCH,
- STREAM_META_OWNER_NAME,
- STREAM_META_OWNER,
- STREAM_META_GROUP_NAME,
- STREAM_META_GROUP,
- STREAM_META_ACCESS.
- $value : mixed
-
An array or a scalar depending of the option.
Return values
boolstream_open()
Open file or URL.
public
stream_open(string $path, string $mode, int $options, string &$openedPath) : bool
This method is called immediately after the wrapper is initialized (f.e. by fopen() and file_get_contents()).
Parameters
- $path : string
-
Specifies the URL that was passed to the original function.
- $mode : string
-
The mode used to open the file, as detailed for fopen().
- $options : int
-
Holds additional flags set by the streams API. It can hold one or more of the following values OR'd together:
- STREAM_USE_PATH, if path is relative, search for the resource using the include_path;
- STREAM_REPORT_ERRORS, if this is set, you are responsible for raising errors using trigger_error during opening the stream. If this is not set, you should not raise any errors.
- $openedPath : string
-
If the $path is opened successfully, and STREAM_USE_PATH is set in $options, $openedPath should be set to the full path of the file/resource that was actually opened.
Return values
boolstream_read()
Read from stream.
public
stream_read(int $count) : string
This method is called in response to fread() and fgets().
Parameters
- $count : int
-
How many bytes of data from the current position should be returned.
Return values
stringstream_seek()
Seek to specific location in a stream.
public
stream_seek(int $offset[, int $whence = SEEK_SET ]) : bool
This method is called in response to fseek(). The read/write position of the stream should be updated according to the $offset and $whence.
Parameters
- $offset : int
-
The stream offset to seek to.
- $whence : int = SEEK_SET
-
Possible values:
- SEEK_SET to set position equal to $offset bytes ;
- SEEK_CUR to set position to current location plus $offsete ;
- SEEK_END to set position to end-of-file plus $offset.
Return values
boolstream_set_option()
Change stream options.
public
stream_set_option(int $option, int $arg1, int $arg2) : bool
This method is called to set options on the stream.
Parameters
- $option : int
-
One of:
- STREAM_OPTION_BLOCKING, the method was called in response to stream_set_blocking() ;
- STREAM_OPTION_READ_TIMEOUT, the method was called in response to stream_set_timeout() ;
- STREAM_OPTION_WRITE_BUFFER, the method was called in response to stream_set_write_buffer().
- $arg1 : int
-
If $option is:
- STREAM_OPTION_BLOCKING: requested blocking mode (1 meaning block, 0 not blocking) ;
- STREAM_OPTION_READ_TIMEOUT: the timeout in seconds ;
- STREAM_OPTION_WRITE_BUFFER: buffer mode (STREAM_BUFFER_NONE or STREAM_BUFFER_FULL).
- $arg2 : int
-
If $option is:
- STREAM_OPTION_BLOCKING: this option is not set ;
- STREAM_OPTION_READ_TIMEOUT: the timeout in microseconds ;
- STREAM_OPTION_WRITE_BUFFER: the requested buffer size.
Return values
boolstream_stat()
Retrieve information about a file resource.
public
stream_stat() : array<string|int, mixed>
This method is called in response to fstat().
Return values
array<string|int, mixed>stream_tell()
Retrieve the current position of a stream.
public
stream_tell() : int
This method is called in response to ftell().
Return values
intstream_truncate()
Truncate a stream to a given length.
public
stream_truncate(int $size) : bool
Parameters
- $size : int
-
Size.
Return values
boolstream_write()
Write to stream.
public
stream_write(string $data) : int
This method is called in response to fwrite().
Parameters
- $data : string
-
Should be stored into the underlying stream.
Return values
intunlink()
Delete a file.
public
unlink(string $path) : bool
This method is called in response to unlink().
Parameters
- $path : string
-
The file URL which should be deleted.
Return values
boolurl_stat()
Retrieve information about a file.
public
url_stat(string $path, int $flags) : array<string|int, mixed>
This method is called in response to all stat() related functions.
Parameters
- $path : string
-
The file URL which should be retrieve information about.
- $flags : int
-
Holds additional flags set by the streams API. It can hold one or more of the following values OR'd together. STREAM_URL_STAT_LINK: for resource with the ability to link to other resource (such as an HTTP location: forward, or a filesystem symlink). This flag specified that only information about the link itself should be returned, not the resource pointed to by the link. This flag is set in response to calls to lstat(), is_link(), or filetype(). STREAM_URL_STAT_QUIET: if this flag is set, our wrapper should not raise any errors. If this flag is not set, we are responsible for reporting errors using the trigger_error() function during stating of the path.