Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[DependencyInjection] A decorated service should not keep the autowiring types #20267

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

Conversation

chalasr
Copy link
Member

@chalasr chalasr commented Oct 21, 2016

Q A
Branch? 2.8
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #20260 (comment)
License MIT
Doc PR n/a

When decorating a service which is not abstract and has autowiring_types, the decorator should be the one used for autowiring methods of autowired services, so we should explicitly empty them on the decorated definition after merged them into the child. See #20260 (comment) for a use case where we are forced to manually empty the decorated service's autowiring_types.

@dunglas
Copy link
Member

dunglas commented Oct 22, 2016

Status: Reviewed

👍

@xabbuh
Copy link
Member

xabbuh commented Oct 22, 2016

This patch is for parent/child definitions. Do we have the same issue for service decoration (as handled in the DecoratorServicePass)?

@chalasr
Copy link
Member Author

chalasr commented Oct 22, 2016

@xabbuh This patch concerns service decoration, not parent/child (abstract services). In fact the ResolveDefinitionTemplatesPass is responsible of resolving/merging definitions for both parent/child and decorated/decorator services, as both are using DefinitionDecorator.

Here we are explicitly ignoring abstract services, because only decorated services (corresponding to %service_id% in decorates: %service_id%) must loose autowiring types, otherwise it is always this one which is used for autowiring services (the decorated instead of the decorator).

Applying this patch to parent/child definitions (removing autowiring types from the abstract parent def) would mean that only the first child of the abstract service inherit the autowiring types, that is not what we want.

Note that this issue is very specific to autowiring types.

@chalasr chalasr changed the title [DependencyInjection] A non-abstract service should not keep the autowiring types if decorated [DependencyInjection] A decorated service should not keep the autowiring types Oct 22, 2016
@chalasr chalasr force-pushed the fix/decorated_should_not_keep_autowiring_types branch 3 times, most recently from 5343373 to a1b0814 Compare October 22, 2016 10:49
@chalasr
Copy link
Member Author

chalasr commented Oct 22, 2016

@xabbuh You are totally right, I was not at the right place. It must indeed be done in the DecoratorServicePass. I made the changes and tested the patch on #20260, it works. Thanks!

Status: needs review

@chalasr
Copy link
Member Author

chalasr commented Oct 22, 2016

Failed builds are unrelated (Twig).

@@ -57,6 +57,7 @@ public function process(ContainerBuilder $container)
$public = $decoratedDefinition->isPublic();
$decoratedDefinition->setPublic(false);
$decoratedDefinition->setTags(array());
$decoratedDefinition->setAutowiringTypes(array());
Copy link
Member

Choose a reason for hiding this comment

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

I think we should first add the old value to the decorating service. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed, done

@@ -142,6 +142,25 @@ public function testProcessMovesTagsFromDecoratedDefinitionToDecoratingDefinitio
$this->assertEquals(array('name' => 'bar'), $container->getDefinition('baz')->getTags());
}

public function testDecoratedServiceLoosesAutowiringTypes()
Copy link
Member

Choose a reason for hiding this comment

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

loses

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

@chalasr chalasr force-pushed the fix/decorated_should_not_keep_autowiring_types branch 2 times, most recently from c43301e to 963d0c5 Compare October 23, 2016 09:03
@chalasr chalasr force-pushed the fix/decorated_should_not_keep_autowiring_types branch from 963d0c5 to 5951378 Compare October 23, 2016 09:04
@fabpot
Copy link
Member

fabpot commented Oct 23, 2016

Thank you @chalasr.

@fabpot fabpot merged commit 5951378 into symfony:2.8 Oct 23, 2016
fabpot added a commit that referenced this pull request Oct 23, 2016
…the autowiring types (chalasr)

This PR was merged into the 2.8 branch.

Discussion
----------

[DependencyInjection] A decorated service should not keep the autowiring types

| Q             | A
| ------------- | ---
| Branch?       | 2.8
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #20260 (comment)
| License       | MIT
| Doc PR        | n/a

When decorating a service which is not abstract and has `autowiring_types`, the decorator should be the one used for autowiring methods of autowired services, so we should explicitly empty them on the decorated definition after merged them into the child. See  #20260 (comment) for a use case where we are forced to manually empty the decorated service's `autowiring_types`.

Commits
-------

5951378 A decorated service should not keep the autowiring types
@chalasr chalasr deleted the fix/decorated_should_not_keep_autowiring_types branch October 23, 2016 16:10
@fabpot fabpot mentioned this pull request Oct 27, 2016
@fabpot fabpot mentioned this pull request Oct 27, 2016
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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.