@@ -6,8 +6,8 @@ The discovery service is a set of static classes which allows to find and use in
6
6
Currently available discovery services:
7
7
8
8
- HTTP Adapter Discovery
9
- - PSR Message Discovery
10
- - PSR URI Discovery
9
+ - PSR-7 Message Discovery
10
+ - PSR-7 URI Discovery
11
11
12
12
13
13
## General
@@ -33,14 +33,13 @@ A start value can be defined for the `classes` property in the following structu
33
33
34
34
``` php
35
35
[
36
- 'name' => [
36
+ [
37
37
'class' => 'MyClass',
38
38
'condition' => 'MyCondition',
39
39
],
40
40
]
41
41
```
42
42
43
- - ` name ` : A unique name for the resource, can be overwritten using ` register `
44
43
- ` class ` : The class that is instantiated. There MUST NOT be any constructor arguments.
45
44
- ` condition ` : The condition that is evaluated to boolean to decide whether the resource is available. The following types are allowed:
46
45
- string: Checked for class existence
@@ -51,9 +50,11 @@ A start value can be defined for the `classes` property in the following structu
51
50
By declaring a start value for ` classes ` only string conditions are allowed, however the ` register ` method allows any type of arguments:
52
51
53
52
``` php
54
- MyDiscovery::register('name', ' MyClass', true);
53
+ MyDiscovery::register('MyClass', true);
55
54
```
56
55
56
+ Classes registered manually are put on top of the list.
57
+
57
58
The condition can also be omitted. In that case the class is used as the condition (to check for existence).
58
59
59
60
The last thing to do is to find the first available resource:
@@ -91,3 +92,66 @@ class MyClass
91
92
}
92
93
}
93
94
```
95
+
96
+
97
+ ## Message Factory Discovery
98
+
99
+ This type of discovery finds installed [ PSR-7] ( http://www.php-fig.org/psr/psr-7/ ) Message implementations and their factories.
100
+
101
+ Currently available factories:
102
+
103
+ - [ Guzzle] ( https://github.com/guzzle/psr7 ) factory
104
+ - [ Diactoros] ( https://github.com/zendframework/zend-diactoros ) factory
105
+
106
+
107
+ ``` php
108
+ use Http\Message\MessageFactory;
109
+ use Http\Discovery\MessageFactoryDiscovery;
110
+
111
+ class MyClass
112
+ {
113
+ /**
114
+ * @var MessageFactory
115
+ */
116
+ protected $messageFactory;
117
+
118
+ /**
119
+ * @param MessageFactory $messageFactory
120
+ */
121
+ public function __construct(MessageFactory $messageFactory)
122
+ {
123
+ $this->messageFactory = $messageFactory ?: MessageFactoryDiscovery::find();
124
+ }
125
+ }
126
+ ```
127
+
128
+ ## URI Factory Discovery
129
+
130
+ This type of discovery finds installed [ PSR-7] ( http://www.php-fig.org/psr/psr-7/ ) URI implementations and their factories.
131
+
132
+ Currently available factories:
133
+
134
+ - [ Guzzle] ( https://github.com/guzzle/psr7 ) factory
135
+ - [ Diactoros] ( https://github.com/zendframework/zend-diactoros ) factory
136
+
137
+
138
+ ``` php
139
+ use Http\Message\UriFactory;
140
+ use Http\Discovery\UriFactoryDiscovery;
141
+
142
+ class MyClass
143
+ {
144
+ /**
145
+ * @var UriFactory
146
+ */
147
+ protected $uriFactory;
148
+
149
+ /**
150
+ * @param UriFactory $uriFactory
151
+ */
152
+ public function __construct(UriFactory $uriFactory)
153
+ {
154
+ $this->uriFactory = $uriFactory ?: UriFactoryDiscovery::find();
155
+ }
156
+ }
157
+ ```
0 commit comments