vfsStream.php
Some utility methods for vfsStream.
- Package
- bovigo_vfs
\vfsStream
Some utility methods for vfsStream.
Constants
Properties
Methods


addStructure(
\array<string,array | \string> $structure, \vfsStreamDirectory $baseDir
)
:
\vfsStreamDirectory
helper method to create subdirectories recursively
Name | Type | Description |
---|---|---|
$structure | \array<string,array | \string> | subdirectory structure to add |
$baseDir | \vfsStreamDirectory | directory to add the structure to optional |
Type | Description |
---|---|
\vfsStreamDirectory |


copyFromFileSystem(
string $path, \vfsStreamDirectory $baseDir
=
null, int $maxFileSize
=
1048576
)
:
\vfsStreamDirectory
copies the file system structure from given path into the base dir
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 is 1024 KB.
Name | Type | Description |
---|---|---|
$path | string | path to copy the structure from |
$baseDir | \vfsStreamDirectory | directory to add the structure to optional |
$maxFileSize | int | maximum file size of files to copy content from optional |
Type | Description |
---|---|
\vfsStreamDirectory |
Exception | Description |
---|---|
\InvalidArgumentException |
- See
- \https://github.com/mikey179/vfsStream/issues/4
- Since
- 0.11.0


create(
\array<string,array | \string> $structure, \vfsStreamDirectory $baseDir
=
null
)
:
\vfsStreamDirectory
creates vfsStream directory structure from an array and adds it to given base dir
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.
Name | Type | Description |
---|---|---|
$structure | \array<string,array | \string> | directory structure to add under root directory |
$baseDir | \vfsStreamDirectory | base directory to add structure to optional |
Type | Description |
---|---|
\vfsStreamDirectory |
Exception | Description |
---|---|
\InvalidArgumentException |
- See
- \https://github.com/mikey179/vfsStream/issues/14
- See
- \https://github.com/mikey179/vfsStream/issues/20
- Since
- 0.10.0


getCurrentGroup(
)
:
int
returns current group
If the system does not support posix_getgid() the current group will be root (0).
Type | Description |
---|---|
int |


getCurrentUser(
)
:
int
returns current user
If the system does not support posix_getuid() the current user will be root (0).
Type | Description |
---|---|
int |


inspect(
\vfsStreamVisitor $visitor, \vfsStreamContent $content
=
null
)
:
\vfsStreamVisitor
use visitor to inspect a content structure
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.
Name | Type | Description |
---|---|---|
$visitor | \vfsStreamVisitor | |
$content | \vfsStreamContent | optional |
Type | Description |
---|---|
\vfsStreamVisitor |
Exception | Description |
---|---|
\InvalidArgumentException |
- See
- \https://github.com/mikey179/vfsStream/issues/10
- Since
- 0.10.0


newDirectory(
string $name, int $permissions
=
null
)
:
\vfsStreamDirectory
returns a new directory with given name
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.
Name | Type | Description |
---|---|---|
$name | string | |
$permissions | int | optional |
Type | Description |
---|---|
\vfsStreamDirectory |


newFile(
string $name, int $permissions
=
null
)
:
\vfsStreamFile
returns a new file with given name
Name | Type | Description |
---|---|---|
$name | string | |
$permissions | int | optional |
Type | Description |
---|---|
\vfsStreamFile |


path(
string $url
)
:
string
restores the path from the url
Name | Type | Description |
---|---|---|
$url | string |
Type | Description |
---|---|
string |


setup(
string $rootDirName
=
'root', int $permissions
=
null, \array<string,array | \string> $structure
=
array()
)
:
\vfsStreamDirectory
helper method for setting up vfsStream in unit tests
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.
Name | Type | Description |
---|---|---|
$rootDirName | string | optional name of root directory |
$permissions | int | optional file permissions of root directory |
$structure | \array<string,array | \string> | optional directory structure to add under root directory |
Type | Description |
---|---|
\vfsStreamDirectory |
- See
- \https://github.com/mikey179/vfsStream/issues/14
- See
- \https://github.com/mikey179/vfsStream/issues/20
- Since
- 0.7.0


umask(
int $umask
=
null
)
:
int
sets new umask setting and returns previous umask setting
If no value is given only the current umask setting is returned.
Name | Type | Description |
---|---|---|
$umask | int | optional |
Type | Description |
---|---|
int |
- Since
- 0.8.0