dnj / filesystem
The Filesystem component provides basic utilities for the filesystem.
Installs: 1 817
Dependents: 7
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 1
Open Issues: 0
pkg:composer/dnj/filesystem
Requires
- php: >=7.4
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.1
- phpstan/phpstan: ^0.12.68
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2025-10-17 14:36:14 UTC
README
The Filesystem component provides basic utilities for the filesystem and the start point of creating any filesystem
Introduction
This is a repository intended to serve as a starting point if you want to bootstrap a filesystem in PHP.
It could be useful if you want to implement a filesystem. The idea is that you don't have to worry about the basic structure of a filesystem.
We
Just implement this contracts and have your own filesystem!
We have to
- Latest versions of PHP and PHPUnit
- Best practices applied:
README.md(badges included)LICENSEcomposer.jsonphpunit.xml.gitignore
- Some useful resources to start coding
How To Start
First, You should decide what kind of filesystem you decide to create, Like: Local, TMP, S3, FTP or any file system you decide to create.
Note: we implement some filesystems that you can use them:
GitHub: All DNJ implemented filesystems
Create new project and require dnj/filesystem , so run:
composer require dnj/filesystem
Then, You should implement two interface, IDirectory and IFile
Note: The above interfaces is extended from See: INode
INode methods:
getBasename(): stringgetDirname(): stringgetPath(): stringgetRelativePath(IDirectory $base): stringexists(): boolgetDirectory(): IDirectorydelete(): voidrename(string $newName): void
IDirectory methods:
files(bool $recursively): Iterator<IFile|IDirectory>items(bool $recursively): Iterator<IFile>directories(bool $recursively): Iterator<IDirectory>make(bool $recursively): voidsize(bool $recursively): intmove(IDirectory $dest): voidfile(string $name): IFiledirectory(string $name): IDirectoryisEmpty(): boolcopyTo(IDirectory $dest): voidcopyFrom(IDirectory $source): void
IFile methods:
copyTo(IFile $dest): voidcopyFrom(IFile $source): voidmove(IFile $dest): voidread(int $length = 0): stringwrite(string $data): voidsize(): intgetExtension(): stringisEmpty(): boolmd5(bool $raw): stringsha1(bool $raw): string
Helpful resources
We implement some parts of the above interfaces that you can use them:
Directory Abstract: Directory
File Abstract: File
Node Abstract: Node
Example implementation:
Directory:
<?php namespace YOUR_NAMESPACE\YOUR_FILESYSTEM; use dnj\Filesystem\Directory as DirectoryAbstract; class Directory extends DirectoryAbstract { public function make(bool $recursively = true): void { ... } . . . }
File:
namespace YOUR_NAMESPACE\YOUR_FILESYSTEM; use dnj\Filesystem\File as FileAbstract; class Directory extends FileAbstract { public function write(string $data): void { ... } public function read(int $length = 0): string { ... } . . . }
DNJ implemented filesystems:
You can find all implemented filesystems by DNJ by following GitHub
Local FileSystem By DNJ: Github Repository
Temporary FileSystem By DNJ: Github Repository
S3 FileSystem By DNJ: Github Repository
More resources
PHP 8
PHPUnit
About
We'll try to maintain this project as simple as possible, but Pull Requests are welcomed!
License
The MIT License (MIT). Please see License File for more information.