Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
This page provides an overview of vfsStream functionality.
The full machine generated documentation is available at http://vfs.bovigo.org/apidoc/.
You start using vfsStream by creating a (virtual) root directory:
$root = vfsStream::setup('home');
All files created in vfsStream will be below the specified directory, i.e.
Creating a file
You can now manipulate files using all the standard PHP functions. To do this, you'll need a filename. That is where
vfsStream::url() is used. Thus to create a file you can:
vfsStream::setup('home'); $file = vfsStream::url('home/test.txt'); file_put_contents($file, "The new contents of the file");
However, you can also create a file directly using vfsStream as follows:
$root = vfsStream::setup('home'); vfsStream::newFile('test.txt')->at($root)->setContent("The new contents of the file");
newFile method creates a file but doesn't place it into the file system. The chained
at method specifies where in the file system to place it (i.e.
/home/test.txt). Finally, the
setContent method initializes the file with data in the provided string.