Some utility methods for vfsStream.

api

 Methods

copies the file system structure from given path into the base dir

copyFromFileSystem(string $path, \org\bovigo\vfs\vfsStreamDirectory $baseDir, int $maxFileSize) : \org\bovigo\vfs\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 is 1024 KB.

since 0.11.0
see \org\bovigo\vfs\https://github.com/mikey179/vfsStream/issues/4

Parameters

$path

string

path to copy the structure from

$baseDir

\org\bovigo\vfs\vfsStreamDirectory

directory to add the structure to

$maxFileSize

int

maximum file size of files to copy content from

Exceptions

\InvalidArgumentException

Returns

creates vfsStream directory structure from an array and adds it to given base dir

create(array $structure, \org\bovigo\vfs\vfsStreamDirectory $baseDir) : \org\bovigo\vfs\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.

since 0.10.0
see \org\bovigo\vfs\https://github.com/mikey179/vfsStream/issues/14
see \org\bovigo\vfs\https://github.com/mikey179/vfsStream/issues/20

Parameters

$structure

array

directory structure to add under root directory

$baseDir

\org\bovigo\vfs\vfsStreamDirectory

base directory to add structure to

Exceptions

\InvalidArgumentException

Returns

disable dotfiles in directory listings

disableDotfiles() 

since 1.3.0

enable dotfiles in directory listings

enableDotfiles() 

since 1.3.0

returns current group

getCurrentGroup() : int

If the system does not support posix_getgid() the current group will be root (0).

Returns

int

returns current user

getCurrentUser() : int

If the system does not support posix_getuid() the current user will be root (0).

Returns

int

use visitor to inspect a content structure

inspect(\org\bovigo\vfs\visitor\vfsStreamVisitor $visitor, \org\bovigo\vfs\vfsStreamContent $content) : \org\bovigo\vfs\visitor\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.

since 0.10.0
see \org\bovigo\vfs\https://github.com/mikey179/vfsStream/issues/10

Parameters

$visitor

\org\bovigo\vfs\visitor\vfsStreamVisitor

the visitor who inspects

$content

\org\bovigo\vfs\vfsStreamContent

directory structure to inspect

Exceptions

\InvalidArgumentException

Returns

returns a new directory with given name

newDirectory(string $name, int $permissions) : \org\bovigo\vfs\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

permissions of directory to create

Returns

returns a new file with given name

newFile(string $name, int $permissions) : \org\bovigo\vfs\vfsStreamFile

Parameters

$name

string

name of file to create

$permissions

int

permissions of file to create

Returns

restores the path from the url

path(string $url) : string

Parameters

$url

string

vfsStream url to translate into path

Returns

string

sets quota to given amount of bytes

setQuota(int $bytes) 

since 1.1.0

Parameters

$bytes

int

helper method for setting up vfsStream in unit tests

setup(string $rootDirName, int $permissions, array $structure) : \org\bovigo\vfs\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.

since 0.7.0
see \org\bovigo\vfs\https://github.com/mikey179/vfsStream/issues/14
see \org\bovigo\vfs\https://github.com/mikey179/vfsStream/issues/20

Parameters

$rootDirName

string

name of root directory

$permissions

int

file permissions of root directory

$structure

array

directory structure to add under root directory

Returns

sets new umask setting and returns previous umask setting

umask(int $umask) : int

If no value is given only the current umask setting is returned.

since 0.8.0

Parameters

$umask

int

new umask setting

Returns

int

prepends the scheme to the given URL

url(string $path) : string

Parameters

$path

string

path to translate to vfsStream url

Returns

string

checks if vfsStream lists dotfiles in directory listings

useDotfiles() : bool

since 1.3.0

Returns

bool

helper method to create subdirectories recursively

addStructure(array $structure, \org\bovigo\vfs\vfsStreamDirectory $baseDir) : \org\bovigo\vfs\vfsStreamDirectory

Parameters

$structure

array

subdirectory structure to add

$baseDir

\org\bovigo\vfs\vfsStreamDirectory

directory to add the structure to

Returns

 Properties

 

initial umask setting

$umask 

type int
 

switch whether dotfiles are enabled in directory listings

$dotFiles 

type bool

 Constants

 

group: root

GROUP_ROOT 

 

group: user 1

GROUP_USER_1 

 

group: user 2

GROUP_USER_2 

 

owner: root

OWNER_ROOT 

 

owner: user 1

OWNER_USER_1 

 

owner: user 2

OWNER_USER_2 

 

url scheme

SCHEME