Application Filesystem

The Webino™ filesystem provides simple to use drivers for working with local filesystems, Azure, Amazon S3, Copy.com, Dropbox, (S)FTP, GridFS, Memory, Rackspace, WebDAV, PHPCR and ZipArchive. [TODO]

Filesystem Interface

Note

All paths used by Filesystem API are relative to its adapter root directory.

$app->getFilesystems()

Accessing filesystem manager service.

/** @var \Zend\ServiceManager\ServiceLocatorInterface $filesystems */
$filesystems = $app->getFilesystems();

$app->file()

Obtaining filesystem instance.

use WebinoAppLib\Filesystem\LocalFiles;
use WebinoAppLib\Filesystem\InMemoryFiles;

// default filesystem
$localFiles = $app->file();
// or
$localFiles = $app->file(LocalFiles::class);

// different filesystem
$inMemoryFiles = $app->file(InMemoryFiles::class);

$app->file()->write()

Write files, throws an exception if the file already exists.

$app->file()->write('path/to/file.txt', 'File content example.');

$app->file()->update()

Update files, throws an exception if the file does not exists.

$app->file()->update('path/to/file.txt', 'File content example updated.');

$app->file()->put()

Write or update files.

$app->file()->put('path/to/file.txt', 'File content example.');

$app->file()->read()

Read files.

$contents = $app->file()->read('path/to/file.txt');

$app->file()->has()

Check if a file exists.

$exists = $app->file()->has('path/to/file.txt');

$app->file()->delete()

Delete files.

$app->file()->delete('path/to/file.txt');

$app->file()->readAndDelete()

Read and delete files.

$contents = $app->file()->readAndDelete('path/to/file.txt');

$app->file()->rename()

Rename files.

$app->file()->rename('path/to/file.txt', 'path/to/new-file.txt');

$app->file()->copy()

Copy files.

$app->file()->copy('path/to/file.txt', 'path/to/file-copy.txt');

$app->file()->getMimetype()

Get MIME types.

$mimetype = $app->file()->getMimetype('path/to/file.txt');

$app->file()->getTimestamp()

Get timestamps.

$timestamp = $app->file()->getTimestamp('path/to/file.txt');

$app->file()->getSize()

Get file sizes.

$size = $app->file()->getSize('path/to/file.txt');

$app->file()->createDir()

Create directories.

$app->file()->createDir('path/to/new/directory');

Directories are also made implicitly when writing to a deeper path.

$app->file()->write('path/to/file.txt', 'File content example.');

$app->file()->deleteDir()

Delete directories.

$app->file()->deleteDir('path/to/directory');

$app->file()->emptyDir()

Empty directories.

$app->file()->emptyDir('path/to/directory');

$app->file()->listContents()

List contents, returns array of info of the files and folders.

$contents = $app->file()->listContents('path/to/directory', $recursive = false);

// non-recursive root by default
$contents = $app->file()->listContents();

$app->file()->listPaths()

List paths, returns array of paths of the files and folders.

$paths = $app->file()->listPaths('path/to/directory', $recursive = false);

// non-recursive root by default
$paths = $app->file()->listPaths();

$app->file()->listFiles()

List files, returns array of paths of the files.

$files = $app->file()->listFiles('path/to/directory', $recursive = false);

// non-recursive root by default
$files = $app->file()->listFiles();

$app->file()->writeStream()

Write files using stream, throws an exception if the file already exists.

$app->file()->writeStream('path/to/file.txt', $stream);

$app->file()->updateStream()

Update files using stream, throws an exception if the file does not exists.

$app->file()->updateStream('path/to/file.txt', $stream);

$app->file()->putStream()

Write or update files using stream.

$app->file()->putStream('path/to/file.txt', $stream);

$app->file()->readStream()

Read files using stream.

$stream = $app->file()->readStream('path/to/file.txt');

Filesystem Config

DefaultFilesystem

Overriding default local working dir filesystem.

use WebinoAppLib\Feature\DefaultFilesystem;

Webino::config([
    // optional
    new DefaultFilesystem('custom/root'),
]);

See also

$app->file()

MemoryFilesystem

Configuring temporary filesystem in the memory.

use WebinoAppLib\Feature\MemoryFilesystem;

Webino::config([
    new MemoryFilesystem,
]);