PHPackages                             symplify/smart-file-system - 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. symplify/smart-file-system

Abandoned → [symfony/filesystem](/?search=symfony%2Ffilesystem)ArchivedLibrary[Utility &amp; Helpers](/categories/utility)

symplify/smart-file-system
==========================

Sanitized FileInfo with safe getRealPath() and other handy methods

11.1.26(3y ago)7712.3M↓19.3%420MITPHPPHP &gt;=8.1

Since Nov 23Pushed 2y ago1 watchersCompare

[ Source](https://github.com/deprecated-packages/smart-file-system)[ Packagist](https://packagist.org/packages/symplify/smart-file-system)[ Fund](https://www.paypal.me/rectorphp)[ GitHub Sponsors](https://github.com/tomasvotruba)[ RSS](/packages/symplify-smart-file-system/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (14)Versions (438)Used By (20)

Smart File System
=================

[](#smart-file-system)

[![Downloads total](https://camo.githubusercontent.com/ecad2753cf7b278e184f4aa3ab84f91619ba1c853d411f659fe6d7292cab0d72/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73796d706c6966792f736d6172742d66696c652d73797374656d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/symplify/smart-file-system/stats)

Install
-------

[](#install)

```
composer require symplify/smart-file-system
```

Use
---

[](#use)

### Does `SplFileInfo` exist?

[](#does-splfileinfo-exist)

The `SplFileInfo::getRealPath()` method returns absolute path to the file... [or `FALSE`, if the file doesn't exist](https://www.php.net/manual/en/splfileinfo.getrealpath.php). This default PHP behavior forces you to **check all `getRealPath()` calls**:

```
$fileInfo = new SplFileInfo('non_existing_file.txt');

if ($fileInfo->getRealPath() === false) {
    // damn, the files doesn't exist
    // throw exception or whatever
    // everytime!
}

$fileRealPath = $fileInfo->getRealPath();
```

While this has a reason - e.g. to be sure the file was not deleted since the construction, we actually have to call the method to find out the file was removed. Another annoyance is to tell this to static analyzers.

In reality, **it's very rare to work with file that was existing a while ago, but now is gone, without us doing it on purpose**. We usually use `SplFileInfo` to modify files or work with their paths.

**What if:**

- we could remove this problem and make sure **`getRealPath()` method always returns string**?
- get **an exception of non-existing file on SplFileInfo creation**?

### Introducing `SmartFileInfo`

[](#introducing-smartfileinfo)

```
$fileInfo = new Symplify\SmartFileSystem\SmartFileInfo('non_existing_file.txt');
// throws Symplify\SmartFileSystem\Exception\FileNotFoundException
```

This class also bring new useful methods:

```
// current directory (cwd()) is "/var/www"
$smartFileInfo = new Symplify\SmartFileSystem\SmartFileInfo('/var/www/src/ExistingFile.php');

echo $smartFileInfo->getBasenameWithoutSuffix();
// "ExistingFile"

echo $smartFileInfo->getRelativeFilePath();
// "src/ExistingFile.php"

echo $smartFileInfo->getRelativeDirectoryPath();
// "src"

echo $smartFileInfo->getRelativeFilePathFromDirectory('/var');
// "www/src/ExistingFile.php"
```

**It also fixes WTF behavior** of `Symfony\Component\Finder\SplFileInfo`. Which one? When you run e.g. `vendor/bin/ecs check src` and use `Finder`, the `getRelativeFilePath()` in Symfony now returns all the relative paths to `src`. Which is useless, mainly with multiple dirs like: `vendor/bin/ecs check src tests` both containing file `Post.php`.

```
$smartFileInfo = new Symplify\SmartFileSystem\SmartFileInfo('/var/www/src/Post.php');

echo $smartFileInfo->getRelativeFilePathFromCwd();
// "src/Post.php"
```

### File name Matching

[](#file-name-matching)

Last but not least, matching a file comes useful in excluding files (typical for tools like ECS, PHPStan, Psalm, Rector, PHP CS Fixer or PHP\_CodeSniffer):

```
$smartFileInfo = new Symplify\SmartFileSystem\SmartFileInfo('/var/www/src/PostRepository.php');

echo $smartFileInfo->endsWith('Repository.php');
// true

echo $smartFileInfo->doesFnmatch('*Repo*');
// true
```

### Smart FileSystem - Just like Symfony, just Better

[](#smart-filesystem---just-like-symfony-just-better)

New method - `readFile()` (to read files):

```
$smartFileSystem = new Symplify\SmartFileSystem\SmartFileSystem();
$fileContent = $smartFileSystem->readFile(__DIR__ . '/SomeFile.php');
```

```
// if you plan to use SmartFileInfo, use this
$smartFileInfo = $smartFileSystem->readFileToSmartFileInfo(__DIR__ . '/SomeFile.php');
```

### Sanitizer various files to `SmartFileInfo[]`

[](#sanitizer-various-files-to-smartfileinfo)

Do you have multiple file inputs that can mix-up?

```
$files = [new SplFileInfo('someFile.php')];

$files = [new Symfony\Component\Finder\SplFileInfo('someFile.php', 'someFile', '')];

// or
$files = (new Symfony\Component\Finder\Finder())->files();

// or
$files = ['someFile.php'];
```

Later, you wan to actually work with the files:

```
foreach ($files as $file) {
    // what methods do we have here
    // what kind of object?
    // is it even object or a string?
    $file->...
}
```

Use sanitized files, that **have united format you can rely on**:

```
use Symplify\SmartFileSystem\Finder\FinderSanitizer;

$finderSanitizer = new FinderSanitizer();
$smartFileInfos = $finderSanitizer->sanitize($files);

// always array of Symplify\SmartFileSystem\SmartFileInfo
var_dump($smartFileInfos);
```

Report Issues
-------------

[](#report-issues)

In case you are experiencing a bug or want to request a new feature head over to the [Symplify monorepo issue tracker](https://github.com/symplify/symplify/issues)

Contribute
----------

[](#contribute)

The sources of this package are contained in the Symplify monorepo. We welcome contributions for this package on [symplify/symplify](https://github.com/symplify/symplify).

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity57

Moderate usage in the ecosystem

Community24

Small or concentrated contributor base

Maturity86

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 95.4% 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 ~3 days

Recently: every ~11 days

Total

437

Last Release

1198d ago

Major Versions

v7.3.11 → v8.0.0-beta12020-05-16

8.3.48 → 9.0.0-BETA22020-11-14

9.4.70 → 10.0.0-beta12021-11-02

10.3.3 → 11.0.02022-06-13

PHP version history (6 changes)v7.0.0PHP ^7.2

8.2.17PHP ^7.2|^8.0

8.3.0PHP &gt;=7.2

9.0.0-rc1PHP &gt;=7.3

v9.4.0PHP &gt;=8.0

11.1.11PHP &gt;=8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/924196?v=4)[Tomas Votruba](/maintainers/TomasVotruba)[@TomasVotruba](https://github.com/TomasVotruba)

---

Top Contributors

[![actions-user](https://avatars.githubusercontent.com/u/65916846?v=4)](https://github.com/actions-user "actions-user (206 commits)")[![samsonasik](https://avatars.githubusercontent.com/u/459648?v=4)](https://github.com/samsonasik "samsonasik (7 commits)")[![TomasVotruba](https://avatars.githubusercontent.com/u/924196?v=4)](https://github.com/TomasVotruba "TomasVotruba (3 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisRector

Code StyleECS

### Embed Badge

![Health badge](/badges/symplify-smart-file-system/health.svg)

```
[![Health](https://phpackages.com/badges/symplify-smart-file-system/health.svg)](https://phpackages.com/packages/symplify-smart-file-system)
```

###  Alternatives

[symfony/maker-bundle

Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget about writing boilerplate code.

3.4k111.1M568](/packages/symfony-maker-bundle)[symplify/monorepo-builder

Not only Composer tools to build a Monorepo.

5205.3M82](/packages/symplify-monorepo-builder)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

728272.9k20](/packages/civicrm-civicrm-core)[friendsoftypo3/content-blocks

TYPO3 CMS Content Blocks - Content Types API | Define reusable components via YAML

96374.6k23](/packages/friendsoftypo3-content-blocks)[nativephp/desktop

NativePHP for Desktop

34020.6k3](/packages/nativephp-desktop)[solspace/craft-freeform

The most flexible and user-friendly form building plugin!

52664.9k12](/packages/solspace-craft-freeform)

PHPackages © 2026

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