$ show symfony/finder
Symfony Finder is a mature PHP library that locates files and directories through a fluent, rules-based API. The implementation is not a monolithic filesystem walker but a composition of small SPL iterator decorators: Finder::getIterator() builds a pipeline containing RecursiveDirectoryIterator, ExcludeDirectoryFilterIterator, depth/type/name/content/size/date filters, custom callbacks, and optional gitignore filtering. Multiple search roots are merged lazily through AppendIterator, and sorting is applied only when requested via SortableIterator. The library also exposes standalone, dependency-free pattern compilers, Glob::toRegex() and Gitignore::toRegex(), which translate glob and gitignore syntax into PCRE strings.
The LLM identified 5 files worth highlighting for reuse:
Converts glob(3)-style patterns into anchored PCRE strings. Handles ** double-star spanning directories, *, ?, brace alternation, escaped metacharacters, strict leading-dot behavior, and wildcard-slash modes. Fully self-contained with no internal imports, so it can be lifted directly into any PHP project needing glob-to-regex translation independent of filesystem walking.
Compiles .gitignore file content into a single PCRE regex that respects comments, trailing-space stripping, root anchoring, directory-only patterns, and negation. A separate method isolates negated patterns. Consecutive patterns are grouped to avoid PCRE nesting limits, and nested negative lookaheads model git's 'last matching rule wins' semantics. Self-contained and reusable in any tool needing gitignore matching.
Wraps any Traversable of \SplFileInfo and applies built-in or callback sorting while preserving original keys. Supports natural, case-insensitive, type, extension, size, atime/ctime/mtime sorts and reverse order; avoids materializing the iterator when no sort is needed. An isolated, reusable key-preserving sorter for file iterators.
Filters files according to recursive .gitignore rules, walking up to the nearest git repository root and correctly handling nested repositories, worktrees, negations, and the rule that paths inside an ignored directory cannot be re-included. Caches parsed .gitignore files and ignored-path decisions to keep large traversals efficient. Depends only on Gitignore and SPL, and demonstrates a rigorous model of gitignore precedence reusable beyond Finder.
Extends SPL RecursiveDirectoryIterator to return SplFileInfo objects enriched with relative paths while working around non-rewindable stream wrappers such as FTP and honoring ignoreUnreadableDirs. Caches rootPath/subPath between iterations to avoid redundant filesystem work. The pattern of augmenting SPL directory iteration with relative-path context is reusable in other traversal tools.