Skip to content

Section method only in ConsoleOutputInterface #14550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 22, 2020

Conversation

ybenhssaien
Copy link
Contributor

Since excecute() accepts an instanceof OutputInterface which doesn't contain the method section we have to add a check on ConsoleOutputInterface

Copy link

@Matts Matts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @ybenhssaien

After this change LGTM 👍

@wouterj
Copy link
Member

wouterj commented Nov 16, 2020

Hi @ybenhssaien! Thanks for your PR :)

However, I do not agree completely with the changes. Personally, I don't think it's possible to ever get a non-ConsoleOutputInterface output as argument to execute(), unless you're calling it yourself. In this case, I expect people to have a deeper understanding than the normal documentation audience.

That aside, I think the code you've posted does not work. Later on in the example, $section1->overwrite()/$section1->clear() is used, which only exists on the ConsoleSectionOutput class and not the OutputInterface. If you think it's needed to add something here, I would go for something like if (!$output instanceof ConsoleOutputInterface) { throw new \LogicException('This code should not be reached, only console output is supported.') } at the start of the command.

@ybenhssaien
Copy link
Contributor Author

ybenhssaien commented Nov 17, 2020

Thanks @wouterj for your feedback, I agree with you about throwing exception rather than my suggestion, and clearly people should receive an instance of ConsoleOutputInterface when creating commands inside a Symfony app, may some enterprises internal frameworks which using Console components outside Symfony package depend only on this doc to customize their commands, so I think it is better to mention it (I like the idea of throwing exception) => I will update my PR

This is a test with BufferedOutput (using StreamOutput too since both of them extend Output)
image

@wouterj wouterj changed the base branch from 5.1 to 4.4 November 22, 2020 11:48
wouterj added a commit that referenced this pull request Nov 22, 2020
@wouterj wouterj merged commit 6f13815 into symfony:4.4 Nov 22, 2020
@wouterj
Copy link
Member

wouterj commented Nov 22, 2020

Thank you @ybenhssaien! I've merged this one in 4.4 (the lowest still maintained version) and made the nr of lines a bit smaller: 73f02f1 (the focus of this example is the usage of console sections, so I kept the exception as small as possible to avoid too much distraction)

wouterj added a commit that referenced this pull request Nov 23, 2020
* 4.4:
  Enhancement: Streamline workflow
  GitHub Actions: use docker container for CI build
  Bus restricting with Interfaces
  Security: add example code which Maker Bundle generated
  [#14550] Reduce nr of lines used for exception
  Section method only in ConsoleOutputInterface
wouterj added a commit that referenced this pull request Nov 23, 2020
* 5.1:
  Enhancement: Streamline workflow
  GitHub Actions: use docker container for CI build
  Bus restricting with Interfaces
  Security: add example code which Maker Bundle generated
  [#14550] Reduce nr of lines used for exception
  Section method only in ConsoleOutputInterface
wouterj added a commit that referenced this pull request Nov 23, 2020
* 5.2:
  Enhancement: Streamline workflow
  GitHub Actions: use docker container for CI build
  Bus restricting with Interfaces
  Security: add example code which Maker Bundle generated
  [#14550] Reduce nr of lines used for exception
  Section method only in ConsoleOutputInterface
OskarStark added a commit to OskarStark/symfony-docs that referenced this pull request Nov 25, 2020
* 5.1: (31 commits)
  Fix package name for OvhCloud notifier
  Fix wrong key name
  Enhancement: Streamline workflow
  GitHub Actions: use docker container for CI build
  Bus restricting with Interfaces
  Security: add example code which Maker Bundle generated
  [symfony#14550] Reduce nr of lines used for exception
  Section method only in ConsoleOutputInterface
  Added a new troubleshooting section in the maintainer guide
  Removed duplicated line
  Complete documentation about mailer integration
  [symfony#14083] Revert mailer.headers option in 4.4 - 5.1
  Removed 4.3 versionadded directive
  [symfony#14565] Minor formatting fixes
  Updated getParent() description with the why/when (thanks javier!)
  [Form] Added explicit `getParent()` call in types inheritance mechanism
  Added PHP types to the DI related articles
  Added PHP types to the Form related articles
  Added PHP types to the Doctrine related articles
  Tweak
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants