I’ve got some services that are being hit with a certain tag in my Symfony2 project that I’d like to use inside of a controller.
As a result, I’m trying to figure out the best way to get them passed to the controller, and thought that perhaps there’s a way to do it with Symfony2’s overall configuration system.
# Inside routing.yml:
my_controller:
pattern: "/path"
defaults {
_controller: Bundle:Controller:action
# The following line is kind of what I'm looking for.
myParam: @my.tag
}
# Inside a services.yml file:
my.service:
class: Bundle\MyService
tags:
- { name: my.tag }
my.otherService:
class: Bundle\MyOtherService
tags:
- { name: my.tag }
Given the two config file examples above, I’d like it so that my instance of “Bundle:Controller:action” receives an array containing instances of “Bundle\MyService” and “Bundle\MyOtherService”.
Thanks!
This discussion on google groups has resulted in a solution. Some of the API however has changed. Namely:
So long as you move the two blocks of code accordingly and implement it correctly, you should be able to get something along the lines of the functionality I want.
Sadly, this isn’t in any way automated by the DIC, but it’s important to note that I do have the requirement of getting everything of a specific tag. Not just from my bundle, but from every bundle ultimately becoming part of the app.