File tree Expand file tree Collapse file tree 1 file changed +53
-1
lines changed Expand file tree Collapse file tree 1 file changed +53
-1
lines changed Original file line number Diff line number Diff line change 5
5
## Installation
6
6
7
7
```
8
- $ composer require php-di/slim-bridge
8
+ composer require php-di/slim-bridge
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ Instead of using ` Slim\App ` , simply use ` DI\Bridge\Slim\App ` :
14
+
15
+ ``` php
16
+ <?php
17
+ require 'vendor/autoload.php';
18
+
19
+ $app = new \DI\Bridge\Slim\App;
20
+ ```
21
+
22
+ You can then use the application [ just like a classic Slim application] ( http://www.slimframework.com/ ) :
23
+
24
+ ``` php
25
+ use Psr\Http\Message\ServerRequestInterface as Request;
26
+ use Psr\Http\Message\ResponseInterface as Response;
27
+
28
+ $app->get('/hello/{name}', function (Request $request, Response $response) {
29
+ $response->getBody()->write("Hello!");
30
+ return $response;
31
+ });
32
+
33
+ $app->run();
34
+ ```
35
+
36
+ ### Configuring PHP-DI
37
+
38
+ If you want to configure PHP-DI, simply extend the ` DI\Bridge\Slim\App ` class and override the ` configureContainer() ` method:
39
+
40
+ ``` php
41
+ class MyApp extends \DI\Bridge\Slim\App
42
+ {
43
+ protected function configureContainer(ContainerBuilder $builder)
44
+ {
45
+ $builder->addDefinitions(__DIR__ . 'my-config-file.php');
46
+ }
47
+ }
48
+
49
+ $app = new MyApp;
50
+ ```
51
+
52
+ Or if you are using PHP 7 you can use anonymous classes:
53
+
54
+ ``` php
55
+ $app = new class() extends \DI\Bridge\Slim\App {
56
+ protected function configureContainer(ContainerBuilder $builder)
57
+ {
58
+ $builder->addDefinitions(__DIR__ . 'my-config-file.php');
59
+ }
60
+ };
9
61
```
You can’t perform that action at this time.
0 commit comments