Cover of the book Symfony 5: The Fast Track

Symfony 5: The Fast Track is the best book to learn modern Symfony development, from zero to production. +300 pages showcasing Symfony with Docker, APIs, queues & async tasks, Webpack, SPAs, etc.

New in Symfony 2.2: Finder improvements

The Finder component gives you a nice DSL to let you find files and directories.

Contributed by
Włodzimierz Gajda
in #4739.

Filter by Path

The name() method restricts files by name; it accepts strings, globs, or regexes:


As of Symfony 2.2, you can also restrict files and directories by path, via the path() method, which accepts strings or regexes:


To negate the restriction, use the notName() and notPath() methods.

Learn more about this new feature in the documentation.

Contributed by
Jakub Zalas
in #6531.

Glob Support for the in() method

The in() method tells the Finder to look for files and directories into the passed directories. As of 2.2, you can define these directories as globs:


Documentation is available in the Finder component chapter.

Contributed by
Jean-François Simon
in #4061.

Speedup on some Platforms

Last but not least, and only for some platforms (like Linux, MacOs, and BSD), the Finder performance was greatly improved by converting the criteria to native commands. Have a look at the initial benchmark results that were published when the pull request was submitted.

We need your help for this change as sometimes, the optimized version does not work on some Unix versions; so we need to be sure to exclude those cases and fallback to the PHP adapter. Test on your environment and report if there are any issues.

Help the Symfony project!

As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.


How calling find/findstr/sort/awk is an optimization? Or are the benchs based on the file iterators APIs only?
thanks guys, good job Jakub, man the finder is more versatile now!

Comments are closed.

To ensure that comments stay relevant, they are closed for old posts.