doc

Page 42

Chapter 11

Formatter Helper The Formatter helpers provides functions to format the output with colors. You can do more advanced things with this helper than you can in Coloring the Output. The FormatterHelper1 is included in the default helper set, which you can get by calling getHelperSet()2: Listing 11-1

1 $formatter = $this->getHelperSet()->get('formatter');

The methods return a string, which you'll usually render to the console by passing it to the OutputInterface::writeln3 method.

Print Messages in a Section Symfony offers a defined style when printing a message that belongs to some "section". It prints the section in color and with brackets around it and the actual message to the right of this. Minus the color, it looks like this: Listing 11-2

1 [SomeSection] Here is some message related to that section

To reproduce this style, you can use the formatSection()4 method: Listing 11-3

1 $formattedLine = $formatter->formatSection( 2 'SomeSection', 3 'Here is some message related to that section' 4 ); 5 $output->writeln($formattedLine);

1. http://api.symfony.com/2.2/Symfony/Component/Console/Helper/FormatterHelper.html 2. http://api.symfony.com/2.2/Symfony/Component/Console/Command/Command.html#getHelperSet() 3. http://api.symfony.com/2.2/Symfony/Component/Console/Output/OutputInterface.html#writeln() 4. http://api.symfony.com/2.2/Symfony/Component/Console/Helper/FormatterHelper.html#formatSection()

PDF brought to you by generated on March 17, 2013

Chapter 11: Formatter Helper | 42


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.