Filesystem Component
September 25, 2016 ยท View on GitHub
Introduction
Filesystem is component that allows managing multiple filesystems and provides abstraction for various storage models.
Features
Filesystem features:
Concepts
This section contains terminology, useful concepts and definitions, that might be helpful to learn to fully understand this component purpose.
Filesystem
Filesystem is an abstraction of methods manipulating on local and remote file and directory structure.
Examples
This section contains examples and patterns that can be used with described component.
Creating Filesystem
To create filesystem you have to pass storage model for it to operate upon.
$fs = new Filesystem(
(new FilesystemAdapterFactory)->create('Local');
);
Or alternatively, since Kraken 0.3.1
$fs = (new FilesystemFactory)->create('Local');
Mounting Filesystems
It is possible to mount multiple filesystems using Kraken\Filesystem\FilesystemManager. Mounted filesystems will then be accessible using proper prefix.
$factory = new FilesystemFactory();
$manager = new FilesystemManager([
'local' => $factory->create('Local', [[ 'path' => __DIR__ ]]), // this fs will be available with local:// prefix
'aws' => $factory->create('AwsS3v3', [ $config ]); // this fs will be available with aws:// prefix
]);
Operating On Filesystem
All operations on filesystem can be made via Kraken\Filesystem\FilesystemInterface.
Creating files:
$fs->createFile($path, "some text\n", $fs::VISIBILITY_PRIVATE);
Writing:
Writing to files can be done by write, prepend and append methods, for example:
$fs->append($path, "this will be added at the end\n");
Removing files:
$fs->removeFile($path);
Creating directories:
$fs->createDir($dir);
Removing directories:
$fs->removeDir($dir);
For more options, please see Kraken\Filesystem\FilesystemInterface.
Listing Files
To list files use getFiles method.
$files = $fs->getFiles($path, true, $filter = "#\.php$#si");
This example will list all .php files recursively in given path.
Listing Directories
To list directories use getDirectories method.
$dirs = $fs->getDirectories($path, $recursiveness, $filter);
Important Classes & Interfaces
This section contains list of most important classes and interfaces shipped with this component. It does not include all classes and interface.
Filesystem
class Filesystem implements FilesystemInterface
Loop is an abstraction layer for managing filesystem structure using various storage models. It wraps around the PHP League filesystem providing new, extended and Kraken-compatible interface, which has been redone with consistency in mind.
FilesystemInterface
interface FilesystemInterface
FilesystemManager
class FilesystemManager implements FilesystemManagerInterface
FilesystemManager is a special concrete object allowing you to create composition of filesystems and referencing all of them using one object.
FilesystemManagerInterface
interface FilesystemManagerInterface extends FilesystemInterface
FilesystemAdapterFactory
class FilesystemAdapterFactory extends Factory implements FilesystemAdapterFactoryInterface
This factory allows you to create any filesystem adapter wrapping corresponding PHP League model.
FilesystemAdapterFactoryInterface
interface FilesystemAdapterFactoryInterface extends FactoryInterface
Important Directories
This section contains list of most important directories existing inside of component. It does not include all directories.
Factory
Factory folder contains set of factories for creating variety of League Filesystem adapters for using Filesystem with cloud storage. All of them might be created using Kraken\Filesystem\FilesystemAdapterFactory.