Skip to content

Commit e229df1

Browse files
committed
Add message factory documentation
1 parent 1bfef90 commit e229df1

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

docs/message-factory.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Message Factory
2+
3+
**Factory interfaces for PSR-7 HTTP Message.**
4+
5+
6+
## Rationale
7+
8+
The FIG was pretty straightforward by NOT putting any construction logic into PSR-7. However there is a need for that. This does not try to be the "de facto" way to do message construction, but tries to provide an easy way to construct messages by following already existing patterns. (For example: `MessageFactory` accepts parameters in the order they appear in a request/response: method, uri, protocol version, headers, body (in case of a request)).
9+
10+
11+
## Usage
12+
13+
This package provides interfaces for PSR-7 factories including:
14+
15+
- `MessageFactory`
16+
- `ServerRequestFactory` - WIP (PRs welcome)
17+
- `StreamFactory`
18+
- `UploadedFileFactory` - WIP (PRs welcome)
19+
- `UriFactory`
20+
- `ClientContextFactory` (Combines `MessageFactory`, `StreamFactory` and `UriFactory`)
21+
22+
23+
A virtual package ([php-http/message-factory-implementation](https://packagist.org/providers/php-http/message-factory-implementation)) MAY be introduced which MUST be versioned together with this package.
24+
25+
26+
### General usage
27+
28+
``` php
29+
use Http\Message\SomeFactory;
30+
31+
class MyFactory implements SomeFactory
32+
{
33+
34+
}
35+
```
36+
37+
38+
### Factory awares and templates
39+
40+
For each factory there is a helper interface and trait to ease injecting them into other objects (such as HTTP clients).
41+
42+
An example:
43+
44+
``` php
45+
use Http\Message\SomeFactoryAware;
46+
use Http\Message\SomeFactoryAwareTemplate;
47+
48+
class HttpClient implements SomeFactoryAware
49+
{
50+
use SomeFactoryAwareTemplate;
51+
}
52+
53+
$client = new HttpClient();
54+
$someFactory = $client->getSomeFactory();
55+
$client->setSomeFactory($someFactory);
56+
```

0 commit comments

Comments
 (0)