Conditional output with a Symfony command, depending on the current verbosity level

Published on 2021-09-18 • Modified on 2021-09-18

This snippet shows how to conditionally display stuff with a Symfony command, depending on the current verbosity level. In this case, we can use the isVerbose() function of the OutputInterface. Note that the writeXX() functions of the OutputInterface accept a verbosity level as the second argument, so you don't even have to use an if statement. If you want to test on a given level only, use the OutputInterface::VERBOSITY_ constants.


EOT
            );
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $io = new SymfonyStyle($input, $output);
        $io->title(self::DESCRIPTION);

 More on Stackoverflow   Read the doc  More on the web  Random snippet

  Work with me!