function SymfonyStyle::createBlock
1 call to SymfonyStyle::createBlock()
- SymfonyStyle::block in vendor/
symfony/ console/ Style/ SymfonyStyle.php - Formats a message as a block of text.
File
-
vendor/
symfony/ console/ Style/ SymfonyStyle.php, line 400
Class
- SymfonyStyle
- Output decorator helpers for the Symfony Style Guide.
Namespace
Symfony\Component\Console\StyleCode
private function createBlock(iterable $messages, ?string $type = null, ?string $style = null, string $prefix = ' ', bool $padding = false, bool $escape = false) : array {
$indentLength = 0;
$prefixLength = Helper::width(Helper::removeDecoration($this->getFormatter(), $prefix));
$lines = [];
if (null !== $type) {
$type = \sprintf('[%s] ', $type);
$indentLength = Helper::width($type);
$lineIndentation = str_repeat(' ', $indentLength);
}
// wrap and add newlines for each element
$outputWrapper = new OutputWrapper();
foreach ($messages as $key => $message) {
if ($escape) {
$message = OutputFormatter::escape($message);
}
$lines = array_merge($lines, explode(\PHP_EOL, $outputWrapper->wrap($message, $this->lineLength - $prefixLength - $indentLength, \PHP_EOL)));
if (\count($messages) > 1 && $key < \count($messages) - 1) {
$lines[] = '';
}
}
$firstLineIndex = 0;
if ($padding && $this->isDecorated()) {
$firstLineIndex = 1;
array_unshift($lines, '');
$lines[] = '';
}
foreach ($lines as $i => &$line) {
if (null !== $type) {
$line = $firstLineIndex === $i ? $type . $line : $lineIndentation . $line;
}
$line = $prefix . $line;
$line .= str_repeat(' ', max($this->lineLength - Helper::width(Helper::removeDecoration($this->getFormatter(), $line)), 0));
if ($style) {
$line = \sprintf('<%s>%s</>', $style, $line);
}
}
return $lines;
}