PHPackages                             automattic/ignorefile - 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. automattic/ignorefile

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

automattic/ignorefile
=====================

Handle .gitignore style files.

v3.0.2(11mo ago)3211.0k↓58.1%11GPL-2.0-or-laterPHPPHP &gt;=7.2CI passing

Since Dec 22Pushed 2w ago3 watchersCompare

[ Source](https://github.com/Automattic/ignorefile)[ Packagist](https://packagist.org/packages/automattic/ignorefile)[ RSS](/packages/automattic-ignorefile/feed)WikiDiscussions trunk Synced 3d ago

READMEChangelogDependencies (3)Versions (14)Used By (1)

ignorefile
==========

[](#ignorefile)

This small library allows for processing of `.gitignore`-style files in PHP.

It follows the documentation at [gitignore](https://github.com/git/git/blob/5d5b1473453400224ebb126bf3947e0a3276bdf5/Documentation/gitignore.txt), even in cases where git itself does not.

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

[](#installation)

Require using `composer require automattic/ignorefile`.

Usage
-----

[](#usage)

```
// Read a .myignore file.
$ignore = new IgnoreFile();
$ignore->add( file_get_contents( '.myignore' ) );

// Test if a file is ignored.
if ( $ignore->ignores( $filename ) ) {
        echo "$filename is ignored\n";
} else {
        echo "$filename is not ignored\n";
}

// Filter ignored files from an array of files.
$filesToProcess = $ignore->filter( $allFiles );

// Load all .myignore files in a directory tree, then list all non-ignored files.
$ignore = new IgnoreFile();
$iter = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( '.' ) );
foreach ( $iter as $path ) {
        if ( basename( $path ) === '.myignore' ) {
                $ignore->add( file_get_contents( $path ), dirname( $path ) . '/' );
        }
}

$iter = new RecursiveIteratorIterator(
    $ignore->filterIterator( new RecursiveDirectoryIterator( '.' ) )
);
foreach ( $iter as $file ) {
        echo "$file\n";
}
```

### Strict mode

[](#strict-mode)

To match `git`'s behavior, invalid patterns passed to `add()` will be silently ignored. If you'd rather have exceptions thrown, set `$ignore->strictMode` to true.

Known incompatibilities with git
--------------------------------

[](#known-incompatibilities-with-git)

As of git 2.43.0.

The [gitignore documentation](gitignore) refers to [fnmatch](https://pubs.opengroup.org/onlinepubs/9699919799/functions/fnmatch.html) for specifics of `*`, `?`, and bracket expressions. That in turn refers to a few other documents.

PatternDocumentedGit`a.[`Matches `a.[`, per [§2.13.1](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_13_01) "Otherwise, '\[' shall match the character itself."Never matches anything. Git aborts on unclosed bracket.`a.[x`Matches `a.[x`, as above.Never matches anything, as above.`a.[x\\]`Matches `a.[x]`, as above.Never matches anything, as above.`a.[]`Matches `a.[]`, as above.Never matches anything, as above.`a.[\\]`Matches `a.[]`, as above.Never matches anything, as above.`a.[!]`Matches `a.[!]`, as above.Never matches anything, as above.`a.[z-a]`Either matches nothing or is an error, per [§9.3.5](https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_03_05) "If the represented set of collating elements is empty, it is unspecified whether the expression matches nothing, or is treated as invalid."Matches `a.z`.Inspiration
-----------

[](#inspiration)

I needed something similar to [the npm module `ignore`](https://www.npmjs.com/package/ignore) for PHP, but couldn't find one. So I wrote one, copying the fairly comprehensive set of tests to make sure my implementation was accurate.

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance77

Regular maintenance activity

Popularity36

Limited adoption so far

Community25

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 50% 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 ~132 days

Total

11

Last Release

332d ago

Major Versions

v1.0.5 → v2.0.02024-02-07

v2.1.0 → v3.0.02025-01-09

PHP version history (2 changes)v2.0.0PHP &gt;=7.0

v3.0.0PHP &gt;=7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/7c5869ecbb8e0eac7e8b8e0f3cf7bdd8d5fcdc4abc10a72281872c53f8639d44?d=identicon)[automattic](/maintainers/automattic)

---

Top Contributors

[![anomiex](https://avatars.githubusercontent.com/u/1030580?v=4)](https://github.com/anomiex "anomiex (82 commits)")[![tbradsha](https://avatars.githubusercontent.com/u/32492176?v=4)](https://github.com/tbradsha "tbradsha (29 commits)")[![samiff](https://avatars.githubusercontent.com/u/15803018?v=4)](https://github.com/samiff "samiff (9 commits)")[![zinigor](https://avatars.githubusercontent.com/u/374293?v=4)](https://github.com/zinigor "zinigor (6 commits)")[![sdixon194](https://avatars.githubusercontent.com/u/33553323?v=4)](https://github.com/sdixon194 "sdixon194 (4 commits)")[![gmjuhasz](https://avatars.githubusercontent.com/u/36671565?v=4)](https://github.com/gmjuhasz "gmjuhasz (3 commits)")[![coder-karen](https://avatars.githubusercontent.com/u/16754605?v=4)](https://github.com/coder-karen "coder-karen (3 commits)")[![manzoorwanijk](https://avatars.githubusercontent.com/u/18226415?v=4)](https://github.com/manzoorwanijk "manzoorwanijk (2 commits)")[![chihsuan](https://avatars.githubusercontent.com/u/4344253?v=4)](https://github.com/chihsuan "chihsuan (2 commits)")[![ice9js](https://avatars.githubusercontent.com/u/8056203?v=4)](https://github.com/ice9js "ice9js (2 commits)")[![jeherve](https://avatars.githubusercontent.com/u/426388?v=4)](https://github.com/jeherve "jeherve (2 commits)")[![kraftbj](https://avatars.githubusercontent.com/u/88897?v=4)](https://github.com/kraftbj "kraftbj (2 commits)")[![zaerl](https://avatars.githubusercontent.com/u/167611?v=4)](https://github.com/zaerl "zaerl (1 commits)")[![adimoldovan](https://avatars.githubusercontent.com/u/3854374?v=4)](https://github.com/adimoldovan "adimoldovan (1 commits)")[![LiamSarsfield](https://avatars.githubusercontent.com/u/43409125?v=4)](https://github.com/LiamSarsfield "LiamSarsfield (1 commits)")[![adamwoodnz](https://avatars.githubusercontent.com/u/1017872?v=4)](https://github.com/adamwoodnz "adamwoodnz (1 commits)")[![millerf](https://avatars.githubusercontent.com/u/790558?v=4)](https://github.com/millerf "millerf (1 commits)")[![nunyvega](https://avatars.githubusercontent.com/u/16329583?v=4)](https://github.com/nunyvega "nunyvega (1 commits)")[![paulopmt1](https://avatars.githubusercontent.com/u/1044309?v=4)](https://github.com/paulopmt1 "paulopmt1 (1 commits)")[![psealock](https://avatars.githubusercontent.com/u/1922453?v=4)](https://github.com/psealock "psealock (1 commits)")

### Embed Badge

![Health badge](/badges/automattic-ignorefile/health.svg)

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

###  Alternatives

[laravel-enso/forms

JSON-based form builder for Laravel Enso

12354.2k85](/packages/laravel-enso-forms)

PHPackages © 2026

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