macfja/symfony-console-filechooser

适用于 Symfony 控制台的文件选择器助手(支持自动完成功能)

1.0.0 2018-10-21 12:14 UTC

This package is auto-updated.

Last update: 2024-09-22 01:52:17 UTC


README

该库为任何 Symfony 控制台应用程序提供文件选择器功能。它支持在目录中进行导航的自动完成功能。

安装

Composer

composer require macfja/symfony-console-filechooser

使用

use MacFJA\Symfony\Console\Filechooser\FilechooserHelper;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

$app = new Application();

// Adding the helper to Symfony Console Application
$app->getHelperSet()->set(new FilechooserHelper());

$app->register('ask-path')->setCode(function (InputInterface $input, OutputInterface $output) use ($app) {
    // ask and validate the answer
    $dialog = $app->getHelperSet()->get('filechooser');
    $filter = new \MacFJA\Symfony\Console\Filechooser\FileFilter('Where is your file? ');
    $path = $dialog->ask($input, $output, $filter);
    $output->writeln(sprintf('You have just entered: %s', $path));
});

$app->run();