Skip to content

Commit 6f13815

Browse files
committed
minor #14550 Section method only in ConsoleOutputInterface (ybenhssaien)
This PR was submitted for the 5.1 branch but it was squashed and merged into the 4.4 branch instead. Discussion ---------- Section method only in ConsoleOutputInterface Since `excecute()` accepts an instanceof `OutputInterface` which doesn't contain the method [`section`](https://github.com/symfony/symfony/blob/5.1/src/Symfony/Component/Console/Output/ConsoleOutputInterface.php#L31) we have to add a check on `ConsoleOutputInterface` <!-- If your pull request fixes a BUG, use the oldest maintained branch that contains the bug (see https://symfony.com/releases for the list of maintained branches). If your pull request documents a NEW FEATURE, use the same Symfony branch where the feature was introduced (and `5.x` for features of unreleased versions). --> Commits ------- 4440725 Section method only in ConsoleOutputInterface
2 parents b73b941 + 4440725 commit 6f13815

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

console.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,18 @@ which returns an instance of
181181
{
182182
protected function execute(InputInterface $input, OutputInterface $output)
183183
{
184+
// The section() method is only available in classes that implement ConsoleOutputInterface
185+
if (!$output instanceof ConsoleOutputInterface) {
186+
throw new LogicException(sprintf(
187+
'This command accepts only an instance of "%s", an instance of "%s" is given',
188+
ConsoleOutputInterface::class,
189+
\get_class($output)
190+
));
191+
}
192+
184193
$section1 = $output->section();
185194
$section2 = $output->section();
195+
186196
$section1->writeln('Hello');
187197
$section2->writeln('World!');
188198
// Output displays "Hello\nWorld!\n"

0 commit comments

Comments
 (0)