2017 © Pedro Peláez
 

library vfs

Simple, iterable, emulated file system iterator for PHP apps

image

wwsh/vfs

Simple, iterable, emulated file system iterator for PHP apps

  • Tuesday, March 1, 2016
  • by wwsh
  • Repository
  • 1 Watchers
  • 0 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

VFS File System Iterator

A Virtual File System (VFS) directory iterator for PHP, compatible with the API of RecursiveDirectoryIterator and DirectoryIterator, able to mimic original class behaviour, while creating a virtual, non-existent file system from a PHP array., (*1)

Input

Factory accepts two parameters: * string or array: either path to a JSON file, or array itself. * (optional) the initial path to iterate, for example: "/music/oldies", (*2)

Array format

Each key represents a directory, each value is the filename itself., (*3)

Structure example:, (*4)

 '/music' => [
        '1993 Haddaway - What Is Love (Remixes)' => [
            "1 - Haddaway - What Is Love (7'' Mix).wav",
            "2 - Haddaway - What Is Love (Eat This Mix).wav",
            "3 - Haddaway - What Is Love (Tour De Trance Mix).wav"
        ],
        "1985 Paul Hardcastle - 19 (The Final Story) [601 814]" => [
            "01 - Paul Hardcastle - 19 (The Final Story).wav",
            "02 - Paul Hardcastle - 19 (Destruction Mix).wav"
        ]
    ]

JSON format

Identical. See vfs-example.json for an example., (*5)

Output

The following methods are supported and fully emulated:, (*6)

public function getFilename();

public function getPath();

public function isDir();

public function isDot();

public function isFile();

public function current();

public function next();

public function valid();

public function getChildren();

public function hasChildren();

public function rewind();

See [here][1] for original API explanation., (*7)

Example working code

    $path = ... // define starting path
    $vfsArray = []; // paste the VFS array here. See above.
    $iterator = FileSystemFactory::create('vfs', [$path, $vfsArray]);
    $iterator->rewind();
    echo 'Browsing path ' . $iterator->getPath() . "...\n";

    while ($iterator->valid()) {
        $file = $iterator->current();

        if ($file->isDot() || $file->isFile()) {
            continue;
        }

        echo 'Processing directory ' . $file->getFilename() . "\n";
        // process (string)$file.....
        $results[] = $result;

        $iterator->next();
    }

Warnings

Not designed to not use in foreach loops., (*8)

Notes

Licensed via MIT. Feel free to modify and contribute. Enjoy!, (*9)

The Versions

01/03 2016

dev-master

9999999-dev

Simple, iterable, emulated file system iterator for PHP apps

  Sources   Download

GPL

The Development Requires

psr psr-3