phpdocumentor/flyfinder
Flyfinder is a lightweight Finder component for phpDocumentor, built on Symfony Finder. It locates files and directories with a fluent API, supports glob patterns, ignore rules, and custom iterators—ideal for scanning project trees in tools and build pipelines.
Start by installing the package via Composer:
composer require phpdocumentor/flyfinder
The primary entry point is the Flyfinder class. Its simplest use case is offering a keyboard-navigable fuzzy picker over an array of strings—like file paths or command names:
use phpDocumentor\FlyFinder\Flyfinder;
$items = ['config/app.php', 'src/Kernel.php', 'routes/web.php', 'tests/Feature/ExampleTest.php'];
$finder = new Flyfinder($items);
$selected = $finder->run();
echo "You selected: {$selected}\n";
Key first steps:
examples/ directory in the repo for concrete, minimal scripts.php examples/files.php to see fuzzy file selection in action.Use Flyfinder to let users pick files interactively in config generators, scaffolding tools, or migration helpers:
use phpDocumentor\FlyFinder\Flyfinder;
use phpDocumentor\FlyFinder\Source\FileSystemSource;
$source = new FileSystemSource(__DIR__ . '/src', ['php', 'yaml'], recursive: true);
$finder = new Flyfinder($source);
$selected = $finder->run();
Build a self-documenting CLI tool that lets users choose from available commands:
$commands = ['make:migration', 'db:seed', 'queue:work', 'optimize:clear'];
$finder = new Flyfinder($commands);
$cmd = $finder->run();
Implement phpDocumentor\FlyFinder\Source\SourceInterface to support dynamic or remote data (e.g., API endpoints, Git refs):
class GitBranchesSource implements SourceInterface {
public function all(): array {
return array_filter(explode("\n", trim(shell_exec('git branch --format="%(refname:short)"'))));
}
}
$finder = new Flyfinder(new GitBranchesSource());
Use within a Command::execute() to offer interactive selection:
protected function execute(InputInterface $input, OutputInterface $output): int {
$output->write('Select environment: ');
$envs = ['local', 'staging', 'prod'];
$choice = (new Flyfinder($envs))->run();
$output->writeln("Selected: {$choice}");
// … proceed with action
}
FileSystemSource for large directory trees—it optimizes path scanning and excludes large files by default.$finder->setCaseSensitive(false) for user-friendliness.php script.php won’t behave in pipes or cron). Use posix_isatty(STDIN) to guard before calling run().chcp 65001). Non-printable characters may break the UI—sanitize inputs.error_reporting(E_ALL)—Flyfinder uses set_exception_handler() internally for graceful handling.Flyfinder to override filter() (e.g., custom scoring) or render() for themed UI (e.g., dark/light mode).SourceInterface or wrap Flyfinder in a service so tests can inject a static array—don’t rely on interactive prompts in CI.Esc, Flyfinder returns null. Always handle this explicitly to avoid silent failures.How can I help you explore Laravel packages today?