The Filesystem component provides basic utilities for the filesystem and the start point of creating any filesystem
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
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/filesystemThen, 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
We implement some parts of the above interfaces that you can use them:
Directory Abstract: Directory
File Abstract: File
Node Abstract: Node
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
{
...
}
.
.
.
}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
We'll try to maintain this project as simple as possible, but Pull Requests are welcomed!
The MIT License (MIT). Please see License File for more information.