SymfonyStyle

The SymfonyStyle class is a utility class provided by the Symfony framework that helps in creating and formatting command-line output. It provides various methods for displaying information, asking for user input, and formatting text on the command line.

To use the SymfonyStyle class, you need to create an instance of it and pass the input and output objects to its constructor. Here's an example:

use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

class MyCommand extends Command
{
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $io = new SymfonyStyle($input, $output);

        // Displaying information
        $io->writeln('Hello, SymfonyStyle!');

        // Asking for user input
        $name = $io->ask('What is your name?');
        $io->writeln('Hello, '.$name);

        // Formatting text
        $io->title('Important Message');
        $io->section('Section 1');
        $io->writeln('This is a message in section 1.');
        $io->section('Section 2');
        $io->writeln('This is a message in section 2.');

        // Displaying tables
        $headers = ['Name', 'Email'];
        $rows = [
            ['John Doe', '[email protected]'],
            ['Jane Smith', '[email protected]'],
        ];
        $io->table($headers, $rows);

        // Displaying progress bar
        $io->progressStart(100);
        for ($i = 0; $i < 100; $i++) {
            // Do some work
            $io->progressAdvance();
        }
        $io->progressFinish();

        // Displaying success, error, and warning messages
        $io->success('Operation completed successfully.');
        $io->error('An error occurred.');
        $io->warning('Warning: Something might go wrong.');

        // And many more methods for different types of output

        return Command::SUCCESS;
    }
}

This is just a basic example of how to use the SymfonyStyle class. You can explore the Symfony documentation for more information and examples on how to use this class effectively.