-
Notifications
You must be signed in to change notification settings - Fork 11
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
Symfony container entries can reference PHP-DI's entries #4
Conversation
Exactly what I needed :D |
|
This is awesome. Just to clarify, the at symbol indicates this is a class name and will be coming from PHP DI container? |
@mtotheikle the Here in my example it's a class name, and since PHP-DI uses "autowiring", container entries are class names (because they are auto-detected, but it's not mandatory at all). So yes, in that example the dependency will be provided by PHP-DI. To be more explicit: # Symfony
services:
foo:
class: My\Service
arguments: [ "@bar", "@abc" ]
bar:
class: My\Other\Service <?php
return [
'abc' => DI\object('Some\Other\Class'),
];
|
I have added a
The config: services:
foo:
class: Acme\DemoBundle\Service\FooService
arguments: [ "@Acme\DemoBundle\Service\BarService" ] It seems Symfony's container lowercases every entry name, and then when PHP-DI tries to load I'm still looking for a solution… |
@mnapoli I totally overlooked that the at symbol was indicating to Symfony that that variable is a service. I've worked with Symfony YAML configuration a lot and when I saw your first comment it just threw me off cause I was thinking it was special to PHP-DI as I was trying to figure out the specific changes you made to make this possible. The DebugClassLoader gets enabled by calling Symfony\Component\Debug\Debug::enable(..) in most systems, which to me means that this is going to require some sort of PR to Symfony |
@mtotheikle thanks for the help, this is indeed that. If I comment out So we have 3 options:
The 3rd option seems more practical but it means a class to maintain in sync with Symfony. Doing a PR to Symfony will take too much time, and it will probably never get accepted as long as it doesn't benefits Symfony itself. I don't want to get my hopes up on this :/ What do you guys think? |
My 2 cents:
I don't really like this option - what functionality/transparency is lost by removing this?
what functionality/transparency is lost by removing this?
This seems like the better option |
bb4f90d
to
03b59e0
Compare
03b59e0
to
2ef4b0d
Compare
I've rebased everything and I'm planning this for the 2.0 release (which will require PHP-DI 5 and Symfony 3). Conclusion about the issues mentioned in this thread:
Both are not serious issues, only tools for development. I will implement a workaround for the first one to avoid losing the feature. For the second, I don't see one for now, but it shouldn't be a problem it's just a helper for debugging. Merging on master, I'll tag a beta version today. |
Symfony entires can reference PHP-DI entries. This means complete interoperability between the 2 containers! For the record, PHP-DI entires can already reference Symfony's entries.
That's the solution if you need to use tags (e.g. voters, …) for a specific service -> you define it in Symfony (YAML) and you can still inject PHP-DI services into it.
For example:
Here
My\Other\Service
is a service that PHP-DI will provide (not Symfony).And the whole thing is even easier than before. Currently, what you have to do:
Now with this branch, you only do this:
Warnings
CheckExceptionOnInvalidReferenceBehaviorPass
compiler pass.It checked for unknown references, and since it doesn't know about PHP-DI's entries, they are "unknown references" to it, so it throws exceptions.
I tried to replace it with a custom compiler pass (that would look into PHP-DI too), but PHP-DI is not built yet when Symfony's container is being compiled, so it doesn't seem really possible.
So is that really bad to have removed that compiler pass? Is that worth it? To be discussed.
Kernel
class instead of Symfony's one. I don't see that as a problem, is it?Feedback more than welcome, ping @tentacode