dev-master
9999999-devSimple, iterable, emulated file system iterator for PHP apps
GPL
The Development Requires
by Thomas Parys
psr psr-3
Simple, iterable, emulated file system iterator for PHP apps
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)
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)
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" ] ]
Identical. See vfs-example.json for an example., (*5)
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)
$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(); }
Not designed to not use in foreach loops., (*8)
Licensed via MIT. Feel free to modify and contribute. Enjoy!, (*9)
Simple, iterable, emulated file system iterator for PHP apps
GPL
psr psr-3