Skip to content

Commit 1bfef90

Browse files
committed
Update discovery documentation
1 parent e73b895 commit 1bfef90

File tree

1 file changed

+69
-5
lines changed

1 file changed

+69
-5
lines changed

docs/discovery.md

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ The discovery service is a set of static classes which allows to find and use in
66
Currently available discovery services:
77

88
- HTTP Adapter Discovery
9-
- PSR Message Discovery
10-
- PSR URI Discovery
9+
- PSR-7 Message Discovery
10+
- PSR-7 URI Discovery
1111

1212

1313
## General
@@ -33,14 +33,13 @@ A start value can be defined for the `classes` property in the following structu
3333

3434
``` php
3535
[
36-
'name' => [
36+
[
3737
'class' => 'MyClass',
3838
'condition' => 'MyCondition',
3939
],
4040
]
4141
```
4242

43-
- `name`: A unique name for the resource, can be overwritten using `register`
4443
- `class`: The class that is instantiated. There MUST NOT be any constructor arguments.
4544
- `condition`: The condition that is evaluated to boolean to decide whether the resource is available. The following types are allowed:
4645
- string: Checked for class existence
@@ -51,9 +50,11 @@ A start value can be defined for the `classes` property in the following structu
5150
By declaring a start value for `classes` only string conditions are allowed, however the `register` method allows any type of arguments:
5251

5352
``` php
54-
MyDiscovery::register('name', 'MyClass', true);
53+
MyDiscovery::register('MyClass', true);
5554
```
5655

56+
Classes registered manually are put on top of the list.
57+
5758
The condition can also be omitted. In that case the class is used as the condition (to check for existence).
5859

5960
The last thing to do is to find the first available resource:
@@ -91,3 +92,66 @@ class MyClass
9192
}
9293
}
9394
```
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

Comments
 (0)