Documentation

vfsStreamWrapper
in package

Stream wrapper to mock file system requests.

Table of Contents

ALL  = 2
file mode: read and write
APPEND  = 'a'
set file pointer to end, append new data
READ  = 'r'
open file for reading
READONLY  = 0
file mode: read only
TRUNCATE  = 'w'
truncate file
WRITE  = 'x'
set file pointer to start, overwrite existing data
WRITE_NEW  = 'c'
set file pointer to start, overwrite existing data; or create file if does not exist
WRITEONLY  = 1
file mode: write only
$content  : mixed
shortcut to file container
$dir  : mixed
shortcut to directory container
$dirIterator  : mixed
shortcut to directory container iterator
$mode  : mixed
file mode: read only, write only, all
$registered  : mixed
switch whether class has already been registered as stream wrapper or not
$root  : mixed
root content
$quota  : mixed
disk space quota
dir_closedir()  : bool
closes directory
dir_opendir()  : bool
opens a directory
dir_readdir()  : string
reads directory contents
dir_rewinddir()  : bool
reset directory iteration
getRoot()  : vfsStreamContainer
returns the root content
mkdir()  : bool
creates a new directory
register()  : mixed
method to register the stream wrapper
rename()  : bool
rename from one path to another
rmdir()  : bool
removes a directory
setQuota()  : mixed
sets quota for disk space
setRoot()  : vfsStreamContainer
sets the root content
stream_cast()  : bool
retrieve the underlaying resource
stream_close()  : mixed
closes the stream
stream_eof()  : bool
checks whether stream is at end of file
stream_flush()  : bool
flushes unstored data into storage
stream_lock()  : bool
set lock status for stream
stream_metadata()  : bool
sets metadata like owner, user or permissions
stream_open()  : bool
open the stream
stream_read()  : string
read the stream up to $count bytes
stream_seek()  : bool
seeks to the given offset
stream_set_option()  : bool
sets options on the stream
stream_stat()  : array<string|int, mixed>
returns status of stream
stream_tell()  : int
returns the current position of the stream
stream_truncate()  : bool
truncates a file to a given length
stream_write()  : int
writes data into the stream
unlink()  : bool
remove the data under the given path
unregister()  : mixed
Unregisters a previously registered URL wrapper for the vfs scheme.
url_stat()  : array<string|int, mixed>
returns status of url
calculateMode()  : int
calculates the file mode
doUnlink()  : bool
removes a path
getContent()  : vfsStreamContent
returns content for given path
getContentOfType()  : vfsStreamContent
returns content for given path but only when it is of given type
resolvePath()  : string
helper method to resolve a path from /foo/bar/. to /foo/bar
splitPath()  : array<string|int, string>
splits path into its dirname and the basename
createFile()  : bool
creates a file at given path
doPermChange()  : bool
executes given permission change when necessary rights allow such a change
isInRoot()  : bool
helper method to detect whether given path is in root path

Constants

APPEND

set file pointer to end, append new data

public mixed APPEND = 'a'

WRITE

set file pointer to start, overwrite existing data

public mixed WRITE = 'x'

WRITE_NEW

set file pointer to start, overwrite existing data; or create file if does not exist

public mixed WRITE_NEW = 'c'

Properties

$content

shortcut to file container

protected mixed $content
Tags
type

vfsStreamFile

$dir

shortcut to directory container

protected mixed $dir
Tags
type

vfsStreamDirectory

$dirIterator

shortcut to directory container iterator

protected mixed $dirIterator
Tags
type

vfsStreamDirectory

$mode

file mode: read only, write only, all

protected mixed $mode
Tags
type

int

$registered

switch whether class has already been registered as stream wrapper or not

protected static mixed $registered = false
Tags
type

bool

$root

root content

protected static mixed $root
Tags
type

vfsStreamContent

Methods

dir_closedir()

closes directory

public dir_closedir() : bool
Return values
bool

dir_opendir()

opens a directory

public dir_opendir(string $path, int $options) : bool
Parameters
$path : string
$options : int
Return values
bool

dir_readdir()

reads directory contents

public dir_readdir() : string
Return values
string

dir_rewinddir()

reset directory iteration

public dir_rewinddir() : bool
Return values
bool

mkdir()

creates a new directory

public mkdir(string $path, int $mode, int $options) : bool
Parameters
$path : string
$mode : int
$options : int
Return values
bool

