Skip to content
This repository was archived by the owner on Jul 15, 2021. It is now read-only.

Commit 7727fb8

Browse files
dbucsarrazi
authored andcommitted
document middleware class service definition (#247)
1 parent c54f9da commit 7727fb8

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/Resources/doc/middleware.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,33 @@ is as easy as creating a symfony service and using the `csa_guzzle.middleware` t
1414
</service>
1515
```
1616

17+
You can also define middleware as a class with the `__invoke` method like this:
18+
19+
```php
20+
class Middleware
21+
{
22+
public function __invoke(callable $handler): callable
23+
{
24+
return function (RequestInterface $request, array $options) use ($handler) {
25+
$request = $request->withHeader('X-Test', 'I was here');
26+
27+
return $handler($request, $options);
28+
};
29+
}
30+
}
31+
32+
```
33+
34+
The service definition for such a class is then:
35+
36+
```yaml
37+
My\Middleware:
38+
tags:
39+
- { name: csa_guzzle.middleware, alias: my_middleware, priority: 100 }
40+
```
41+
1742
Middleware are automatically used by all your clients, if you are using the semantic configuration.
18-
However, if you wish to, you can enable specific middleware, for a given client:
43+
However, if you wish to, you can limit a client to a list of specific middleware:
1944
2045
```yml
2146
csa_guzzle:

0 commit comments

Comments
 (0)