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-09-12 01:15:00 UTC
README
将 Ray.Di 集成到 Symfony。
入门
1. 使用 Composer require
$ composer require ttskch/ray-di-bundle
2. 在 AppKernel 中注册
// app/AppKernel.php class AppKernel extends Kernel { public function registerBundles() { $bundles = [ // ... new Ttskch\RayDiBundle\TtskchRayDiBundle(), ]; // ... } // ... }
3. 通过 config.yml 进行配置
# app/config/config.yml ttskch_ray_di: module_class: 'Foo\BarModule' # FQCN of your main Ray.Di `module`
使用方法
当您配置 module
时...
class AppModule extends AbstractModule { public function configure() { $this->bind(SomeServiceInterface::class)->to(SomeServiceConcrete::class); } }
然后您可以从 Symfony 容器中获取 injector
,如下所示
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()); } }