Skip to content
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

Improved param injection #822

Merged
merged 4 commits into from
Jan 1, 2019
Merged

Conversation

greg-1-anderson
Copy link
Member

@greg-1-anderson greg-1-anderson commented Jan 1, 2019

Overview

This pull request:

  • Improves the dependency injection architecture
  • Fixes a bug
  • Adds a feature
  • Breaks backwards compatibility
  • Has tests that cover changes

Summary

The existing Robo DI container adds a reference to the $input and $output objects. Application::run() also takes $input and $output as parameters. What happens, then, if you want to call Application::run() multiple times with different $input and $output objects?

The answer is that some of the code will use the correct $input and $output objects, but other code will use whatever $input and $output were injected into the DI container, which would produce incorrect results. It would be better to simply not have any reference to $input and $output in the DI container at all; however, a lot of objects inject the logger, which needs $output, and a lot of commands implement IOAwareInterface, which has references to both.

This PR allows commands to take a SymfonyStyle object as a parameter, so that they do not need to use $this->io() any longer. Efforts are also made to keep the IO object updated when Application::run() is called for use by legacy applications. Some updates may be needed to "Robo as a Framework" applications in order for the legacy support to work right; however, legacy applications will not behave any worse than they currently do (references to $input and $output for IOAwareInterface objects will come from the DI container if the updates are not made).

Maybe in Robo 2.x we might be able to not inject $input and $output into the DI container at all, and require classes to either use SymfonyStyle parameter injection, or use IOAwareInterface. Direct access to OutputAwareInterface / InputAwareInterface is deprecated.

We also use the logger manager to remove references to $output from the logger. We create a logger at Application::run() time, when $output is available, and add that to the logger manager.

@greg-1-anderson greg-1-anderson merged commit 5737c84 into master Jan 1, 2019
@greg-1-anderson greg-1-anderson deleted the improved-param-injection branch October 17, 2019 04:05
greg-1-anderson added a commit that referenced this pull request Oct 27, 2019
greg-1-anderson added a commit that referenced this pull request Oct 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant