Skip to content

Fix decoration of private services #17649

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

Closed
wants to merge 1 commit into from
Closed

Fix decoration of private services #17649

wants to merge 1 commit into from

Conversation

blazarecki
Copy link

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

This PR allow to decorate private service.
The alternative is to not remove private aliases which are not use elsewhere.

What do you think ?

@blazarecki blazarecki changed the title Fix decoration of private service Fix decoration of private services Feb 2, 2016
@stof
Copy link
Member

stof commented Feb 2, 2016

Please describe the issue you are facing. This change looks wrong to me. When decorating a private service, the service defined for this id must stay private.

$container->compile();

try {
$container->getAlias('foo');
Copy link
Member

Choose a reason for hiding this comment

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

getting aliases after compilation does not make sense. getAlias is not a runtime usage of the container (it is not part of the ContainerInterface).
So this test does not cover a supported usage of the component.

@dunglas
Copy link
Member

dunglas commented Feb 2, 2016

@stof currently it's not possible to decorate a private factory service:

services:
    foo_factory:
        class: 'AppBundle\FooFactory'
        public: false

    foo_factory_decorator:
        class: 'AppBundle\FooFactoryDecorator'
        public: false
        arguments: [ '@foo_factory_decorator.inner' ]
        decorates: 'foo_factory'

    foo:
        class:  'AppBundle\Foo'
        factory: [ '@foo_factory', 'createFoo' ]

The decorator pass create a private alias and it is never made public, and is then removed. This "fix" is naive but works, however it probably create some side effects.
A better fix would be to resolve the alias.

@dunglas
Copy link
Member

dunglas commented Feb 2, 2016

We should probably be checked if an alias is used as a factory in RemoveUnusedDefinitionsPass.

@stof
Copy link
Member

stof commented Feb 2, 2016

@dunglas there is currently a bug in stable versions with using private aliases as a factory service. This is totally unrelated to the usage of decoration (it happens with any private alias) and has already been fixed in all maintained branches 1 week ago (the issue has been detected by a change in FOSUserBundle).

@dunglas
Copy link
Member

dunglas commented Feb 2, 2016

@stof Thanks this is exactly the fix we need. (The related PR is #17554).

@stof
Copy link
Member

stof commented Feb 2, 2016

OK, so I'm closing this PR as the actual issue is already fixed in dev versions

@stof stof closed this Feb 2, 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.

4 participants