Метод title
Метод title класса SymfonyStyle выводит крупный заголовок в консоли.
Он используется для визуального разделения вывода на смысловые блоки.
Первым параметром передаётся текст заголовка, вторым - подзаголовок,
третьим - цвет фона, четвёртым - цвет текста.
Синтаксис
public function title(string $message, string $subMessage = '', string $style = null): void
Пример
Давайте выведем простой заголовок в консольной команде:
<?php
namespace AppCommand;
use SymfonyComponentConsoleCommandCommand;
use SymfonyComponentConsoleInputInputInterface;
use SymfonyComponentConsoleOutputOutputInterface;
use SymfonyComponentConsoleStyleSymfonyStyle;
class ArticleCommand extends Command
{
protected static $defaultName = 'app:article';
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$io->title('Article section');
return Command::SUCCESS;
}
}
?>
Результат выполнения кода:
"Article section"
Пример
Давайте добавим подзаголовок ко заголовку:
<?php
namespace AppCommand;
use SymfonyComponentConsoleCommandCommand;
use SymfonyComponentConsoleInputInputInterface;
use SymfonyComponentConsoleOutputOutputInterface;
use SymfonyComponentConsoleStyleSymfonyStyle;
class ArticleCommand extends Command
{
protected static $defaultName = 'app:article';
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$io->title('Article section', 'List of articles');
return Command::SUCCESS;
}
}
?>
Результат выполнения кода:
"Article section
List of articles"
Пример
Давайте зададим цвет фона и цвет текста заголовка:
<?php
namespace AppCommand;
use SymfonyComponentConsoleCommandCommand;
use SymfonyComponentConsoleInputInputInterface;
use SymfonyComponentConsoleOutputOutputInterface;
use SymfonyComponentConsoleStyleSymfonyStyle;
class ArticleCommand extends Command
{
protected static $defaultName = 'app:article';
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$io->title('Article section', '', 'green', 'black');
return Command::SUCCESS;
}
}
?>
Результат выполнения кода:
"Article section"
Смотрите также
-
класс
SymfonyStyle,
который оформляет вывод в консоли -
метод
section,
который выводит секцию -
метод
text,
который выводит текст -
метод
newLine,
который выводит пустую строку