PHPackages                             h4kuna/dir - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. h4kuna/dir

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

h4kuna/dir
==========

Create easily directories

v0.1.7(1y ago)173.6k↑15.3%6MITPHPPHP &gt;=8.0CI passing

Since Feb 2Pushed 1y ago1 watchersCompare

[ Source](https://github.com/h4kuna/dir)[ Packagist](https://packagist.org/packages/h4kuna/dir)[ Fund](https://revolut.me/milan2m/czk1000/dir)[ GitHub Sponsors](https://github.com/h4kuna)[ RSS](/packages/h4kuna-dir/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (11)Used By (6)

Dir
===

[](#dir)

[![Downloads this Month](https://camo.githubusercontent.com/0f8250c22d388d9993b0d208688b4e04ba0f3fc7bd725a10bcb1b8387771410f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f68346b756e612f6469722e737667)](https://packagist.org/packages/h4kuna/dir)[![Latest Stable Version](https://camo.githubusercontent.com/4395d49235d8d52819cea5a1d18c3807cf3a8b95ba642d932268ca4595b7dc6b/68747470733a2f2f706f7365722e707567782e6f72672f68346b756e612f6469722f762f737461626c653f666f726d61743d666c6174)](https://packagist.org/packages/h4kuna/dir)[![Coverage Status](https://camo.githubusercontent.com/467c9f5c9506f4d907278cbdd214f289ac531bdb2119ee58a8174afbfa9c2164/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f68346b756e612f6469722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/h4kuna/dir?branch=master)[![Total Downloads](https://camo.githubusercontent.com/8d5d0666f22788a23bfaf5794c490dded627ef0eb3103fa261efe825f89eeaca/68747470733a2f2f706f7365722e707567782e6f72672f68346b756e612f6469722f646f776e6c6f6164733f666f726d61743d666c6174)](https://packagist.org/packages/h4kuna/dir)[![License](https://camo.githubusercontent.com/06f612ec078fbb497c22c7623c568ca304d639a2cedff764ea76cc6e3fa3ac1d/68747470733a2f2f706f7365722e707567782e6f72672f68346b756e612f6469722f6c6963656e73653f666f726d61743d666c6174)](https://packagist.org/packages/h4kuna/dir)

One abstract class provide path and prepare filesystem.

### Install by composer

[](#install-by-composer)

```
composer require h4kuna/dir

```

How to use
----------

[](#how-to-use)

Your path is represented by your class. In this repository is prepared class TempDir. By same way create own class.

These dirs are exist:

- temp dir `/documet/root/temp`
- log dir `/documet/root/log`
- storage dir `/documet/root/data`

### Example

[](#example)

Create StorageDir.

```
class StorageDir extends \h4kuna\Dir\Dir
{

}
```

Start to use.

```
$storageDir = new StorageDir('/documet/root/data'); // dir in constructor does not check
$storageDir->create(); // if dir from constructor does not exist, let's check and create
$subDir = $storageDir->dir('foo/bar');
$filepath = $subDir->filename('lucky', 'jpg');
$filepath2 = $storageDir->filename('baz/foo/happy.jpg');

echo $filepath; // /documet/root/data/foo/bar/lucky.jpg
echo $filepath2; // /documet/root/data/baz/foo/happy.jpg
```

On file system exists path `/documet/root/data/foo/bar` and `/documet/root/data/baz/foo`.

Your storage dir is represented by class StorageDir and you can use it by dependency injection.

```
class MyClass {

    public function __construct(private StorageDir $storageDir) {
    }

}
```

Check dir
---------

[](#check-dir)

If directory does not exist, the method `create` throw IOException. If directory exists, but is not writeable, the method `checkWriteable` throw `DirIsNotWriteableException` extends from `IOException`.

```
use h4kuna\Dir;
try {
    $fileInfo = (new Dir\Dir('/any/path'))
        ->create()
        ->checkWriteable()
        ->fileInfo('foo.txt');
} catch (Dir\Exceptions\IOException $e) {
    // dir is not writable
}

var_dump($fileInfo->getPathname()); // /any/path/foo.txt
```

Incorrect use
-------------

[](#incorrect-use)

In constructor use only absolute path without last slash like in example.

This is incorrect

- `new StorageDir('/documet/root/data/')`
- `new StorageDir('documet/root/data/')`
- `new StorageDir('documet/root/data')`

Correct is only `new StorageDir('/documet/root/data')`.

In methods `dir()` and `filename()` don't use slashes on the begin and end path.

This is incorrect

- `$storageDir->dir('/foo/')`
- `$storageDir->dir('/foo')`
- `$storageDir->dir('foo/')`

Correct is only `$storageDir->dir('foo')` or sub dir `$storageDir->dir('foo/bar')`.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity33

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~66 days

Recently: every ~85 days

Total

9

Last Release

673d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/54b4efb9b89167fa3598b1a41477b20387390f4a0fb65b447bd6bb7c30a49020?d=identicon)[h4kuna](/maintainers/h4kuna)

---

Top Contributors

[![h4kuna](https://avatars.githubusercontent.com/u/335722?v=4)](https://github.com/h4kuna "h4kuna (22 commits)")

### Embed Badge

![Health badge](/badges/h4kuna-dir/health.svg)

```
[![Health](https://phpackages.com/badges/h4kuna-dir/health.svg)](https://phpackages.com/packages/h4kuna-dir)
```

###  Alternatives

[nette/php-generator

🐘 Nette PHP Generator: generates neat PHP code for you. Supports new PHP 8.5 features.

2.3k64.2M576](/packages/nette-php-generator)[nette/robot-loader

🍀 Nette RobotLoader: high performance and comfortable autoloader that will search and autoload classes within your application.

89352.7M321](/packages/nette-robot-loader)[symplify/monorepo-builder

Not only Composer tools to build a Monorepo.

5205.3M82](/packages/symplify-monorepo-builder)[nette/component-model

⚛ Nette Component Model

28516.5M92](/packages/nette-component-model)[nette/code-checker

✅ Nette CodeChecker: A simple tool to check source code against a set of Nette coding standards.

881.7M6](/packages/nette-code-checker)[contributte/di

Extra contrib to nette/di

465.8M18](/packages/contributte-di)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
