8000 [DI] Add "factory" support to named args and autowiring by nicolas-grekas · Pull Request #22277 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DI] Add "factory" support to named args and autowiring #22277

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
Q A
Branch? 3.3
Bug fix? yes
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets -
License MIT
Doc PR -

To me, factories are expected to work named arguments.
Doing so also unlocks supporting them when autowiring, and will benefit #22187 soon.

@nicolas-grekas nicolas-grekas added this to the 3.3 milestone Apr 4, 2017
* @param Definition $definition
* @param bool $required
*
* @return \ReflectionFunctionAbstract
Copy link
Contributor

Choose a reason for hiding this comment

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

|null?

Copy link
Member Author

Choose a reason for hiding this comment

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

yup, fixed

} elseif (null === $class) {
$class = $definition->getClass();
}
if ('__construct' === $method) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it really belong to this method? Shouldn't it be in CheckDefinitionValidityPass instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

this is required to prevent a potential infinite loop

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, good point too :) It should still be added in CheckDefinitionValidityPass imo though.

if ($constructor = $reflectionClass->getConstructor()) {
array_unshift($methodCalls, array($constructor->name, $value->getArguments()));
if ($constructor = $this->getConstructor($value, false)) {
array_unshift($methodCalls, array($constructor, $value->getArguments()));
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't we keep ->name to remove the dedicated case, line 183 (https://github.com/symfony/symfony/pull/22277/files#diff-62df969ae028c559d33ffd256de1ac49R183)?

Copy link
Member Author

Choose a reason for hiding this comment

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

nope we can't, because when a factory is used, a simple string is not enough to reference the target

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, good point 👍

@fabpot
Copy link
Member
fabpot commented Apr 4, 2017

Thank you @nicolas-grekas.

@fabpot fabpot merged commit 27470de into symfony:master Apr 4, 2017
fabpot added a commit that referenced this pull request Apr 4, 2017
…g (nicolas-grekas)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[DI] Add "factory" support to named args and autowiring

| Q             | A
| ------------- | ---
| Branch?       | 3.3
| Bug fix?      | yes
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

To me, factories are expected to work named arguments.
Doing so also unlocks supporting them when autowiring, and will benefit #22187 soon.

Commits
-------

27470de [DI] Add "factory" support to named args and autowiring
@nicolas-grekas nicolas-grekas deleted the di-factory branch April 4, 2017 19:05
@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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0