Download the PHP package devmachine/services-injector-bundle without Composer
On this page you can find all versions of the php package devmachine/services-injector-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download devmachine/services-injector-bundle
More information about devmachine/services-injector-bundle
Files in devmachine/services-injector-bundle
Package services-injector-bundle
Short Description Inject services in controllers using annotations.
License MIT
Homepage https://github.com/lakiboy/devmachine-services-injector-bundle
Informations about the package services-injector-bundle
DevmachineServicesInjectorBundle
Inject services into controllers using annotations on top of SensioFrameworkExtraBundle.
2017 update
As of Symfony 3.3 you can type hint a controller argument to receive a service. Read more
Preambule
There are many ways how to retrieve services in controllers. The easiest one is to extend default container aware Symfony\Bundle\FrameworkBundle\Controller\Controller
controller and use get('<service-id>')
method to get a service. This approach is not favoured by purists as injecting a container considers a bad practice (as they say). It is recommended to inject controller dependencies instead in same way you do with other services.
However, this could lead to far too many injections. Controller#actionOne()
and Controller#actionTwo()
requirements could be completely different. There is a way to mitigate this by implementing controller utilities class. More info in this article by Doctrine author.
About
This bundle tries to satisfy both camps. It injects service locator as a request attribute into controller, configured to retrieve defined set of services. Using this approach there is no need to inject container into controller, and each action can retrieve services it actually needs.
Installation
Add the following to your composer.json:
Register bundle in the kernel: