Skip to content

Commit a666cd5

Browse files
committed
Add documentation
1 parent 83f301b commit a666cd5

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

README.md

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,57 @@
55
## Installation
66

77
```
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+
};
961
```

0 commit comments

Comments
 (0)