Download the PHP package gregpriday/gitignore-php without Composer
On this page you can find all versions of the php package gregpriday/gitignore-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download gregpriday/gitignore-php
More information about gregpriday/gitignore-php
Files in gregpriday/gitignore-php
Package gitignore-php
Short Description A PHP Git ignore parser and manager. Useful for general file parsing.
License MIT
Homepage https://github.com/gregpriday/gitignore-php
Informations about the package 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
-
Gitignore Parsing:
Automatically scans your project directory for.gitignorefiles (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.gitignorefiles, 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
Install GitIgnore PHP via Composer:
Usage
Basic Usage
Load a project's gitignore rules and determine whether a file should be ignored:
Using Additional Ignore Files
By default, only .gitignore files are loaded. To include extra ignore files (for example, .ctreeignore), pass an array as the third parameter:
Testing Brace Expansion
The library supports compact rule definitions using brace expansion. For example:
Filtering a Git Repository
Combine GitIgnore PHP with Symfony Finder to list all files that are not ignored:
API Reference
GitIgnoreManager
-
__construct(string $basePath, bool $caseSensitive = true, array $additionalIgnoreFiles = [])
Initializes the manager by scanning the base directory for ignore files. By default, only.gitignoreis loaded; additional files can be specified. -
accept(SplFileInfo $file): bool
Determines whether the specified file should be accepted (i.e. not ignored) based on the loaded rules. matchPattern(string $pattern, string $subject): bool
Checks if the given ignore pattern matches the provided subject string.
PatternConverter
-
convertPatternToRegex(string $pattern): string
Converts a gitignore‑style pattern into a regular expression (without delimiters), handling escapes, wildcards, and character classes. -
expandBraces(string $pattern): array
Recursively expands brace expressions (e.g.*.{js,css,html}) into an array of individual patterns. patternToRegex(string $pattern): string
Converts a gitignore pattern into a complete regular expression with delimiters and anchors, ready for use withpreg_match().
Code Formatting
This project uses Laravel Pint to enforce a consistent coding style. To format your code, run:
Testing
The project includes extensive test coverage using PHPUnit. To run the tests, execute:
or
Contributing
Contributions are welcome! To contribute:
-
Fork the Repository:
Create your own fork and clone it locally. -
Create a New Branch:
Develop your feature or fix on a new branch. -
Follow Coding Standards:
Ensure your code adheres to the Laravel coding style by runningcomposer formatand make sure all tests pass. - Submit a Pull Request:
Provide a clear explanation of your changes in your pull request.
License
GitIgnore PHP is released under the MIT License. See the LICENSE file for details.
GitIgnore PHP provides a comprehensive and flexible toolset for file filtering using gitignore‑style rules. Its advanced pattern support, combined with Symfony Finder integration, makes it ideal for both simple and complex project workflows. Happy coding!