https://github.com/phpdocumentor/flyfinder
https://github.com/phpdocumentor/flyfinder
Last synced: 6 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/phpdocumentor/flyfinder
- Owner: phpDocumentor
- License: mit
- Created: 2015-07-10T14:47:39.000Z (over 10 years ago)
- Default Branch: 2.x
- Last Pushed: 2024-11-07T20:07:20.000Z (about 1 year ago)
- Last Synced: 2025-07-08T12:42:56.091Z (7 months ago)
- Language: PHP
- Size: 287 KB
- Stars: 29
- Watchers: 3
- Forks: 7
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://opensource.org/licenses/MIT)
[](https://scrutinizer-ci.com/g/phpDocumentor/FlyFinder/?branch=master)
[](https://scrutinizer-ci.com/g/phpDocumentor/FlyFinder/?branch=master)
[](https://packagist.org/packages/phpDocumentor/FlyFinder)
[](https://packagist.org/packages/phpDocumentor/FlyFinder)
FlyFinder
=========
FlyFinder is a utility class for [Flysystem](http://flysystem.thephpleague.com/) that will enable you to find files
based on certain criteria.
FlyFinder can search for files that are hidden (either because they are hidden files themselves, or because they are
inside a hidden directory), that have a certain extension, or that exist in a certain path.
Flyfinder does *not* return directories themselves... only files.
## Installation
The easiest way to install this library is with [Composer](https://getcomposer.org) using the following command:
$ composer require phpdocumentor/flyfinder
## Examples
Ready to dive in and don't want to read through all that text below? Just consult the [examples](examples) folder and
check which type of action that your want to accomplish.
## Usage
In order to use the FlyFinder plugin you first need a Flyfinder filesystem with an adapter,
for instance the local adapter.
use League\Flysystem\Filesystem;
use League\Flysystem\Local\LocalFilesystemAdapter as LocalAdapter;
use Flyfinder\Finder;
$filesystem = new Filesystem(new LocalAdapter(__DIR__.'/path/to/files/'));
Now you can create the `Finder` instance:
$finder = new Finder($filesystem);
FlyFinder will need specifications to know what to look for. The following specifications are available:
- IsHidden (this specification will return `true` when a file or directory is hidden,
- HasExtension (this specification will return `true` when a file or directory has the specified extension),
- InPath (this specification will return `true` when a file is in the given path. Wildcards are allowed.)
- note that this path should be considered relative to the `$filesystem`'s path
Specifications can be instantiated as follows:
use Flyfinder\Path;
use Flyfinder\Specification\IsHidden;
use Flyfinder\Specification\HasExtension;
use Flyfinder\Specification\InPath;
$isHidden = new IsHidden();
$hasExtension = new HasExtension(['txt']);
$inPath = new InPath(new Path('mydir'));
### Combining specifications
You can search on more criteria by combining the specifications. Specifications can be chained as follows:
`$isHidden->andSpecification($hasExtension)` will find all files and directories that are hidden AND have the given
extension.
`$isHidden->orSpecification($hasExtension)` will find all files and directories that are hidden OR have the given
extension.
`$isHidden->notSpecification` will find all files and directories that are NOT hidden.
You can also make longer chains like this:
`$specification = $inPath->andSpecification($hasExtension)->andSpecification($isHidden->notSpecification());`
This will find all files in the given path, that have the given extension and are not hidden.