Skip to content

Commit c491766

Browse files
CopilotGrotax
andauthored
Remove deprecated Factory usage from documentation and examples (#30)
* Update documentation and examples to remove deprecated Factory usage * Add migration examples to UPGRADE-6.0.md guide Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: Grotax <[email protected]>
1 parent c25193c commit c491766

File tree

7 files changed

+75
-14
lines changed

7 files changed

+75
-14
lines changed

docs/index.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
<?php
77
require 'vendor/autoload.php';
88

9-
use \FeedIo\Factory;
9+
// create a simple FeedIo instance, e.g. with the Symfony HTTP Client
10+
$client = new \FeedIo\Adapter\Http\Client(new Symfony\Component\HttpClient\HttplugClient());
11+
$feedIo = new \FeedIo\FeedIo($client);
1012

11-
$feedIo = Factory::create()->getFeedIo();
1213
$result = $feedIo->read('http://php.net/feed.atom');
1314

1415
echo "feed title : {$result->getFeed()->getTitle()} \n";
@@ -54,8 +55,9 @@ feed-io is designed to read feeds across the internet and to publish your own. I
5455

5556
```php
5657
<?php
57-
// create a simple FeedIo instance
58-
$feedIo = \FeedIo\Factory::create()->getFeedIo();
58+
// create a simple FeedIo instance, e.g. with the Symfony HTTP Client
59+
$client = new \FeedIo\Adapter\Http\Client(new Symfony\Component\HttpClient\HttplugClient());
60+
$feedIo = new \FeedIo\FeedIo($client);
5961

6062
// read a feed
6163
$result = $feedIo->read($url);
@@ -124,14 +126,18 @@ $feed->add($item);
124126

125127
## Activate logging
126128

127-
feed-io natively supports PSR-3 logging, you can activate it by choosing a 'builder' in the factory :
129+
feed-io natively supports PSR-3 logging, you can activate it by injecting a logger when creating the FeedIo instance :
128130

129131
```php
130-
$feedIo = \FeedIo\Factory::create(['builder' => 'monolog'])->getFeedIo();
132+
use Monolog\Logger;
133+
use Monolog\Handler\StreamHandler;
134+
135+
$client = new \FeedIo\Adapter\Http\Client(new Symfony\Component\HttpClient\HttplugClient());
136+
$logger = new Logger('feed-io', [new StreamHandler('php://stdout')]);
137+
$feedIo = new \FeedIo\FeedIo($client, $logger);
131138
```
132139

133-
feed-io only provides a builder to create Monolog\Logger instances. You can write your own, as long as the Builder implements BuilderInterface.
134-
Building a FeedIo instance without the factory
140+
## Building a FeedIo instance
135141

136142
To create a new FeedIo instance you only need to inject two dependencies :
137143

docs/upgrades/UPGRADE-6.0.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,42 @@ Several major changes in version 6.0:
55
- The factory has been removed. Use `new` to construct your FeedIO instance: `new \FeedIo\FeedIo($client, $logger)`
66
- Feed IO comes no longer bundled with a default HTTP client, but uses HTTPlug instead. To continue using Guzzle, please require `php-http/guzzle7-adapter`.
77
- Feed IO does no longer set a custom user agent. However, HTTP clients usually add a default themselves. If the feed you want to read requires a specific user agent, please configure your HTTP client accordingly, before you inject it into Feed IO.
8+
9+
## Migrating from Factory
10+
11+
### Before (5.x)
12+
```php
13+
use \FeedIo\Factory;
14+
15+
$feedIo = Factory::create()->getFeedIo();
16+
```
17+
18+
### After (6.0+)
19+
```php
20+
use \FeedIo\Adapter\Http\Client;
21+
use \Http\Discovery\Psr18ClientDiscovery;
22+
23+
$client = new Client(Psr18ClientDiscovery::find());
24+
$feedIo = new \FeedIo\FeedIo($client);
25+
```
26+
27+
### With Logging (6.0+)
28+
```php
29+
use \FeedIo\Adapter\Http\Client;
30+
use \Http\Discovery\Psr18ClientDiscovery;
31+
use Monolog\Logger;
32+
use Monolog\Handler\StreamHandler;
33+
34+
$client = new Client(Psr18ClientDiscovery::find());
35+
$logger = new Logger('feed-io', [new StreamHandler('php://stdout')]);
36+
$feedIo = new \FeedIo\FeedIo($client, $logger);
37+
```
38+
39+
### With Guzzle Client (6.0+)
40+
```php
41+
use \FeedIo\Adapter\Guzzle\Client;
42+
use \GuzzleHttp\Client as GuzzleClient;
43+
44+
$client = new Client(new GuzzleClient());
45+
$feedIo = new \FeedIo\FeedIo($client);
46+
```

examples/PdoCallback.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ public function handleError(\FeedIo\Async\Request $request, \Exception $exceptio
9090

9191
}
9292

93-
$logger = (new FeedIo\Factory\Builder\MonologBuilder())->getLogger();
93+
use Monolog\Logger;
94+
use Monolog\Handler\StreamHandler;
95+
96+
$logger = new Logger('feed-io', [new StreamHandler('php://stdout')]);
9497
$pdo = new PDO('sqlite:memory:');
9598
$callback = new PdoCallback($pdo, $logger);
9699

examples/feed-creation.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010

1111
require __DIR__.DIRECTORY_SEPARATOR.'bootstrap.php';
1212

13-
use \FeedIo\Factory;
1413
use \FeedIo\Feed;
14+
use \FeedIo\Adapter\Http\Client;
15+
use \Http\Discovery\Psr18ClientDiscovery;
1516

1617
$feed = new Feed();
1718
$feed->setLink('https://example.com');
@@ -28,7 +29,8 @@
2829
$item->setSummary('my summary');
2930
$feed->add($item);
3031

31-
$feedIo = Factory::create()->getFeedIo();
32+
$client = new Client(Psr18ClientDiscovery::find());
33+
$feedIo = new \FeedIo\FeedIo($client);
3234

3335
echo 'ATOM' . PHP_EOL;
3436
echo $feedIo->format($feed, 'atom');

examples/force-timezone.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010

1111
require __DIR__.DIRECTORY_SEPARATOR.'bootstrap.php';
1212

13-
$feedIo = \FeedIo\Factory::create()->getFeedIo();
13+
use \FeedIo\Adapter\Http\Client;
14+
use \Http\Discovery\Psr18ClientDiscovery;
15+
16+
$client = new Client(Psr18ClientDiscovery::find());
17+
$feedIo = new \FeedIo\FeedIo($client);
1418

1519
$feedIo->getDateTimeBuilder()->setFeedTimezone(new \DateTimeZone('-0500'));
1620
$result = $feedIo->read('http://news.php.net/group.php?group=php.announce&format=rss');

examples/rich-feed.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010

1111
require __DIR__.DIRECTORY_SEPARATOR.'bootstrap.php';
1212

13-
$feedIo = \FeedIo\Factory::create()->getFeedIo();
13+
use \FeedIo\Adapter\Http\Client;
14+
use \Http\Discovery\Psr18ClientDiscovery;
15+
16+
$client = new Client(Psr18ClientDiscovery::find());
17+
$feedIo = new \FeedIo\FeedIo($client);
1418

1519
$result = $feedIo->read('https://debril.org/feed/');
1620

examples/test-async.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
require __DIR__.DIRECTORY_SEPARATOR.'bootstrap.php';
44

5+
use Monolog\Logger;
6+
use Monolog\Handler\StreamHandler;
7+
58
$requests = [
69
new FeedIo\Async\Request('https://jsonfeed.org/feed.json'),
710
new FeedIo\Async\Request('https://jsonfeed.org/xml/rss.xml'),
@@ -10,7 +13,7 @@
1013
new FeedIo\Async\Request('https://debril.org/feed/'),
1114
new FeedIo\Async\Request('https://localhost:8000'),
1215
];
13-
$logger = (new FeedIo\Factory\Builder\MonologBuilder())->getLogger();
16+
$logger = new Logger('feed-io', [new StreamHandler('php://stdout')]);
1417

1518
$feedIo = new \FeedIo\FeedIo(new \FeedIo\Adapter\Guzzle\Client(new \GuzzleHttp\Client()), $logger);
1619

0 commit comments

Comments
 (0)