diff --git a/docs/index.md b/docs/index.md index 0d5c303d..55b1391c 100644 --- a/docs/index.md +++ b/docs/index.md @@ -6,9 +6,10 @@ getFeedIo(); $result = $feedIo->read('http://php.net/feed.atom'); 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 ```php getFeedIo(); +// create a simple FeedIo instance, e.g. with the Symfony HTTP Client +$client = new \FeedIo\Adapter\Http\Client(new Symfony\Component\HttpClient\HttplugClient()); +$feedIo = new \FeedIo\FeedIo($client); // read a feed $result = $feedIo->read($url); @@ -124,14 +126,18 @@ $feed->add($item); ## Activate logging -feed-io natively supports PSR-3 logging, you can activate it by choosing a 'builder' in the factory : +feed-io natively supports PSR-3 logging, you can activate it by injecting a logger when creating the FeedIo instance : ```php -$feedIo = \FeedIo\Factory::create(['builder' => 'monolog'])->getFeedIo(); +use Monolog\Logger; +use Monolog\Handler\StreamHandler; + +$client = new \FeedIo\Adapter\Http\Client(new Symfony\Component\HttpClient\HttplugClient()); +$logger = new Logger('feed-io', [new StreamHandler('php://stdout')]); +$feedIo = new \FeedIo\FeedIo($client, $logger); ``` -feed-io only provides a builder to create Monolog\Logger instances. You can write your own, as long as the Builder implements BuilderInterface. -Building a FeedIo instance without the factory +## Building a FeedIo instance To create a new FeedIo instance you only need to inject two dependencies : diff --git a/docs/upgrades/UPGRADE-6.0.md b/docs/upgrades/UPGRADE-6.0.md index fcf0aaea..e85a8709 100644 --- a/docs/upgrades/UPGRADE-6.0.md +++ b/docs/upgrades/UPGRADE-6.0.md @@ -5,3 +5,42 @@ Several major changes in version 6.0: - The factory has been removed. Use `new` to construct your FeedIO instance: `new \FeedIo\FeedIo($client, $logger)` - 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`. - 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. + +## Migrating from Factory + +### Before (5.x) +```php +use \FeedIo\Factory; + +$feedIo = Factory::create()->getFeedIo(); +``` + +### After (6.0+) +```php +use \FeedIo\Adapter\Http\Client; +use \Http\Discovery\Psr18ClientDiscovery; + +$client = new Client(Psr18ClientDiscovery::find()); +$feedIo = new \FeedIo\FeedIo($client); +``` + +### With Logging (6.0+) +```php +use \FeedIo\Adapter\Http\Client; +use \Http\Discovery\Psr18ClientDiscovery; +use Monolog\Logger; +use Monolog\Handler\StreamHandler; + +$client = new Client(Psr18ClientDiscovery::find()); +$logger = new Logger('feed-io', [new StreamHandler('php://stdout')]); +$feedIo = new \FeedIo\FeedIo($client, $logger); +``` + +### With Guzzle Client (6.0+) +```php +use \FeedIo\Adapter\Guzzle\Client; +use \GuzzleHttp\Client as GuzzleClient; + +$client = new Client(new GuzzleClient()); +$feedIo = new \FeedIo\FeedIo($client); +``` diff --git a/examples/PdoCallback.php b/examples/PdoCallback.php index cee03014..5798cb10 100644 --- a/examples/PdoCallback.php +++ b/examples/PdoCallback.php @@ -90,7 +90,10 @@ public function handleError(\FeedIo\Async\Request $request, \Exception $exceptio } -$logger = (new FeedIo\Factory\Builder\MonologBuilder())->getLogger(); +use Monolog\Logger; +use Monolog\Handler\StreamHandler; + +$logger = new Logger('feed-io', [new StreamHandler('php://stdout')]); $pdo = new PDO('sqlite:memory:'); $callback = new PdoCallback($pdo, $logger); diff --git a/examples/feed-creation.php b/examples/feed-creation.php index bbe8d65f..fd8f6270 100644 --- a/examples/feed-creation.php +++ b/examples/feed-creation.php @@ -10,8 +10,9 @@ require __DIR__.DIRECTORY_SEPARATOR.'bootstrap.php'; -use \FeedIo\Factory; use \FeedIo\Feed; +use \FeedIo\Adapter\Http\Client; +use \Http\Discovery\Psr18ClientDiscovery; $feed = new Feed(); $feed->setLink('https://example.com'); @@ -28,7 +29,8 @@ $item->setSummary('my summary'); $feed->add($item); -$feedIo = Factory::create()->getFeedIo(); +$client = new Client(Psr18ClientDiscovery::find()); +$feedIo = new \FeedIo\FeedIo($client); echo 'ATOM' . PHP_EOL; echo $feedIo->format($feed, 'atom'); diff --git a/examples/force-timezone.php b/examples/force-timezone.php index 3e5a1e42..f29815f6 100644 --- a/examples/force-timezone.php +++ b/examples/force-timezone.php @@ -10,7 +10,11 @@ require __DIR__.DIRECTORY_SEPARATOR.'bootstrap.php'; -$feedIo = \FeedIo\Factory::create()->getFeedIo(); +use \FeedIo\Adapter\Http\Client; +use \Http\Discovery\Psr18ClientDiscovery; + +$client = new Client(Psr18ClientDiscovery::find()); +$feedIo = new \FeedIo\FeedIo($client); $feedIo->getDateTimeBuilder()->setFeedTimezone(new \DateTimeZone('-0500')); $result = $feedIo->read('http://news.php.net/group.php?group=php.announce&format=rss'); diff --git a/examples/rich-feed.php b/examples/rich-feed.php index b747d4e3..15b92fac 100644 --- a/examples/rich-feed.php +++ b/examples/rich-feed.php @@ -10,7 +10,11 @@ require __DIR__.DIRECTORY_SEPARATOR.'bootstrap.php'; -$feedIo = \FeedIo\Factory::create()->getFeedIo(); +use \FeedIo\Adapter\Http\Client; +use \Http\Discovery\Psr18ClientDiscovery; + +$client = new Client(Psr18ClientDiscovery::find()); +$feedIo = new \FeedIo\FeedIo($client); $result = $feedIo->read('https://debril.org/feed/'); diff --git a/examples/test-async.php b/examples/test-async.php index 614c2e0c..8c04428a 100644 --- a/examples/test-async.php +++ b/examples/test-async.php @@ -2,6 +2,9 @@ require __DIR__.DIRECTORY_SEPARATOR.'bootstrap.php'; +use Monolog\Logger; +use Monolog\Handler\StreamHandler; + $requests = [ new FeedIo\Async\Request('https://jsonfeed.org/feed.json'), new FeedIo\Async\Request('https://jsonfeed.org/xml/rss.xml'), @@ -10,7 +13,7 @@ new FeedIo\Async\Request('https://debril.org/feed/'), new FeedIo\Async\Request('https://localhost:8000'), ]; -$logger = (new FeedIo\Factory\Builder\MonologBuilder())->getLogger(); +$logger = new Logger('feed-io', [new StreamHandler('php://stdout')]); $feedIo = new \FeedIo\FeedIo(new \FeedIo\Adapter\Guzzle\Client(new \GuzzleHttp\Client()), $logger);