dnj / filesystem
The Filesystem component provides basic utilities for the filesystem.
Installs: 1 535
Dependents: 7
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 1
Open Issues: 0
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: 2024-10-17 12:43:02 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)LICENSE
composer.json
phpunit.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(): string
getDirname(): string
getPath(): string
getRelativePath(IDirectory $base): string
exists(): bool
getDirectory(): IDirectory
delete(): void
rename(string $newName): void
IDirectory methods:
files(bool $recursively): Iterator<IFile|IDirectory>
items(bool $recursively): Iterator<IFile>
directories(bool $recursively): Iterator<IDirectory>
make(bool $recursively): void
size(bool $recursively): int
move(IDirectory $dest): void
file(string $name): IFile
directory(string $name): IDirectory
isEmpty(): bool
copyTo(IDirectory $dest): void
copyFrom(IDirectory $source): void
IFile methods:
copyTo(IFile $dest): void
copyFrom(IFile $source): void
move(IFile $dest): void
read(int $length = 0): string
write(string $data): void
size(): int
getExtension(): string
isEmpty(): bool
md5(bool $raw): string
sha1(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.