Skip to content

Commit f53a571

Browse files
committed
Document #9
1 parent 8535e67 commit f53a571

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

README.md

+23
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,29 @@ $app->get('/{name}', HelloController::class);
9797

9898
Again you will notice that we pass the class name and not an instance. PHP-DI will correctly detect that this is an invokable class and will instantiate it.
9999

100+
### Middlewares, route variable converters, error handlers and view handlers
101+
102+
The callable resolution described above (for "controllers as services") applies for registering other Silex objects:
103+
104+
- [middlewares](http://silex.sensiolabs.org/doc/middlewares.html)
105+
- [route variable converters](http://silex.sensiolabs.org/doc/usage.html#route-variable-converters)
106+
- [error handlers](http://silex.sensiolabs.org/doc/usage.html#error-handlers)
107+
- [view handlers](http://silex.sensiolabs.org/doc/usage.html#view-handlers)
108+
109+
For example you can define a middleware like so and let PHP-DI instantiate it:
110+
111+
```php
112+
class AuthMiddleware
113+
{
114+
public function beforeRoute(Request $request, Application $app)
115+
{
116+
// ...
117+
}
118+
}
119+
120+
$app->before([AuthMiddleware::class, 'beforeRoute']);
121+
```
122+
100123
## Configuring the container
101124

102125
You can configure PHP-DI's container by creating your own `ContainerBuilder` and passing it to the application:

0 commit comments

Comments
 (0)