Every two weeks I send out a newsletter containing lots of interesting stuff for the modern PHP developer. You can expect quick tips, links to interesting tutorials, opinions and packages. Want to learn the cool stuff? Then sign up now!

A better way to style the output of console commands

When creating output from a Symfony based console command you might have created a title using code like this:

$output->writeln('Lorem Ipsum Dolor Sit Amet');

Starting from Symfony 2.7 there’s a nice way to style the output of console commands. This code produces the same output as the example above

$io = new SymfonyStyle($input, $output)
$io->title('Lorem Ipsum Dolor Sit Amet');

There are styles for titles, sections, questions, tables, and so on. Take a look at the documention to learn what’s possible.

Freek Van der Herten is a partner and developer at Spatie, an Antwerp based company that specializes in creating web apps with Laravel. After hours he writes about modern PHP and Laravel on this blog. When not coding he’s probably rehearsing with his kraut rock band.
  • Jason M

    Great post!

    I do believe there is a typo, this was added in version 2.8.