register()

method to register the stream wrapper

public static register() : mixed

Please be aware that a call to this method will reset the root element to null. If the stream is already registered the method returns silently. If there is already another stream wrapper registered for the scheme used by vfsStream a vfsStreamException will be thrown.

Tags
throws
vfsStreamException
Return values
mixed

rename()

rename from one path to another

public rename(string $path_from, string $path_to) : bool
Parameters
$path_from : string
$path_to : string
Tags
author

Benoit Aubuchon

Return values
bool

rmdir()

removes a directory

public rmdir(string $path, int $options) : bool
Parameters
$path : string
$options : int
Tags
todo

consider $options with STREAM_MKDIR_RECURSIVE

Return values
bool

setQuota()

sets quota for disk space

public static setQuota(Quota $quota) : mixed
Parameters
$quota : Quota
Tags
since
1.1.0
Return values
mixed

stream_cast()

retrieve the underlaying resource

public stream_cast(int $cast_as) : bool

Please note that this method always returns false as there is no underlaying resource to return.

Parameters
$cast_as : int
Tags
since
0.9.0
see
https://github.com/mikey179/vfsStream/issues/3
Return values
bool

stream_eof()

checks whether stream is at end of file

public stream_eof() : bool
Return values
bool

stream_flush()

flushes unstored data into storage

public stream_flush() : bool
Return values
bool

stream_metadata()

sets metadata like owner, user or permissions

public stream_metadata(string $path, int $option, mixed $var) : bool
Parameters
$path : string
$option : int
$var : mixed
Tags
since
1.1.0
Return values
bool

stream_open()

open the stream

public stream_open(string $path, string $mode, string $options, string $opened_path) : bool
Parameters
$path : string

the path to open

$mode : string

mode for opening

$options : string

options for opening

$opened_path : string

full path that was actually opened

Return values
bool

stream_read()

read the stream up to $count bytes

public stream_read(int $count) : string
Parameters
$count : int

amount of bytes to read

Return values
string

stream_seek()

seeks to the given offset

public stream_seek(int $offset, int $whence) : bool
Parameters
$offset : int
$whence : int
Return values
bool

stream_stat()

returns status of stream

public stream_stat() : array<string|int, mixed>
Return values
array<string|int, mixed>

stream_tell()

returns the current position of the stream

public stream_tell() : int
Return values
int

stream_truncate()

truncates a file to a given length

public stream_truncate(int $size) : bool
Parameters
$size : int

length to truncate file to

Tags
since
1.1.0
Return values
bool

stream_write()

writes data into the stream

public stream_write(string $data) : int
Parameters
$data : string
Return values
int

amount of bytes written

remove the data under the given path

public unlink(string $path) : bool
Parameters
$path : string
Return values
bool

unregister()

Unregisters a previously registered URL wrapper for the vfs scheme.

public static unregister() : mixed

If this stream wrapper wasn't registered, the method returns silently.

If unregistering fails, or if the URL wrapper for vfs:// was not registered with this class, a vfsStreamException will be thrown.

Tags
throws
vfsStreamException
since
1.6.0
Return values
mixed

url_stat()

returns status of url

public url_stat(string $path, int $flags) : array<string|int, mixed>
Parameters
$path : string

path of url to return status for

$flags : int

flags set by the stream API

Return values
array<string|int, mixed>

calculateMode()

calculates the file mode

protected calculateMode(string $mode, bool $extended) : int
Parameters
$mode : string

opening mode: r, w, a or x

$extended : bool

true if + was set with opening mode

Return values
int

removes a path

protected doUnlink(string $path) : bool
Parameters
$path : string
Return values
bool

resolvePath()

helper method to resolve a path from /foo/bar/. to /foo/bar

protected resolvePath(string $path) : string
Parameters
$path : string
Return values
string

splitPath()

splits path into its dirname and the basename

protected splitPath(string $path) : array<string|int, string>
Parameters
$path : string
Return values
array<string|int, string>

createFile()

creates a file at given path

private createFile(string $path[, string $mode = null ][, string $options = null ]) : bool
Parameters
$path : string

the path to open

$mode : string = null

mode for opening

$options : string = null

options for opening

Return values
bool

isInRoot()

helper method to detect whether given path is in root path

private isInRoot(string $path) : bool
Parameters
$path : string
Return values
bool

Search results