Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
<?php
require 'vendor/autoload.php';

use \FeedIo\Factory;
// 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);

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

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

```php
<?php
// create a simple FeedIo instance
$feedIo = \FeedIo\Factory::create()->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);
Expand Down Expand Up @@ -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 :

Expand Down
39 changes: 39 additions & 0 deletions docs/upgrades/UPGRADE-6.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
```
5 changes: 4 additions & 1 deletion examples/PdoCallback.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 4 additions & 2 deletions examples/feed-creation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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');
Expand Down
6 changes: 5 additions & 1 deletion examples/force-timezone.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
6 changes: 5 additions & 1 deletion examples/rich-feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -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/');

Expand Down
5 changes: 4 additions & 1 deletion examples/test-async.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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);

Expand Down