Skip to content

Commit feae976

Browse files
committed
Update readme
1 parent 5416e70 commit feae976

File tree

1 file changed

+24
-112
lines changed

1 file changed

+24
-112
lines changed

README.md

+24-112
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
- Content filtering to fetch only the newest items
2020
- DateTime detection and conversion
2121
- 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/).
2323

2424
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).
2525

@@ -34,11 +34,12 @@ Use Composer to add feed-io into your project's requirements :
3434
# Requirements
3535

3636
| 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+ |
4041

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.
4243

4344
# Usage
4445

@@ -56,8 +57,9 @@ feed-io is designed to read feeds across the internet and to publish your own. I
5657

5758
```php
5859

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);
6163

6264
// read a feed
6365
$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
130132

131133
```php
132134

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());
137+
$feedIo = \FeedIo\FeedIo($client);
134138

135139
$feeds = $feedIo->discover($url);
136140

@@ -222,38 +226,7 @@ $jsonResponse = $feedIo->getPsrResponse($feed, 'json');
222226

223227
```
224228

225-
## Configure feed-io using the Factory
226-
227-
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
238-
['builder' => 'GuzzleClient', 'config' => ['verify' => false]]
239-
)->getFeedIo();
240-
```
241-
242-
It's important to specify the "builder", as it's the class that will be in charge of actually building the instance.
243-
244-
### activate logging
245-
246-
feed-io natively supports PSR-3 logging, you can activate it by choosing a 'builder' in the factory :
247-
248-
```php
249-
250-
$feedIo = \FeedIo\Factory::create(['builder' => 'monolog'])->getFeedIo();
251-
252-
```
253-
254-
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
257230

258231
To create a new FeedIo instance you only need to inject two dependencies :
259232

@@ -279,69 +252,13 @@ $feedIo = new FeedIo\FeedIo($client, $logger);
279252
Another example with Monolog configured to write on the standard output :
280253

281254
```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);
340259

341260
```
342261

343-
As feeds' content may vary often, caching may result in unwanted behaviors.
344-
345262
### Inject a custom Logger
346263

347264
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);
361278

362279
### Inject a custom HTTP Client
363280

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.
367282

368283
```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;
373285

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();
376288

377-
$feedIo = new FeedIo($client, $logger);
289+
$feedIo = new FeedIo\FeedIo($client, $logger);
378290

379291
```
380292

381-
### Factory or Dependency Injection ?
293+
## Configure feed-io using the Factory
382294

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.
384296

385297
## Dealing with missing timezones
386298

0 commit comments

Comments
 (0)