Archives


Master Symfony2 fundamentals

Be trained by SensioLabs experts (2 to 6 day sessions -- French or English).
trainings.sensiolabs.com

Discover the SensioLabs Support

Access to the SensioLabs Competency Center for an exclusive and tailor-made support on Symfony
sensiolabs.com

Fabien Potencier
New in Symfony 2.2: Finder improvements
by Fabien Potencier – February 14, 2013 – 2 comments

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.

Comments RSS

  • Pierre Joye
    #1 Pierre Joye said on the 2013/02/14 at 10:59
    How calling find/findstr/sort/awk is an optimization? Or are the benchs based on the file iterators APIs only?
  • Luis Cordova
    #2 Luis Cordova said on the 2013/02/17 at 04:04
    thanks guys, good job Jakub, man the finder is more versatile now!