vfsStream.php

Show: inherited
Table of Contents

Some utility methods for vfsStream.

Package
bovigo_vfs  

\vfsStream

Package: bovigo\vfs

Some utility methods for vfsStream.

Constants

Constant  SCHEME = 'vfs'

url scheme

Constant  OWNER_ROOT = 0

owner: root

Constant  OWNER_USER_1 = 1

owner: user 1

Constant  OWNER_USER_2 = 2

owner: user 2

Constant  GROUP_ROOT = 0

group: root

Constant  GROUP_USER_1 = 1

group: user 1

Constant  GROUP_USER_2 = 2

group: user 2

Properties

Propertyprotectedint  $umask= '0000'
static

initial umask setting

Default value0000Details
Type
int

Methods

methodprotectedaddStructure( \array<string,array | \string> $structure, \vfsStreamDirectory $baseDir ) : \vfsStreamDirectory
static

helper method to create subdirectories recursively

Parameters
Name Type Description
$structure \array<string,array | \string>

subdirectory structure to add

$baseDir \vfsStreamDirectory

directory to add the structure to optional

Returns
Type Description
\vfsStreamDirectory
methodpubliccopyFromFileSystem( string $path, \vfsStreamDirectory $baseDir = null, int $maxFileSize = 1048576 ) : \vfsStreamDirectory
static

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.

Parameters
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

Returns
Type Description
\vfsStreamDirectory
Throws
Exception Description
\InvalidArgumentException
Details
See
\https://github.com/mikey179/vfsStream/issues/4  
Since
0.11.0  
methodpubliccreate( \array<string,array | \string> $structure, \vfsStreamDirectory $baseDir = null ) : \vfsStreamDirectory
static

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.

Parameters
Name Type Description
$structure \array<string,array | \string>

directory structure to add under root directory

$baseDir \vfsStreamDirectory

base directory to add structure to optional

Returns
Type Description
\vfsStreamDirectory
Throws
Exception Description
\InvalidArgumentException
Details
See
\https://github.com/mikey179/vfsStream/issues/14  
See
\https://github.com/mikey179/vfsStream/issues/20  
Since
0.10.0  
methodpublicgetCurrentGroup( ) : int
static

returns current group

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

Returns
Type Description
int
methodpublicgetCurrentUser( ) : int
static

returns current user

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

Returns
Type Description
int
methodpublicinspect( \vfsStreamVisitor $visitor, \vfsStreamContent $content = null ) : \vfsStreamVisitor
static

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.

Parameters
Name Type Description
$visitor \vfsStreamVisitor
$content \vfsStreamContent

optional

Returns
Type Description
\vfsStreamVisitor
Throws
Exception Description
\InvalidArgumentException
Details
See
\https://github.com/mikey179/vfsStream/issues/10  
Since
0.10.0  
methodpublicnewDirectory( string $name, int $permissions = null ) : \vfsStreamDirectory
static

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.

Parameters
Name Type Description
$name string
$permissions int

optional

Returns
Type Description
\vfsStreamDirectory
methodpublicnewFile( string $name, int $permissions = null ) : \vfsStreamFile
static

returns a new file with given name

Parameters
Name Type Description
$name string
$permissions int

optional

Returns
Type Description
\vfsStreamFile
methodpublicpath( string $url ) : string
static

restores the path from the url

Parameters
Name Type Description
$url string
Returns
Type Description
string
methodpublicsetup( string $rootDirName = 'root', int $permissions = null, \array<string,array | \string> $structure = array() ) : \vfsStreamDirectory
static

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.

Parameters
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

Returns
Type Description
\vfsStreamDirectory
Details
See
\https://github.com/mikey179/vfsStream/issues/14  
See
\https://github.com/mikey179/vfsStream/issues/20  
Since
0.7.0  
methodpublicumask( int $umask = null ) : int
static

sets new umask setting and returns previous umask setting

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

Parameters
Name Type Description
$umask int

optional

Returns
Type Description
int
Details
Since
0.8.0  
methodpublicurl( string $path ) : string
static

prepends the scheme to the given URL

Parameters
Name Type Description
$path string
Returns
Type Description
string
Documentation was generated by DocBlox 0.18.1.