Skip to content

[DI] Reduce complexity of autowiring #22256

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
Apr 4, 2017

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented Apr 3, 2017

Q A
Branch? master
Bug fix? no
New feature? no (tweaking existing ones)
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets -
License MIT
Doc PR -
  • optional args are autowired
  • methods with only optional args are autowired
  • use default values of required args when possible

Both first changes remove the behavior delta between constructors and setters, and is expected to me now that things are more explicit. This reduces the "know-how" requirements for using autowiring and is easier to get correct intuitively. The 3rd change plays nice with named args.

// no default value? Then fail
if (!$parameter->isOptional()) {
if (!$parameter->isDefaultValueAvailable()) {
Copy link
Member Author

Choose a reason for hiding this comment

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

as spotted here: #22254 (comment)

Copy link
Member

@stof stof left a comment

Choose a reason for hiding this comment

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

👍

Copy link
Member

@dunglas dunglas left a comment

Choose a reason for hiding this comment

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

👍

@fabpot
Copy link
Member

fabpot commented Apr 3, 2017

@nicolas-grekas I let you merge this one

@nicolas-grekas nicolas-grekas merged commit 146f074 into symfony:master Apr 4, 2017
nicolas-grekas added a commit that referenced this pull request Apr 4, 2017
This PR was merged into the 3.3-dev branch.

Discussion
----------

[DI] Reduce complexity of autowiring

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no (tweaking existing ones)
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

- optional args are autowired
- methods with only optional args are autowired
- default values of required args when possible

Both first changes remove the behavior delta between constructors and setters, and is expected to me now that things are more explicit. This reduces the "know-how" requirements for using autowiring and is easier to get correct intuitively. The 3rd change plays nice with named args.

Commits
-------

146f074 [DI] Reduce complexity of autowiring
@nicolas-grekas nicolas-grekas deleted the di-autow branch April 4, 2017 08:32
@fabpot fabpot mentioned this pull request May 1, 2017
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.

5 participants