vfsStream
in package
Some utility methods for vfsStream.
Table of Contents
- GROUP_ROOT = 0
- group: root
- GROUP_USER_1 = 1
- group: user 1
- GROUP_USER_2 = 2
- group: user 2
- OWNER_ROOT = 0
- owner: root
- OWNER_USER_1 = 1
- owner: user 1
- OWNER_USER_2 = 2
- owner: user 2
- SCHEME = 'vfs'
- url scheme
- $umask : mixed
- initial umask setting
- $dotFiles : mixed
- switch whether dotfiles are enabled in directory listings
- copyFromFileSystem() : vfsStreamDirectory
- copies the file system structure from given path into the base dir
- create() : vfsStreamDirectory
- creates vfsStream directory structure from an array and adds it to given base dir
- disableDotfiles() : mixed
- disable dotfiles in directory listings
- enableDotfiles() : mixed
- enable dotfiles in directory listings
- getCurrentGroup() : int
- returns current group
- getCurrentUser() : int
- returns current user
- inspect() : vfsStreamVisitor
- use visitor to inspect a content structure
- newBlock() : vfsStreamBlock
- returns a new block with the given name
- newDirectory() : vfsStreamDirectory
- returns a new directory with given name
- newFile() : vfsStreamFile
- returns a new file with given name
- path() : string
- restores the path from the url
- setQuota() : mixed
- sets quota to given amount of bytes
- setup() : vfsStreamDirectory
- helper method for setting up vfsStream in unit tests
- umask() : int
- sets new umask setting and returns previous umask setting
- url() : string
- prepends the scheme to the given URL
- useDotfiles() : bool
- checks if vfsStream lists dotfiles in directory listings
- addStructure() : vfsStreamDirectory
- helper method to create subdirectories recursively
Constants
GROUP_ROOT
group: root
public
mixed
GROUP_ROOT
= 0
GROUP_USER_1
group: user 1
public
mixed
GROUP_USER_1
= 1
GROUP_USER_2
group: user 2
public
mixed
GROUP_USER_2
= 2
OWNER_ROOT
owner: root
public
mixed
OWNER_ROOT
= 0
OWNER_USER_1
owner: user 1
public
mixed
OWNER_USER_1
= 1
OWNER_USER_2
owner: user 2
public
mixed
OWNER_USER_2
= 2
SCHEME
url scheme
public
mixed
SCHEME
= 'vfs'
Properties
$umask
initial umask setting
protected
static mixed
$umask
= 00
Tags
$dotFiles
switch whether dotfiles are enabled in directory listings
private
static mixed
$dotFiles
= true
Tags
Methods
copyFromFileSystem()
copies the file system structure from given path into the base dir
public
static copyFromFileSystem(string $path[, vfsStreamDirectory $baseDir = null ][, int $maxFileSize = 1048576 ]) : vfsStreamDirectory
If no baseDir is given it will try to add the structure to the existing root directory without replacing existing childs except those with equal names. File permissions are copied as well. Please note that file contents will only be copied if their file size does not exceed the given $maxFileSize which defaults to 1024 KB. In case the file is larger file content will be mocked, see https://github.com/mikey179/vfsStream/wiki/MockingLargeFiles.
Parameters
- $path : string
-
path to copy the structure from
- $baseDir : vfsStreamDirectory = null
-
directory to add the structure to
- $maxFileSize : int = 1048576
-
maximum file size of files to copy content from
Tags
Return values
vfsStreamDirectory —create()
creates vfsStream directory structure from an array and adds it to given base dir
public
static create(array<string|int, mixed> $structure[, vfsStreamDirectory $baseDir = null ]) : vfsStreamDirectory
Assumed $structure contains an array like this:
array('Core' = array('AbstractFactory' => array('test.php' => 'some text content',
'other.php' => 'Some more text content',
'Invalid.csv' => 'Something else',
),
'AnEmptyFolder' => array(),
'badlocation.php' => 'some bad content',
)
)
the resulting directory tree will look like this:
baseDir \- Core |- badlocation.php |- AbstractFactory | |- test.php | |- other.php | \- Invalid.csv \- AnEmptyFolder
Arrays will become directories with their key as directory name, and strings becomes files with their key as file name and their value as file content.
If no baseDir is given it will try to add the structure to the existing root directory without replacing existing childs except those with equal names.
Parameters
- $structure : array<string|int, mixed>
-
directory structure to add under root directory
- $baseDir : vfsStreamDirectory = null
-
base directory to add structure to
Tags
Return values
vfsStreamDirectory —disableDotfiles()
disable dotfiles in directory listings
public
static disableDotfiles() : mixed
Tags
Return values
mixed —enableDotfiles()
enable dotfiles in directory listings
public
static enableDotfiles() : mixed
Tags
Return values
mixed —getCurrentGroup()
returns current group
public
static getCurrentGroup() : int
If the system does not support posix_getgid() the current group will be root (0).
Return values
int —getCurrentUser()
returns current user
public
static getCurrentUser() : int
If the system does not support posix_getuid() the current user will be root (0).
Return values
int —inspect()
use visitor to inspect a content structure
public
static inspect(vfsStreamVisitor $visitor[, vfsStreamContent $content = null ]) : vfsStreamVisitor
If the given content is null it will fall back to use the current root directory of the stream wrapper.
Returns given visitor for method chaining comfort.
Parameters
- $visitor : vfsStreamVisitor
-
the visitor who inspects
- $content : vfsStreamContent = null
-
directory structure to inspect
Tags
Return values
vfsStreamVisitor —newBlock()
returns a new block with the given name
public
static newBlock(string $name[, int $permissions = null ]) : vfsStreamBlock
Parameters
- $name : string
-
name of the block device
- $permissions : int = null
-
permissions of block to create
Return values
vfsStreamBlock —newDirectory()
returns a new directory with given name
public
static newDirectory(string $name[, int $permissions = null ]) : vfsStreamDirectory
If the name contains slashes, a new directory structure will be created. The returned directory will always be the parent directory of this directory structure.
Parameters
- $name : string
-
name of directory to create
- $permissions : int = null
-
permissions of directory to create
Return values
vfsStreamDirectory —newFile()
returns a new file with given name
public
static newFile(string $name[, int $permissions = null ]) : vfsStreamFile
Parameters
- $name : string
-
name of file to create
- $permissions : int = null
-
permissions of file to create
Return values
vfsStreamFile —path()
restores the path from the url
public
static path(string $url) : string
Parameters
- $url : string
-
vfsStream url to translate into path
Return values
string —setQuota()
sets quota to given amount of bytes
public
static setQuota(int $bytes) : mixed
Parameters
- $bytes : int
Tags
Return values
mixed —setup()
helper method for setting up vfsStream in unit tests
public
static setup([string $rootDirName = 'root' ][, int $permissions = null ][, array<string|int, mixed> $structure = array() ]) : vfsStreamDirectory
Instead of vfsStreamWrapper::register(); vfsStreamWrapper::setRoot(vfsStream::newDirectory('root')); you can simply do vfsStream::setup() which yields the same result. Additionally, the method returns the freshly created root directory which you can use to make further adjustments to it.
Assumed $structure contains an array like this:
array('Core' = array('AbstractFactory' => array('test.php' => 'some text content',
'other.php' => 'Some more text content',
'Invalid.csv' => 'Something else',
),
'AnEmptyFolder' => array(),
'badlocation.php' => 'some bad content',
)
)
the resulting directory tree will look like this:
root \- Core |- badlocation.php |- AbstractFactory | |- test.php | |- other.php | \- Invalid.csv \- AnEmptyFolder
Arrays will become directories with their key as directory name, and strings becomes files with their key as file name and their value as file content.
Parameters
- $rootDirName : string = 'root'
-
name of root directory
- $permissions : int = null
-
file permissions of root directory
- $structure : array<string|int, mixed> = array()
-
directory structure to add under root directory
Tags
Return values
vfsStreamDirectory —umask()
sets new umask setting and returns previous umask setting
public
static umask([int $umask = null ]) : int
If no value is given only the current umask setting is returned.
Parameters
- $umask : int = null
-
new umask setting
Tags
Return values
int —url()
prepends the scheme to the given URL
public
static url(string $path) : string
Parameters
- $path : string
-
path to translate to vfsStream url
Return values
string —useDotfiles()
checks if vfsStream lists dotfiles in directory listings
public
static useDotfiles() : bool
Tags
Return values
bool —addStructure()
helper method to create subdirectories recursively
protected
static addStructure(array<string|int, mixed> $structure, vfsStreamDirectory $baseDir) : vfsStreamDirectory
Parameters
- $structure : array<string|int, mixed>
-
subdirectory structure to add
- $baseDir : vfsStreamDirectory
-
directory to add the structure to