/** * Creates the formatter. * * @param StyleSet $styleSet The style set to use. */ public function __construct(StyleSet $styleSet = null) { $this->innerFormatter = new OutputFormatter(false); if (!$styleSet) { $styleSet = new DefaultStyleSet(); } foreach ($styleSet->toArray() as $tag => $style) { $this->innerFormatter->setStyle($tag, StyleConverter::convert($style)); } }
/** * {@inheritdoc} */ public function format($string, Style $style = null) { if (null !== $style) { $this->innerFormatter->getStyleStack()->push(StyleConverter::convert($style)); } $formatted = $this->innerFormatter->format($string); if (null !== $style) { $this->innerFormatter->getStyleStack()->pop(); } return $formatted; }
/** * @dataProvider getTestCases */ public function testConvert($style, $converted) { $this->assertEquals($converted, StyleConverter::convert($style)); }