PHPackages                             gregpriday/gitignore-php - 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. gregpriday/gitignore-php

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

gregpriday/gitignore-php
========================

A PHP Git ignore parser and manager. Useful for general file parsing.

1.0.0(1y ago)111MITPHPPHP ^8.2

Since Feb 27Pushed 1y ago1 watchersCompare

[ Source](https://github.com/gregpriday/gitignore-php)[ Packagist](https://packagist.org/packages/gregpriday/gitignore-php)[ Docs](https://github.com/gregpriday/gitignore-php)[ RSS](/packages/gregpriday-gitignore-php/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelogDependencies (3)Versions (3)Used By (0)

GitIgnore PHP
=============

[](#gitignore-php)

GitIgnore PHP is a lightweight yet powerful PHP library for parsing and managing gitignore‑style rules. It provides a robust engine to interpret `.gitignore` patterns—including advanced brace expansion, recursive wildcard matching, negation rules, and configurable case sensitivity. Use GitIgnore PHP to filter files in a repository based on ignore rules, integrate with file processing systems, or build custom file parsers.

---

Features
--------

[](#features)

- **Gitignore Parsing:**
    Automatically scans your project directory for `.gitignore` files (and optionally additional ignore files) and loads their rules.
- **Advanced Glob Pattern Support:**
    Handles standard wildcards:

    - `*` – Matches any sequence of characters (except directory separators).
    - `**` – Matches across directory boundaries.
    - `?` – Matches any single character.
- **Brace Expansion:**
    Write compact rules such as `*.{js,css,html}` that expand to multiple patterns (`*.js`, `*.css`, and `*.html`). Nested brace expressions are also supported.
- **Negation and Rule Precedence:**
    Supports negation rules (using `!`) and complex negation chains so that you can re‑include files that might be excluded by earlier rules. Rules are applied hierarchically based on their directory depth.
- **Directory‑only Rules:**
    Patterns ending with a slash (e.g. `build/`) mark directories (and all their contents) as ignored.
- **Configurable Case Sensitivity:**
    Choose between case‑sensitive or case‑insensitive matching via the constructor.
- **Multiple Ignore Files:**
    While the default is to load `.gitignore` files, you can specify additional files (e.g. `['.ctreeignore']`) to merge extra rules.
- **Seamless Symfony Finder Integration:**
    Designed to work in tandem with Symfony's Finder component, making it easy to filter entire file sets.

---

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

[](#installation)

Install GitIgnore PHP via Composer:

```
composer require gregpriday/gitignore-php
```

---

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

Load a project's gitignore rules and determine whether a file should be ignored:

```
