Skip to content

[DI][DX] Raise a warning at build-time if lazy=true is encountered, but ProxyManager bridge is not present #27865

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
dkarlovi opened this issue Jul 6, 2018 · 2 comments
Labels
DependencyInjection DX DX = Developer eXperience (anything that improves the experience of using Symfony)

Comments

@dkarlovi
Copy link
Contributor

dkarlovi commented Jul 6, 2018

Description

The docs says:

NOTE
If you don't install the ProxyManager bridge and the ocramius/proxy-manager, the container will just skip over the lazy flag and simply instantiate the service as it would normally do.

This detail is vital to the functionality of lazy services (which might be yours or 3rd-party bundles', relying on it for specific features) and having it silently not working is confusing at best.

I propose DI raises a build-time warning for each lazy=true service if the bridge is not present.

@dkarlovi dkarlovi changed the title [DI] Raise a warning at build-time if lazy=true is encountered, but ProxyManager bridge is not present [DI][DX] Raise a warning at build-time if lazy=true is encountered, but ProxyManager bridge is not present Jul 6, 2018
@nicolas-grekas
Copy link
Member

That should be doable as a compiler log. PR welcome.

@xabbuh xabbuh added DependencyInjection DX DX = Developer eXperience (anything that improves the experience of using Symfony) labels Jul 6, 2018
@nicolas-grekas
Copy link
Member

Implemented in #28060 as a compile-time exception when circular loops are found.

nicolas-grekas added a commit that referenced this issue Aug 8, 2018
…ptions or infinite loops at runtime (nicolas-grekas)

This PR was merged into the 3.4 branch.

Discussion
----------

[DI] Fix false-positive circular ref leading to wrong exceptions or infinite loops at runtime

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #28010, #27865
| License       | MIT
| Doc PR        | -

When circular loops involve references in properties, method calls or configurators, it is possible to properly instantiate the related services.

The current logic is broken: `ContainerBuilder` considers some of these loops as self-referencing circular references, leading to a runtime exception, and in similar situations, `PhpDumper` generates code that turns to infinite loops at runtime 💥. These badly handled situations happen with inlined definitions.

This PR fixes both classes by making them track which references are really part of the constructors' chain, including inline definitions.

It also fixes dumping infinite loops when dumping circular loops involving lazy services while proxy-manager-bridge is not installed.

Commits
-------

e843bb8 [DI] Fix false-positive circular ref leading to wrong exceptions or infinite loops at runtime
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DependencyInjection DX DX = Developer eXperience (anything that improves the experience of using Symfony)
Projects
None yet
Development

No branches or pull requests

3 participants