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:

1
2
Finder::create()->files()->name('*.php');
Finder::create()->files()->name('/\.php$/');

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

1
2
Finder::create()->path('some/special/dir');
Finder::create()->path('/^foo\/bar/');

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:

1
Finder::create()->files()->in('src/Symfony/*/*/Resources/translations');

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.