Pages 14

Clone this wiki locally

Visitors

Especially with larger directory structures one can get confused of how the directory tree looks like. Since version 0.10.0 vfsStream provides a simple utility method to inspect the directory structure: vfsStream::inspect(). As first parameter it expects a vfsStreamVisitor - for simplicity and most use cases the vfsStreamPrintVisitor should be sufficient. It prints out the directory structure, defaulting to STDOUT, but can be changed to write to another stream (yes, even to a vfs:// stream ;-)).

The second parameter of vfsStream::inspect() is the directory you want to inspect. If not given it will try to inspect the current root. If no root exists it throws an InvalidArgumentException.

vfsStream also provides the vfsStreamStructureVisitor which creates a similar structure which can be used for vfsStream::create(). It can also be used to do something like this:

This way you can make sure the overall structure after an operation like unlink() or rename() is still correct without having to test a bunch of directories and files.

If none of the delivered visitor implementations fit one can create another implementation of the vfsStreamVisitor interface, best by extending from vfsStreamAbstractVisitor which delivers a default implementation for the vfsStreamVisitor::visit() method.

Note: since version 1.0.0 the visitor interface and classes are namespaced with org\bovigo\vfs\visitor.