ttskch / ray-di-bundle
dev-master
2016-09-26 07:18 UTC
Requires
- php: >=5.4.0
- ray/di: ^2.2
- symfony/framework-bundle: ^2.3|^3.0
Requires (Dev)
- phpunit/phpunit: ^4.8
This package is not auto-updated.
Last update: 2024-11-21 01:58:34 UTC
README
Integration of Ray.Di into Symfony.
Getting started
1. Composer-require
$ composer require ttskch/ray-di-bundle
2. Register with AppKernel
// app/AppKernel.php class AppKernel extends Kernel { public function registerBundles() { $bundles = [ // ... new Ttskch\RayDiBundle\TtskchRayDiBundle(), ]; // ... } // ... }
3. Configure via config.yml
# app/config/config.yml ttskch_ray_di: module_class: 'Foo\BarModule' # FQCN of your main Ray.Di `module`
Usage
When you configure your module
...
class AppModule extends AbstractModule { public function configure() { $this->bind(SomeServiceInterface::class)->to(SomeServiceConcrete::class); } }
Then you can get injector
from Symfony container like as below:
class SomeController extends Controller { public function indexAction() { /** @var \Ray\Di\Injector $injector */ $injector = $this->get('ttskch_ray_di.injector'); $someService = $injector->getInstance(SomeServiceInterface::class); return new Response($someService->someMethod()); } }