Org_Heigl\FileFinder

Build Status Code Climate Test Coverage Scrutinizer Code Quality

This library allows to find files from the filesystem that apply to a set of filter-rules. The files are returned in a filelist-object.

Installation

Org_Heigl\FileFinder is installed via composer. Call composer require org_heigl/filefinder from the commandline in your project.

Alternatively you can include the following line in your composer.json inside the require-section:

"org_heigl/filefinder" : "stable"

Usage

Simplest usage would be to add a filter to the FileFinder as well as a directory.

<?php
$finder = new \Org_Heigl\FileFinder\FileFinder();
$finder->addFilter(new \Org_Heigl\FileFinder\Filter\FileExtension('jpg'));
$finder->addDirectory($dir);
$list = $finder->find();
// $list will be an \Org_Heigl\FileFinder\FileList-Object containing all Files with the extension 'jpg' inside $dir

You can also set your own FileList-Object as long as it implements \Org_Heigl\FileFinder\FileListInterface. That would then look like this:

<?php
$finder = new \Org_Heigl\FileFinder\FileFinder();
$finder->addFilter(new \Org_Heigl\FileFinder\Filter\FileExtension('jpg'));
$finder->addDirectory($dir);
$finder->setFileList(new MyPrettyFileList())
$list = $finder->find();
// $list will be the MyPrettyFileList-Object containing all Files with the extension 'jpg' inside ```$dir```

You can also get a mapping of classname to filename for all classes implementing \Iterator underneath the directory $dir using this snippet:

<?php
$finder = new \Org_Heigl\FileFinder\FileFinder();
$finder->addFilter(new \Org_Heigl\FileFinder\Filter\FileExtension('php'));
$finder->addFilter(new \Org_Heigl\FileFinder\Filter\ClassIsInstanceof('\Iterator'));
$finder->setFileList(new \Org_Heigl\FileFinder\ClassMapList());
$finder->addDirectory($dir);
$list = $finder->find();
// $list now contains the classname as key and the filepath as value

The directories added with the FileList::addDirectory()-method will be recursively checked.

The filters have to implement \Org_Heigl\FileFinder\FilterInterface. Therefore you can add your own filters very easily.

Contains

Currently the library contains the following filters and lists:

Filters

Lists

Interfaces

Helpers

License

This library is licensed under the MIT-License.

Issues

You have an issue? Use the Issuetracker to report it and we’ll see for it.