PHPackages                             dnj/filesystem - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. dnj/filesystem

ActiveLibrary[File &amp; Storage](/categories/file-storage)

dnj/filesystem
==============

The Filesystem component provides basic utilities for the filesystem.

1.0.1(3y ago)01.8k15MITPHPPHP &gt;=7.4

Since Sep 26Pushed 3y ago1 watchersCompare

[ Source](https://github.com/dnj/filesystem)[ Packagist](https://packagist.org/packages/dnj/filesystem)[ RSS](/packages/dnj-filesystem/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (3)Versions (3)Used By (5)

PHP FileSystem
==============

[](#php-filesystem)

[![Latest Version on Packagist](https://camo.githubusercontent.com/b33625484a3d2046ea6e57149dd68c4b19293d929e8faa1dacbd972d903da36c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f646e6a2f66696c6573797374656d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/dnj/filesystem)[![Total Downloads](https://camo.githubusercontent.com/8b26f89fb8db69e8e67367387f8d4c2eb0c3c24830464e76a22d965892536996/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f646e6a2f66696c6573797374656d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/dnj/filesystem)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://github.com/dnj/filesystem/blob/master/LICENSE)[![Testing status](https://github.com/dnj/filesystem/actions/workflows/test.yml/badge.svg)](https://github.com/dnj/filesystem/actions/workflows/test.yml)

### The Filesystem component provides basic utilities for the filesystem and the start point of creating any filesystem

[](#the-filesystem-component-provides-basic-utilities-for-the-filesystem-and-the-start-point-of-creating-any-filesystem)

Introduction
------------

[](#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`](https://github.com/dnj/filesystem/blob/master/README.md) (badges included)
    - [`LICENSE`](https://github.com/dnj/filesystem/blob/master/LICENSE)
    - [`composer.json`](https://github.com/dnj/filesystem/blob/master/composer.json)
    - [`phpunit.xml`](https://github.com/dnj/filesystem/blob/master/phpunit.xml)
    - [`.gitignore`](https://github.com/dnj/filesystem/blob/master/.gitignore)
- Some useful resources to start coding

How To Start
------------

[](#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](https://github.com/orgs/dnj/repositories?q=-filesystem)

Create new project and require `dnj/filesystem` , so run:

```
composer require dnj/filesystem
```

Then, You should implement two interface, [IDirectory](https://github.com/dnj/filesystem/blob/master/src/Contracts/IDirectory.php) and [IFile](https://github.com/dnj/filesystem/blob/master/src/Contracts/IDirectory.php)
Note: The above interfaces is extended from See: [INode](https://github.com/dnj/filesystem/blob/master/src/Contracts/INode.php)

### [INode](https://github.com/dnj/filesystem/blob/master/src/Contracts/INode.php) methods:

[](#inode-methods)

- `getBasename(): string`
- `getDirname(): string`
- `getPath(): string`
- `getRelativePath(IDirectory $base): string`
- `exists(): bool`
- `getDirectory(): IDirectory`
- `delete(): void`
- `rename(string $newName): void`

### [IDirectory](https://github.com/dnj/filesystem/blob/master/src/Contracts/IDirectory.php) methods:

[](#idirectory-methods)

- `files(bool $recursively): Iterator`
- `items(bool $recursively): Iterator`
- `directories(bool $recursively): Iterator`
- `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](https://github.com/dnj/filesystem/blob/master/src/Contracts/IDirectory.php) methods:

[](#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
-----------------

[](#helpful-resources)

We implement some parts of the above interfaces that you can use them:
Directory Abstract: [Directory](https://github.com/dnj/filesystem/blob/master/src/Directory.php)
File Abstract: [File](https://github.com/dnj/filesystem/blob/master/src/File.php)
Node Abstract: [Node](https://github.com/dnj/filesystem/blob/master/src/Node.php)

Example implementation:
-----------------------

[](#example-implementation)

Directory:

```
