Reputation: 1391
I'm trying to use the symfony2 service container.However when I construct each service I want to use some of the variables defined in my controller.I want to know whether that's possible and how to do it.or an alternative if the aforementioned is not possible.
p.s: I'm using the yml service definitions.
$_ws['configurator'] = cmfGetInitObject(); //returns an instance of cmlObj
$_ws['configurator']->setOptions(
array(
'configurationsFolderPath' => realpath(dirname(__FILE__) . '/../configurations'),
'server' => &$_SERVER,
'legacyFormatEnabled' => true
)
);
$_ws['packageManager'] =& $_ws['configurator']->packageManager;
$_ws = $_ws['configurator']->load($_ws); //$_ws['configurator'] again resolves to a cmlObj
this is the array containing the configurations I mentioned.
Upvotes: 0
Views: 47
Reputation: 41954
You can't. The service container is created at the beginning of the request flow, while the controller is executed almost at the end of the flow.
If you really have not access to the required config in the container build phase of the request, you can use setters to set the values in the container and maybe use default values when building the service.
Even better would be to move this out of the controller and inside an event listener.
Upvotes: 1