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
Copy file name to clipboardexpand all lines: README.md
+24-112
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@
19
19
- Content filtering to fetch only the newest items
20
20
- DateTime detection and conversion
21
21
- A generic HTTP ClientInterface
22
-
-Guzzle Client integration
22
+
-Integrates with every [PSR-18 compatible HTTP client](https://www.php-fig.org/psr/psr-18/).
23
23
24
24
This library is highly extensible and is designed to adapt to many situations, so if you don't find a solution through the documentation feel free to ask in the [discussions](https://github.com/alexdebril/feed-io/discussions).
25
25
@@ -34,11 +34,12 @@ Use Composer to add feed-io into your project's requirements :
34
34
# Requirements
35
35
36
36
| feed-io | PHP |
37
-
| --------| ---- |
38
-
| 4.x | 7.1+ |
39
-
| 5.0 | 8.0+ |
37
+
|---------|------|
38
+
| 4.x | 7.1+ |
39
+
| 5.0 | 8.0+ |
40
+
| 6.0 | 8.1+ |
40
41
41
-
feed-io 4 requires PHP 7.1+, feed-io 5 requires PHP 8.0+. All versions relies on `psr/log` and `guzzle`. it suggests `monolog` for logging. Monolog is not the only library suitable to handle feed-io's logs, you can use any PSR/Log compliant library instead.
42
+
feed-io 4 requires PHP 7.1+, feed-io 5 requires PHP 8.0+. All versions relies on `psr/log` and any PSR-18 compliant HTTP client. To continue using you may require `php-http/guzzle7-adapter`. it suggests `monolog` for logging. Monolog is not the only library suitable to handle feed-io's logs, you can use any PSR/Log compliant library instead.
42
43
43
44
# Usage
44
45
@@ -56,8 +57,9 @@ feed-io is designed to read feeds across the internet and to publish your own. I
56
57
57
58
```php
58
59
59
-
// create a simple FeedIo instance
60
-
$feedIo = \FeedIo\Factory::create()->getFeedIo();
60
+
// create a simple FeedIo instance, e.g. with the Symfony HTTP Client
61
+
$client = new \FeedIo\Adapter\Http\Client(new Symfony\Component\HttpClient\HttplugClient());
62
+
$feedIo = \FeedIo\FeedIo($client);
61
63
62
64
// read a feed
63
65
$result = $feedIo->read($url);
@@ -130,7 +132,9 @@ A web page can refer to one or more feeds in its headers, feed-io provides a way
130
132
131
133
```php
132
134
133
-
$feedIo = \FeedIo\Factory::create()->getFeedIo();
135
+
// create a simple FeedIo instance, e.g. with the Symfony HTTP Client
136
+
$client = new \FeedIo\Adapter\Http\Client(new Symfony\Component\HttpClient\HttplugClient());
We saw in the [reading section](#reading) that to get a simple `FeedIo` instance we can simply call the `Factory` statically and let it return a fresh `FeedIo` composed of the main dependencies it needs to work. The problem is that we may want to inject configuration to its underlying components, such as configuring Guzzle to ignore SSL errors.
228
-
229
-
For that, we will inject the configuration through `Factory::create()` parameters, first one being for the logging system, and the second one for the HTTP Client (well, Guzzle).
230
-
231
-
### Configure Guzzle through the Factory
232
-
233
-
A few lines above, we talked about ignoring ssl errors, let's see how to configure Guzzle to do this:
234
-
235
-
```php
236
-
$feedIo = \FeedIo\Factory::create(
237
-
['builder' => 'NullLogger'], // assuming you want feed-io to keep quiet
feed-io only provides a builder to create Monolog\Logger instances. You can write your own, as long as the Builder implements BuilderInterface.
255
-
256
-
## Building a FeedIo instance without the factory
229
+
## Building a FeedIo instance
257
230
258
231
To create a new FeedIo instance you only need to inject two dependencies :
259
232
@@ -279,69 +252,13 @@ $feedIo = new FeedIo\FeedIo($client, $logger);
279
252
Another example with Monolog configured to write on the standard output :
280
253
281
254
```php
282
-
use FeedIo\FeedIo;
283
-
use FeedIo\Adapter\Guzzle\Client;
284
-
use GuzzleHttp\Client as GuzzleClient;
285
-
use Monolog\Logger;
286
-
use Monolog\Handler\StreamHandler;
287
-
288
-
$client = new Client(new GuzzleClient());
289
-
$logger = new Logger('default', [new StreamHandler('php://stdout')]);
290
-
291
-
$feedIo = new FeedIo($client, $logger);
292
-
293
-
```
294
-
295
-
### Guzzle Configuration
296
-
297
-
You can configure Guzzle before injecting it to `FeedIo` :
298
-
299
-
```php
300
-
use FeedIo\FeedIo;
301
-
use FeedIo\Adapter\Guzzle\Client;
302
-
use GuzzleHttp\Client as GuzzleClient;
303
-
use \Psr\Log\NullLogger;
304
-
305
-
// We want to timeout after 3 seconds
306
-
$guzzle = new GuzzleClient(['timeout' => 3]);
307
-
$client = new Client($guzzle);
308
-
309
-
$logger = new NullLogger();
310
-
311
-
$feedIo = new \FeedIo\FeedIo($client, $logger);
312
-
313
-
```
314
-
Please read [Guzzle's documentation](http://docs.guzzlephp.org/en/stable/index.html) to get more information about its configuration.
315
-
316
-
#### Caching Middleware usage
317
-
318
-
To prevent your application from hitting the same feeds multiple times, you can inject [Kevin Rob's cache middleware](https://github.com/Kevinrob/guzzle-cache-middleware) into Guzzle's instance :
319
-
320
-
```php
321
-
use FeedIo\FeedIo;
322
-
use FeedIo\Adapter\Guzzle\Client;
323
-
use GuzzleHttp\Client As GuzzleClient;
324
-
use GuzzleHttp\HandlerStack;
325
-
use Kevinrob\GuzzleCache\CacheMiddleware;
326
-
use Psr\Log\NullLogger;
327
-
328
-
// Create default HandlerStack
329
-
$stack = HandlerStack::create();
330
-
331
-
// Add this middleware to the top with `push`
332
-
$stack->push(new CacheMiddleware(), 'cache');
333
-
334
-
// Initialize the client with the handler option
335
-
$guzzle = new GuzzleClient(['handler' => $stack]);
336
-
$client = new Client($guzzle);
337
-
$logger = new NullLogger();
338
-
339
-
$feedIo = new \FeedIo\FeedIo($client, $logger);
255
+
// create a simple FeedIo instance, e.g. with the Symfony HTTP Client
256
+
$client = new \FeedIo\Adapter\Http\Client(new Symfony\Component\HttpClient\HttplugClient());
257
+
$logger = new Monolog\Logger('default', [new Monolog\Handler\StreamHandler('php://stdout')]);
258
+
$feedIo = \FeedIo\FeedIo($client, $logger);
340
259
341
260
```
342
261
343
-
As feeds' content may vary often, caching may result in unwanted behaviors.
344
-
345
262
### Inject a custom Logger
346
263
347
264
You can inject any Logger you want as long as it implements `Psr\Log\LoggerInterface`. Monolog does, but it's not the only library : https://packagist.org/providers/psr/log-implementation
@@ -361,26 +278,21 @@ $feedIo = new FeedIo($client, $logger);
361
278
362
279
### Inject a custom HTTP Client
363
280
364
-
Warning : it is highly recommended to use the default Guzzle Client integration.
365
-
366
-
If you really want to use another library to read feeds, you need to create your own `FeedIo\Adapter\ClientInterface` class to embed interactions with the library :
281
+
Since 6.0 there is a generic HTTP adapter that wraps any PST-18 compliant HTTP client.
367
282
368
283
```php
369
-
use FeedIo\FeedIo;
370
-
use Custom\Adapter\Client;
371
-
use Library\Client as LibraryClient;
372
-
use Psr\Log\NullLogger;
284
+
use CustomPsr18\Client as CustomClient;
373
285
374
-
$client = new Client(new LibraryClient());
375
-
$logger = new NullLogger();
286
+
$client = new Custom\Adapter\Http\Client(new CustomClient())
287
+
$logger = new Psr\Log\NullLogger();
376
288
377
-
$feedIo = new FeedIo($client, $logger);
289
+
$feedIo = new FeedIo\FeedIo($client, $logger);
378
290
379
291
```
380
292
381
-
### Factory or Dependency Injection ?
293
+
##Configure feed-io using the Factory
382
294
383
-
Choosing between using the Factory or build `FeedIo` without it is a question you must ask yourself at some point of your project. The Factory is mainly designed to let you use feed-io with the lesser efforts and get your first results in a small amount of time. However, it doesn't let you benefit of all Monolog's and Guzzle's features, which could be annoying. Dependency injection will also let you choose another library to handle logs if you need to.
295
+
The factory has been deprecated in feed-io 5.2 and was removed in 6.0. Instantiate the facade directly and pass in the desired HTTP client and logger interface.
0 commit comments