ppokatilo / magic-injection-bundle
Magically inject dependencies into services
Installs: 18
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=5.3.2
- doctrine/annotations: 1.*
- symfony/config: ~2.0
- symfony/dependency-injection: ~2.0
- symfony/http-kernel: ~2.0
This package is not auto-updated.
Last update: 2024-12-17 04:09:50 UTC
README
This Symfony2 bundle provides a way to magically inject dependencies into your services. The dependencies will not be available in the constructor. To use it, you need to complete the following steps:
- Add the tag
magic_injection.injectable_service
to the service you wish to inject. The tag takes an optional argument calledtype
, which you can use to group injectable services. - Add the tag
magic_injection.injection_target
to the service which should receive the injected services. - Finally, annotate properties with the
MagicInjection
annotation, which will take an optionaltype
argument that refers to a group of injectable services.
Example usage
- services.yml
services: service.that.will.be.injected: class: Service\MyServiceA tags: - { name: magic_injection.injectable_service, type: my_services } service.that.has.a.dependency: class: Service\MyServiceB tags: - { name: magic_injection.injection_target }
- MyServiceB.php
class MyServiceB { /** * @MagicInjection(type="my_services") * @var \Service\MyServiceA */ private $myServiceA; public function __construct() { assert($this->myServiceA === null); } public function foo() { $this->myServiceA->bar(); } }