8000 [DependencyInjection] Anonymous services are not removed along with the parent service · Issue #30428 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DependencyInjection] Anonymous services are not removed along with the parent service #30428

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
marcospassos opened this issue Mar 3, 2019 · 3 comments
Labels
Bug DependencyInjection Good first issue Ideal for your first contribution! (some Symfony experience may be required) Help wanted Issues and PRs which are looking for volunteers to complete them. Status: Needs Review

Comments

@marcospassos
Copy link
marcospassos commented Mar 3, 2019

Description
When a definition is removed, I expect nested anonymous services to be removed as well:

How to reproduce

<service id="foo_service" class="Foo">
    <argument type="service">
        <service class="Bar">
            <argument>%bar.parameter%</argument>
        </service>
    </argument>
</service>

Extension:

if (!isset($config['option'])) {
    $container->removeDefinition('foo_service');

    return;
}

$container->setParameter('bar.parameter', $config['option']);

Compiling the container without option results in:

The service ".3_Bar~hJYmG7r" has a dependency on a non-existent parameter "bar.parameter".
@sstok
Copy link
Contributor
sstok commented Mar 3, 2019

Due to the way services are parsed by the

private function processAnonymousServices(\DOMDocument $xml, $file, $defaults)
(and Yaml also) Anonymous services are registered as regular services but with a unique id to reference them, so they are not embedded in the actual service that uses them.

I don't think this something that can be fixed (that is the cascade removing of a an Anonymous service), or it would be rather difficult to do so 😅

Edit. Although as these are private they should be removed as unused, I guess the parameter resolving happens bef 8000 ore the private services are removed 🤔 which is something that can be improved.

@marcospassos
Copy link
Author
marcospassos commented Mar 3, 2019

In fact, the nested services will be removed as part of the optimization step. My point is that warning about a missing parameter is completely unexpected.

@nicolas-grekas
Copy link
Member

In a similar situation (AutowiringPass if I'm not wrong), we use Definition::setError() to solve this case. It should work here also if someone wants to have a look.

@nicolas-grekas nicolas-grekas added Help wanted Issues and PRs which are looking for volunteers to complete them. Good first issue Ideal for your first contribution! (some Symfony experience may be required) labels Dec 2, 2019
@fabpot fabpot closed this as completed Jan 7, 2020
fabpot added a commit that referenced this issue Jan 10, 2020
…ss (Islam93)

This PR was merged into the 3.4 branch.

Discussion
----------

[DI] deferred exceptions in ResolveParameterPlaceHoldersPass

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #30428
| License       | MIT
| Doc PR        | n/a

fixes case #30428
implemented as in AutowiringPass

Commits
-------

b3a2173 [DI] deferred exceptions in ResolveParameterPlaceHoldersPass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug DependencyInjection Good first issue Ideal for your first contribution! (some Symfony experience may be required) Help wanted Issues and PRs which are looking for volunteers to complete them. Status: Needs Review
Projects
None yet
Development

No branches or pull requests

6 participants
0