https://github.com/ttskch/ttskchraydibundle
Integration of Ray.Di into Symfony.
https://github.com/ttskch/ttskchraydibundle
Last synced: 10 months ago
JSON representation
Integration of Ray.Di into Symfony.
- Host: GitHub
- URL: https://github.com/ttskch/ttskchraydibundle
- Owner: ttskch
- License: mit
- Created: 2016-02-13T17:07:48.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2016-09-26T07:18:45.000Z (over 9 years ago)
- Last Synced: 2025-02-08T12:16:14.414Z (about 1 year ago)
- Language: PHP
- Homepage:
- Size: 7.81 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# TtskchRayDiBundle
[](https://travis-ci.org/ttskch/TtskchRayDiBundle)
[](https://packagist.org/packages/ttskch/ray-di-bundle)
[](https://packagist.org/packages/ttskch/ray-di-bundle)
Integration of [Ray.Di](https://github.com/ray-di/Ray.Di) into Symfony.
## Getting started
#### 1. Composer-require
```bash
$ composer require ttskch/ray-di-bundle
```
#### 2. Register with AppKernel
```php
// app/AppKernel.php
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = [
// ...
new Ttskch\RayDiBundle\TtskchRayDiBundle(),
];
// ...
}
// ...
}
```
#### 3. Configure via config.yml
```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`...
```php
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:
```php
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());
}
}
```