2017 © Pedro Peláez
 

library vfs

Virtual file system

image

adlawson/vfs

Virtual file system

  • Friday, April 22, 2016
  • by adlawson
  • Repository
  • 12 Watchers
  • 296 Stars
  • 32,155 Installations
  • PHP
  • 13 Dependents
  • 0 Suggesters
  • 16 Forks
  • 7 Open issues
  • 11 Versions
  • 14 % Grown

The README.md

VFS (Virtual File System)

Virtual File System, (*1)

![Master branch build status][ico-build] Published version PHP ~5.4 ![MIT Licensed][ico-license], (*2)

VFS is a virtual file system for PHP built using the stream wrapper API. Streams are exposed just as typical file:// or http:// streams are to PHP's built-in functions and keywords like fopen and require. This implementation attempts to stay true to the typical streams, including triggering warnings and handling edge cases appropriately., (*3)

It can be installed in whichever way you prefer, but I recommend Composer., (*4)

{
    "require": {
        "adlawson/vfs": "*"
    }
}

Documentation

After creating and mounting the file system, you have the option of manipulating the virtual file system either via PHP's built-in functions, the VFS interfaces, or interfaces provided by another file system library., (*5)

<?php
use Vfs\FileSystem;
use Vfs\Node\Directory;
use Vfs\Node\File;

// Create and mount the file system
$fs = FileSystem::factory('vfs://');
$fs->mount();

// Add `/foo` and `/foo/bar.txt`
$foo = new Directory(['bar.txt' => new File('Hello, World!')]);
$fs->get('/')->add('foo', $foo);

// Get contents of `/foo/bar.txt`
$fs->get('/foo/bar.txt')->getContent(); // Hello, World!
file_get_contents('vfs://foo/bar.txt'); // Hello, World!

// Add `/foo/bar` and `/foo/bar/baz.php`
mkdir('vfs://foo/bar');
file_put_contents('vfs://foo/bar.php', '<?php echo "Hello, World!";');

// Require `/foo/bar.php`
require 'vfs://foo/baz.php';

// Works with any other file system library too
$symfony = new Symfony\Component\Filesystem\Filesystem();
$symfony->mkdir('vfs://foo/bar/baz');
$laravel = new Illuminate\Filesystem();
$laravel->isDirectory('vfs://foo/bar/baz'); //true

// Triggers PHP warnings on error just like typical streams
rename('vfs://path/to/nowhere', 'vfs://path/to/somewhere');
// PHP Warning: rename(vfs://path/to/nowhere,vfs://path/to/somewhere): No such file or directory in /srv/index.php on line 1; triggered in /srv/src/Logger/PhpErrorLogger.php on line 32

Example use cases

If you need to ask what you'd use a virtual file system for, you probably don't need one, but just in case, I've compiled a small list of examples: - Testing file system libraries without writing to disc - Runtime evaluation without eval (via write and require) - ...we need some more!, (*6)

Todo

Current tasks are listed on the github issues page, but some are listed here for reference: - Symlinks - File locks - Permissions/ACL, (*7)

Contributing

Contributions are accepted via Pull Request, but passing unit tests must be included before it will be considered for merge., (*8)

$ curl -O https://raw.githubusercontent.com/adlawson/vagrantfiles/master/php/Vagrantfile
$ vagrant up
$ vagrant ssh
...

$ cd /srv
$ composer install
$ vendor/bin/phpunit

License

The content of this library is released under the MIT License by Andrew Lawson.br/ You can find a copy of this license in LICENSE or at http://opensource.org/licenses/mit., (*9)

The Versions

22/04 2016

dev-develop

dev-develop https://github.com/adlawson/php-vfs

Virtual file system

  Sources   Download

MIT

The Requires

 

The Development Requires

read write file wrapper system stream virtual directory dir fs

20/02 2016

dev-master

9999999-dev https://github.com/adlawson/php-vfs

Virtual file system

  Sources   Download

MIT

The Requires

 

The Development Requires

read write file wrapper system stream virtual directory dir fs

20/02 2016

0.12.1

0.12.1.0 https://github.com/adlawson/php-vfs

Virtual file system

  Sources   Download

MIT

The Requires

 

The Development Requires

read write file wrapper system stream virtual directory dir fs

03/08 2015

0.12.0

0.12.0.0 https://github.com/adlawson/php-vfs

Virtual file system

  Sources   Download

MIT

The Requires

 

The Development Requires

read write file wrapper system stream virtual directory dir fs

24/07 2015

0.11.0

0.11.0.0 https://github.com/adlawson/php-vfs

Virtual file system

  Sources   Download

MIT

The Requires

 

The Development Requires

read write file wrapper system stream virtual directory dir fs

22/07 2015

0.10.0

0.10.0.0 https://github.com/adlawson/php-vfs

Virtual file system

  Sources   Download

MIT

The Requires

 

The Development Requires

read write file wrapper system stream virtual directory dir fs

30/12 2014

0.9.4

0.9.4.0

Virtual file system

  Sources   Download

MIT

The Requires

 

The Development Requires

read write file wrapper system stream virtual directory dir fs

07/09 2014

0.9.3

0.9.3.0

Virtual file system

  Sources   Download

MIT

The Requires

 

The Development Requires

read write file wrapper system stream virtual directory dir fs

06/09 2014

0.9.2

0.9.2.0

Virtual file system

  Sources   Download

MIT

The Requires

 

The Development Requires

read write file wrapper system stream virtual directory dir fs

04/09 2014

0.9.1

0.9.1.0

Virtual file system

  Sources   Download

MIT

The Requires

 

The Development Requires

read write file wrapper system stream directory dir fs

06/07 2014

0.9.0

0.9.0.0

Virtual file system

  Sources   Download

MIT

The Requires

 

The Development Requires

read write file wrapper system stream directory dir fs