PHPackages                             marktaborosi/flysystem-filter - 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. marktaborosi/flysystem-filter

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

marktaborosi/flysystem-filter
=============================

A lightweight filtering layer and an easy-to-use filter builder for League/Flysystem filesystem contents.

v3.0.0(8mo ago)11.2k↓67%MITPHPPHP &gt;=8.2CI passing

Since Dec 7Pushed 8mo ago1 watchersCompare

[ Source](https://github.com/marktaborosi/flysystem-filter)[ Packagist](https://packagist.org/packages/marktaborosi/flysystem-filter)[ Docs](https://github.com/marktaborosi/flysystem-filter)[ RSS](/packages/marktaborosi-flysystem-filter/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)Dependencies (7)Versions (7)Used By (0)

Flysystem Filter
================

[](#flysystem-filter)

[![Author](https://camo.githubusercontent.com/bc394b2935ae7d40994923fa66d51a4027da43bc8e4c8addc07509b7cd412c8c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f617574686f722d406d61726b7461626f726f73692d626c75652e737667)](https://github.com/marktaborosi)[![Latest Version](https://camo.githubusercontent.com/9afba8fa488299f34031cb5868b8fe48d8d4b636a36b30e02971a46f249be7e4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6d61726b7461626f726f73692f666c7973797374656d2d66696c7465722e7376673f7374796c653d666c61742d737175617265)](https://github.com/marktaborosi/flysystem-filter/releases)[![Software License](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](https://github.com/marktaborosi/flysystem-filter/blob/master/LICENSE)[![Downloads](https://camo.githubusercontent.com/d5e256fc03a3f85c294343853565ee2d2a5c90c5607ec463aeab64d0f139eff1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d61726b7461626f726f73692f666c7973797374656d2d66696c7465722e737667)](https://camo.githubusercontent.com/d5e256fc03a3f85c294343853565ee2d2a5c90c5607ec463aeab64d0f139eff1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d61726b7461626f726f73692f666c7973797374656d2d66696c7465722e737667)[![php 8.2+](https://camo.githubusercontent.com/b9650bc67fbe9468d5b9a9c0e738f8a492d477c26dd975407624353da58cbaf9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d6d696e253230382e322d7265642e737667)](https://camo.githubusercontent.com/b9650bc67fbe9468d5b9a9c0e738f8a492d477c26dd975407624353da58cbaf9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d6d696e253230382e322d7265642e737667)[![CI](https://github.com/marktaborosi/flysystem-filter/actions/workflows/test.yml/badge.svg)](https://github.com/marktaborosi/flysystem-filter/actions)

Flysystem Filter is a lightweight and intuitive filtering layer for [League/Flysystem](https://flysystem.thephpleague.com/). It provides an easy-to-use `FilterBuilder` for logical and chainable filtering of filesystem contents (`DirectoryListing`).

Features
--------

[](#features)

- **Simple Filtering:** Filter filesystem contents without writing complex callback functions.
- **Logical Expressions:** Combine conditions using `and()`, `or()`, `group_start()`, and `group_end()`.
- **Chainable API:** Build complex filters with a readable, chainable syntax.
- **Integration with Flysystem:** Works seamlessly with League/Flysystem's `DirectoryListing`.

Installation
------------

[](#installation)

Install via Composer:

```
composer require marktaborosi/flysystem-filter
```

Usage
-----

[](#usage)

### Simple Example

[](#simple-example)

Here's a basic example that filters only files:

```
use League\Flysystem\Filesystem;
use League\Flysystem\Local\LocalFilesystemAdapter;
use Marktaborosi\FlysystemFilter\FilterBuilder;
use Marktaborosi\FlysystemFilter\FlysystemFilter;

require 'vendor/autoload.php';

$adapter = new LocalFilesystemAdapter(__DIR__ . '/tests/Storage/');
$flysystem = new Filesystem($adapter);
$flysystemContents = $flysystem->listContents('', true);

$filter = new FilterBuilder();
$filter->isFile();

$flysystemFilter = new FlysystemFilter();
$filteredResults = $flysystemFilter->filter($flysystemContents, $filter);

foreach ($filteredResults as $result) {
    echo $result->path() . PHP_EOL;
}
```

### Advanced Example

[](#advanced-example)

Filter files with advanced conditions:

```
$filter = new FilterBuilder();
$filter
    ->extensionEquals(['txt', 'log'])
    ->and()
    ->isPublic()
    ->and()
    ->sizeLt('1G');

$flysytemFilter = new FlysystemFilter();
$filteredResults = $flysystemFilter->filter($flysystemContents, $filter);
```

### Using Grouping and Logical Operators

[](#using-grouping-and-logical-operators)

You can group conditions to create complex expressions:

```
$filter = new FilterBuilder();
$filter
    ->group_start()
        ->extensionContains(['log', 'txt'])
        ->and()
        ->isFile()
    ->group_end()
    ->or()
    ->pathMatchesRegex('/debug/');

$flysytemFilter = new FlysystemFilter();
$filteredResults = $flysystemFilter->filter($flysystemContents, $filter);
```

Laravel Integration
-------------------

[](#laravel-integration)

From **v3.0.0**, Flysystem Filter ships with native Laravel support — including a Service Provider and a Facade — for seamless integration into your Laravel projects.

### Installation

[](#installation-1)

If installed via Composer in a Laravel application, the package will be automatically discovered thanks to Laravel's package auto-discovery.

**composer.json** (auto-discovery config — already included in this package):

```
{
  "extra": {
    "laravel": {
      "providers": [
        "Marktaborosi\\FlysystemFilter\\Laravel\\FlysystemFilterServiceProvider"
      ],
      "aliases": {
        "FlysystemFilter": "Marktaborosi\\FlysystemFilter\\Laravel\\FlysystemFilterFacade"
      }
    }
  }
}
```

If you have disabled auto-discovery, register them manually in `config/app.php`:

```
'providers' => [
    Marktaborosi\FlysystemFilter\Laravel\FlysystemFilterServiceProvider::class,
],
'aliases' => [
    'FlysystemFilter' => Marktaborosi\FlysystemFilter\Laravel\FlysystemFilterFacade::class,
],
```

### Example: Using `FilterBuilder` via the Facade

[](#example-using-filterbuilder-via-the-facade)

```
use Illuminate\Support\Facades\Storage;
use Marktaborosi\FlysystemFilter\FilterBuilder;
use FlysystemFilter; // Facade alias

Route::get('/filtered-files', function () {
    $listing = Storage::disk('local')->listContents('', true);

    $builder = (new FilterBuilder())
        ->isFile()
        ->group_start()
            ->filenameContains('console')
            ->or()
            ->filenameContains('file')
        ->group_end();

    $filtered = FlysystemFilter::filter($listing, $builder);

    return $filtered->map(fn($i) => $i->path())->toArray();
});
```

### Example: Using a Callable Predicate

[](#example-using-a-callable-predicate)

```
use Illuminate\Support\Facades\Storage;
use League\Flysystem\StorageAttributes;
use FlysystemFilter;

Route::get('/log-files', function () {
    $listing = Storage::disk('local')->listContents('', true);

    // Callable allows custom filter logic without building a `FilterBuilder`
    $callable = static fn(StorageAttributes $item): bool =>
        str_ends_with($item->path(), '.log');

    $filtered = FlysystemFilter::filter($listing, $callable);

    return $filtered->map(fn($i) => $i->path())->toArray();
});
```

### Notes

[](#notes)

- `FlysystemFilter::filter()` is **now an instance method** (since v3.0.0) — the Facade makes it look static in Laravel, but under the hood it is resolved from the container.
- All filtering logic and method signatures remain the same as in standalone usage.
- Non-`StorageAttributes` entries in the listing are automatically skipped.

API Overview
------------

[](#api-overview)

### Filtering Options

[](#filtering-options)

#### General Conditions

[](#general-conditions)

- `isFile()`: Matches file entries.
- `isDirectory()`: Matches directory entries.

#### Path-Based Conditions

[](#path-based-conditions)

- `pathEquals($paths)`: Matches exact paths. Accepts `string` or `array`.
- `pathContains($substrings)`: Matches paths containing specific substrings.
- `pathNotContains($substrings)`: Excludes paths containing any given substrings.
- `pathMatchesRegex($pattern)`: Matches paths using a regular expression.
- `pathStartsWith($prefixes)`: Matches paths starting with specific prefix(es).
- `pathEndsWith($suffixes)`: Matches paths ending with specific suffix(es).

#### Filename-Based Conditions *(excluding extension)*

[](#filename-based-conditions-excluding-extension)

- `filenameEquals($filenames)`: Matches exact filenames (excluding extensions). Accepts `string` or `array`.
- `filenameNotEquals($filenames)`: Excludes filenames that match exactly.
- `filenameContains($substrings)`: Matches filenames containing any of the substrings.
- `filenameNotContains($substrings)`: Excludes filenames containing any of the substrings.
- `filenameStartsWith($prefixes)`: Matches filenames starting with any of the specified prefix(es).
- `filenameEndsWith($suffixes)`: Matches filenames ending with any of the specified suffix(es).
- `filenameMatchesRegex($pattern)`: Matches filenames via regular expression.

#### Basename-Based Conditions *(filename including extension)*

[](#basename-based-conditions-filename-including-extension)

- `basenameEquals($basenames)`: Matches the full filename (including extension) exactly.
- `basenameNotEquals($basenames)`: Excludes files with exact matching basenames.
- `basenameContains($substrings)`: Matches basenames containing any of the substrings.
- `basenameNotContains($substrings)`: Excludes basenames containing any of the substrings.
- `basenameStartsWith($prefixes)`: Matches basenames that start with the given prefix(es).
- `basenameEndsWith($suffixes)`: Matches basenames that end with the given suffix(es).

#### Extension-Based Conditions

[](#extension-based-conditions)

- `extensionEquals($extensions)`: Matches files with one or more exact extensions.
- `extensionNotEquals($extensions)`: Excludes files with the specified extensions.
- `extensionContains($substrings)`: Matches files whose extension contains any given substring.
- `extensionNotContains($substrings)`: Excludes files whose extension contains any given substring.

#### Size-Based Conditions

[](#size-based-conditions)

- `sizeEquals($size)`: Matches files with an exact size.
- `sizeGt($size)`: Matches files larger than a specific size.
- `sizeGte($size)`: Matches files larger than or equal to a specific size.
- `sizeLt($size)`: Matches files smaller than a specific size.
- `sizeLte($size)`: Matches files smaller than or equal to a specific size.
- `sizeBetween($min, $max)`: Matches files within a size range.

📌 **Note**: Size units can be specified as `B`, `K`, `M`, `G`, `T` (e.g., `'512K'`, `'1G'`).

#### Date-Based Conditions

[](#date-based-conditions)

- `lastModifiedBefore($timestamp)`: Matches files modified before a given timestamp or `Carbon` instance.
- `lastModifiedAfter($timestamp)`: Matches files modified after a given timestamp or `Carbon` instance.
- `lastModifiedBetween($start, $end)`: Matches files modified within a date range.

#### Mime-Type Conditions

[](#mime-type-conditions)

- `mimeTypeEquals($mimeTypes)`: Matches files with exact MIME types.
- `mimeTypeNotEquals($mimeTypes)`: Excludes files with specific MIME types.
- `mimeTypeContains($substrings)`: Matches files where the MIME type contains any substring.
- `mimeTypeNotContains($substrings)`: Excludes files whose MIME type contains specific substrings.

📌 **Note**: MIME types are detected from file extensions using `league/mime-type-detection`. No file contents are read.

#### Visibility-Based Conditions

[](#visibility-based-conditions)

- `isPublic()`: Matches files with `'public'` visibility.
- `isPrivate()`: Matches files with `'private'` visibility.
- `visibilityEquals($visibilities)`: Matches files with exact visibility values.
- `visibilityContains($substrings)`: Matches files whose visibility string contains given substring(s).

#### Depth-Based Conditions

[](#depth-based-conditions)

- `depthEquals($depth)`: Matches items with an exact directory depth.
- `depthGt($depth)`: Matches items with a depth greater than the specified value.
- `depthLt($depth)`: Matches items with a depth less than the specified value.

### Logical Operators

[](#logical-operators)

- `and()`: Combines conditions with logical AND.
- `or()`: Combines conditions with logical OR.
- `group_start() / group_end()`: Groups conditions for logical precedence (like parentheses).

Requirements
------------

[](#requirements)

- PHP 8.2 or higher
- League/Flysystem 3.29 or higher

Development
-----------

[](#development)

Run the tests:

```
composer test
```

Contributing
------------

[](#contributing)

Feel free to contribute to the project by submitting issues or pull requests on [GitHub](https://github.com/marktaborosi/flysystem-filter).

License
-------

[](#license)

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

---

> Made with ❤️ by [Mark Taborosi](https://github.com/marktaborosi)

###  Health Score

39

—

LowBetter than 85% of packages

Maintenance62

Regular maintenance activity

Popularity21

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

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 ~50 days

Recently: every ~62 days

Total

6

Last Release

266d ago

Major Versions

v1.1.0 → v2.0.02025-04-30

v2.0.0 → v3.0.02025-08-15

### Community

Maintainers

![](https://www.gravatar.com/avatar/a9198d441036aea902354f6d4f00fb75f7e1e0f9fa696fd282468cfbe4f13c08?d=identicon)[marktaborosi](/maintainers/marktaborosi)

---

Top Contributors

[![marktaborosi](https://avatars.githubusercontent.com/u/33125644?v=4)](https://github.com/marktaborosi "marktaborosi (10 commits)")

---

Tags

phpfilesystemFlysystemfilterleague-flysystemfilter-builderfilesystem-filter

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/marktaborosi-flysystem-filter/health.svg)

```
[![Health](https://phpackages.com/badges/marktaborosi-flysystem-filter/health.svg)](https://phpackages.com/packages/marktaborosi-flysystem-filter)
```

###  Alternatives

[league/flysystem-aws-s3-v3

AWS S3 filesystem adapter for Flysystem.

1.6k263.6M785](/packages/league-flysystem-aws-s3-v3)[league/flysystem-sftp-v3

SFTP filesystem adapter for Flysystem.

6129.6M91](/packages/league-flysystem-sftp-v3)[league/flysystem-ftp

FTP filesystem adapter for Flysystem.

2820.8M100](/packages/league-flysystem-ftp)[league/flysystem-google-cloud-storage

Google Cloud Storage adapter for Flysystem.

2316.7M45](/packages/league-flysystem-google-cloud-storage)[league/flysystem-async-aws-s3

AsyncAws S3 filesystem adapter for Flysystem.

2610.5M30](/packages/league-flysystem-async-aws-s3)[jerodev/flysystem-v3-smb-adapter

SMB adapter for Flysystem v3

1289.9k1](/packages/jerodev-flysystem-v3-smb-adapter)

PHPackages © 2026

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