TtskchRayDiBundle
, (*1)
Integration of Ray.Di into Symfony., (*2)
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(),
];
// ...
}
// ...
}
# app/config/config.yml
ttskch_ray_di:
module_class: 'Foo\BarModule' # FQCN of your main Ray.Di `module`
Usage
When you configure your module..., (*3)
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:, (*4)
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());
}
}