You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> Note: you can only inject services that you can type-hint and that PHP-DI can provide. Type-hint injection is simple, it simply injects the result of `$container->get(/* the type-hinted class */)`.
96
98
97
-
## Installation
98
-
99
-
```
100
-
composer require php-di/slim-bridge
101
-
```
102
-
103
-
## Usage
104
-
105
-
Instead of using `Slim\App`, simply use `DI\Bridge\Slim\App`:
106
-
107
-
```php
108
-
<?php
109
-
require 'vendor/autoload.php';
110
-
111
-
$app = new \DI\Bridge\Slim\App;
112
-
```
113
-
114
-
You can then use the application [just like a classic Slim application](http://www.slimframework.com/):
115
-
116
-
```php
117
-
use Psr\Http\Message\ServerRequestInterface as Request;
118
-
use Psr\Http\Message\ResponseInterface as Response;
119
-
120
-
$app->get('/hello/{name}', function (Request $request, Response $response) {
121
-
$response->getBody()->write('Hello!');
122
-
return $response;
123
-
});
124
-
125
-
$app->run();
126
-
```
127
-
128
-
You may notice the `DI\Bridge\Slim\App` class is very simple. You can very well create the container yourself and pass it to the constructor of `Slim\App`. Just don't forget to register the [`src/config.php`](src/config.php) file in the container.
129
-
130
-
### Configuring PHP-DI
131
-
132
-
If you want to configure PHP-DI, simply extend the `DI\Bridge\Slim\App` class and override the `configureContainer()` method:
133
-
134
-
```php
135
-
class MyApp extends \DI\Bridge\Slim\App
136
-
{
137
-
protected function configureContainer(ContainerBuilder $builder)
0 commit comments