Skip to content

Commit 29f8d4f

Browse files
committed
Move the documentation to PHP-DI's website
1 parent 11e3a33 commit 29f8d4f

File tree

1 file changed

+4
-106
lines changed

1 file changed

+4
-106
lines changed

README.md

Lines changed: 4 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ This package configures Slim 3 to work with the [PHP-DI container](http://php-di
44

55
[![Build Status](https://travis-ci.org/PHP-DI/Slim-Bridge.svg?branch=master)](https://travis-ci.org/PHP-DI/Slim-Bridge)
66

7+
The full documentation is here: **http://php-di.org/doc/frameworks/slim.html**
8+
79
## Why?
810

911
### PHP-DI as a container
@@ -94,110 +96,6 @@ $app->get('/', function (ResponseInterface $response, Twig $twig) {
9496

9597
> 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 */)`.
9698
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)
138-
{
139-
$builder->addDefinitions(__DIR__ . 'my-config-file.php');
140-
}
141-
}
142-
143-
$app = new MyApp;
144-
```
145-
146-
Or if you are using PHP 7 you can use anonymous classes:
147-
148-
```php
149-
$app = new class() extends \DI\Bridge\Slim\App {
150-
protected function configureContainer(ContainerBuilder $builder)
151-
{
152-
$builder->addDefinitions(__DIR__ . 'my-config-file.php');
153-
}
154-
};
155-
```
156-
157-
Have a look at [configuring PHP-DI](http://php-di.org/doc/container-configuration.html) for more details.
99+
## Documentation
158100

159-
### Twig
160-
161-
In order to get you started easily, here is how you can install the Twig extension for Slim:
162-
163-
- install the [Twig-View](https://github.com/slimphp/Twig-View) package:
164-
165-
```
166-
composer require slim/twig-view
167-
```
168-
- configure the `Twig` class in PHP-DI (taken from [the package's documentation](https://github.com/slimphp/Twig-View#usage)):
169-
170-
```php
171-
class MyApp extends \DI\Bridge\Slim\App
172-
{
173-
protected function configureContainer(ContainerBuilder $builder)
174-
{
175-
$definitions = [
176-
177-
\Slim\Views\Twig::class => function (ContainerInterface $c) {
178-
$twig = new \Slim\Views\Twig('path/to/templates', [
179-
'cache' => 'path/to/cache'
180-
]);
181-
182-
$twig->addExtension(new \Slim\Views\TwigExtension(
183-
$c->get('router'),
184-
$c->get('request')->getUri()
185-
));
186-
187-
return $twig;
188-
},
189-
190-
];
191-
192-
$builder->addDefinitions($definitions);
193-
}
194-
}
195-
```
196-
197-
You can now inject the service in your controllers and render templates:
198-
199-
```php
200-
$app->get('/', function ($response, Twig $twig) {
201-
return $twig->render($response, 'home.twig');
202-
});
203-
```
101+
The documentation can be read here: **http://php-di.org/doc/frameworks/slim.html**

0 commit comments

Comments
 (0)