Edit this page

Filesystem Component


Filesystem is component that allows managing multiple filesystems and provides abstraction for various storage models.


Filesystem features:

  • Abstraction for filesystem-related operations
  • Mount manager for multiple filesystems
  • Support for multiple storage models including clouds
  • Kraken Framework compatibility


This section contains terminology, useful concepts and definitions, that might be helpful to learn to fully understand this component purpose.


Filesystem is an abstraction of methods manipulating on local and remote file and directory structure.


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 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:


Creating directories:


Removing directories:


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.


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.


interface FilesystemInterface


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.


interface FilesystemManagerInterface extends FilesystemInterface


class FilesystemAdapterFactory extends Factory implements FilesystemAdapterFactoryInterface

This factory allows you to create any filesystem adapter wrapping corresponding PHP League model.


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 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.

Start from the Beginning