You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the library is unable to discover a suitable PSR-17 implementation, the `Discovery::httpRequestFactory()`, `Discovery::httpResponseFactory()` or `Discovery::httpStreamFactory()` discovery methods will simply return `null`. This allows you to handle the failure gracefully, for example by falling back to a default implementation.
59
+
If the library is unable to discover a suitable PSR-17 implementation, the `Discover::httpRequestFactory()`, `Discover::httpResponseFactory()` or `Discover::httpStreamFactory()` discovery methods will simply return `null`. This allows you to handle the failure gracefully, for example by falling back to a default implementation.
// No suitable HTTP RequestFactory implementation was discovered.
@@ -74,20 +74,20 @@ if ($requestFactory === null) {
74
74
75
75
## Singletons
76
76
77
-
By default, the `Discovery::httpRequestFactory()`, `Discovery::httpResponseFactory()` or `Discovery::httpStreamFactory()` methods will always return a new instance of the discovered implementation. If you wish to use a singleton instance instead, simply pass `true` to the `$singleton` parameter of the discovery method.
77
+
By default, the `Discover::httpRequestFactory()`, `Discover::httpResponseFactory()` or `Discover::httpStreamFactory()` methods will always return a new instance of the discovered implementation. If you wish to use a singleton instance instead, simply pass `true` to the `$singleton` parameter of the discovery method.
// Return an instance of Nyholm\Psr7\Factory\Psr17Factory,
111
111
// or the next available from the list of candidates,
112
112
// Returns null if none are discovered.
113
-
$factory = Discovery::httpRequestFactory();
113
+
$factory = Discover::httpRequestFactory();
114
114
```
115
115
116
116
In this case, this will cause the `httpRequestFactory()` method to return the preferred implementation if it is available, otherwise, it will fall back to the default behavior. The same applies to `httpResponseFactory()` and `httpStreamFactory()` when their relevant classes are configured similarly.
@@ -122,15 +122,15 @@ Note that assigning a preferred implementation will give it priority over the de
122
122
If you wish to force a specific implementation and ignore the rest of the discovery candidates, you can `use()` its package name:
123
123
124
124
```php
125
-
use PsrDiscovery\Discovery;
125
+
use PsrDiscovery\Discover;
126
126
use PsrDiscovery\Implementations\Psr17\ResponseFactories;
127
127
128
128
// Only discover a specific implementation of PSR-17.
129
129
ResponseFactories::use('nyholm/psr7');
130
130
131
131
// Return an instance of Nyholm\Psr7\Factory\Psr17Factory,
132
132
// or null if it is not available.
133
-
$factory = Discovery::httpResponseFactory();
133
+
$factory = Discover::httpResponseFactory();
134
134
```
135
135
136
136
In this case, this will cause the `httpResponseFactory()` method to return the preferred implementation if it is available, otherwise, it will return `null`. The same applies to `httpRequestFactory()` and `httpStreamFactory()` when their relevant classes are configured similarly.
0 commit comments