public function testRenderWithIndentation() { $layout = new BlockLayout(); $layout->add(new Paragraph('HEADING 1'))->add(new Paragraph(self::LOREM_IPSUM))->add(new EmptyLine())->add(new LabeledParagraph('Not Aligned', self::LOREM_IPSUM, 1, false))->add(new EmptyLine())->add(new Paragraph('HEADING 2'))->beginBlock()->add(new LabeledParagraph('Label 1', self::LOREM_IPSUM))->add(new LabeledParagraph('Label 2', self::LOREM_IPSUM))->endBlock()->add(new Paragraph('HEADING 3'))->beginBlock()->add(new LabeledParagraph('Longer Label', self::LOREM_IPSUM))->endBlock(); $layout->render($this->io, 4); $expected = <<<'EOF' HEADING 1 Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt Not Aligned Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt HEADING 2 Label 1 Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt Label 2 Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt HEADING 3 Longer Label Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt EOF; $this->assertSame($expected, $this->io->fetchOutput()); }
/** * Renders the "Description" section. * * @param BlockLayout $layout The layout. * @param string $help The help text. */ protected function renderDescription(BlockLayout $layout, $help) { $layout->add(new Paragraph('<b>DESCRIPTION</b>'))->beginBlock()->add(new Paragraph($help))->endBlock()->add(new EmptyLine()); }
/** * Renders the synopsis of a console command. * * @param BlockLayout $layout The layout. * @param ArgsFormat $argsFormat The console arguments to render. * @param string $appName The name of the application binary. * @param string $prefix The prefix to insert. * @param bool $lastOptional Set to `true` if the last command of the * console arguments is optional. This * command will be enclosed in brackets in * the output. */ protected function renderSynopsis(BlockLayout $layout, ArgsFormat $argsFormat, $appName, $prefix = '', $lastOptional = false) { $nameParts = array(); $argumentParts = array(); $nameParts[] = '<u>' . ($appName ?: 'console') . '</u>'; foreach ($argsFormat->getCommandNames() as $commandName) { $nameParts[] = '<u>' . $commandName->toString() . '</u>'; } foreach ($argsFormat->getCommandOptions() as $commandOption) { $nameParts[] = $commandOption->isLongNamePreferred() ? '--' . $commandOption->getLongName() : '-' . $commandOption->getShortName(); } if ($lastOptional) { $lastIndex = count($nameParts) - 1; $nameParts[$lastIndex] = '[' . $nameParts[$lastIndex] . ']'; } foreach ($argsFormat->getOptions(false) as $option) { // \xC2\xA0 is a non-breaking space if ($option->isValueRequired()) { $format = "%s <%s>"; } elseif ($option->isValueOptional()) { $format = "%s [<%s>]"; } else { $format = '%s'; } $optionName = $option->isLongNamePreferred() ? '--' . $option->getLongName() : '-' . $option->getShortName(); $argumentParts[] = sprintf('[' . $format . ']', $optionName, $option->getValueName()); } foreach ($argsFormat->getArguments() as $argument) { $argName = $argument->getName(); $argumentParts[] = sprintf($argument->isRequired() ? '<%s>' : '[<%s>]', $argName . ($argument->isMultiValued() ? '1' : '')); if ($argument->isMultiValued()) { $argumentParts[] = sprintf('... [<%sN>]', $argName); } } $argsOpts = implode(' ', $argumentParts); $name = implode(' ', $nameParts); $layout->add(new LabeledParagraph($prefix . $name, $argsOpts, 1, false)); }