PHP code example of macfja / symfony-console-filechooser

1. Go to this page and download the library: Download macfja/symfony-console-filechooser library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

macfja / symfony-console-filechooser example snippets


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();