File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,35 @@ It will check whether the created instance implements the `MiddlewareInterface`.
22
22
Currently the only provided locator is the ` ContainerLocator ` which accepts a
23
23
` Interop\Container\ContainerInterface ` to fetch your middleware instances.
24
24
25
+ ## Example
26
+ ``` php
27
+ $container = /* ... */;
28
+ $locator = new ContainerLocator($container);
29
+ $middlewares = [];
30
+
31
+ $config = [
32
+ 'middlewares' => [/*...*/]
33
+ 'options' => [/*...*/]
34
+ ];
35
+
36
+ foreach ($config['middlewares'] as $middleware) {
37
+ $middlewares[] = $locator->get($middleware);
38
+ }
39
+
40
+ $runner = new MiddlewareRunner($config['options'], $middelwares);
41
+
42
+ $runner->pre($request)->then(function ($request) use ($options) {
43
+ return resolve($this->browser->send(
44
+ $request
45
+ ));
46
+ }, function (ResponseInterface $response) {
47
+ return resolve($response);
48
+ })->then(function (ResponseInterface $response) use ($runner) {
49
+ return $runner->post($response);
50
+ });
51
+ ```
52
+
53
+
25
54
# License
26
55
27
56
The MIT License (MIT)
You can’t perform that action at this time.
0 commit comments