kgengler/feed-client
该包的最新版本(v4.0.1)没有提供许可证信息。
Laravel 框架的 Atom 和 RSS 订阅客户端
v4.0.1
2016-12-04 22:16 UTC
Requires
- php: >=5.3.0
- illuminate/support: 4.*
This package is not auto-updated.
Last update: 2024-09-29 02:54:50 UTC
README
此分支适用于 Laravel 4.x
Laravel 框架的 Atom 和 RSS 订阅客户端
安装
将以下行添加到 composer.json
文件的 require
部分:
{ "require": { "kgengler/feed-client": "4.*" } }
运行 composer update
。
配置
使用 Artisan 发布包配置。
php artisan config:publish kgengler/feed-client
在 app/config/app.php 中找到 providers 键并注册 Feed Client 服务提供者。
'providers' => array( // ... 'Kgengler\FeedClient\FeedClientServiceProvider', )
在 app/config/app.php 中找到 aliases 键并添加 Feed Client 门面别名。
'aliases' => array( // ... 'FeedClient' => 'Kgengler\FeedClient\FeedClientFacade' )
打开 app/config/packages/kgengler/feed-client/config.php 配置文件,并添加您需要访问的订阅
<?php // app/config/packages/kgengler/feed-client/config.php return array( // The `laravel` key here is used to fetch the feed later. You can specify multiple // feeds, just use another key. 'laravel' => array( // Feed type, either `atom` or `rss` // Required // Default: none 'type' => 'atom', // Url of the feed // Required // Default: none 'url' => 'https://github.com/laravel/laravel/commits/master.atom', // username required to access feed // Optional // Default: null 'user' => null, // password required to access feed // Optional // Default: null 'password' => null, // whether or not to cache the feed locally. I would recommend leaving this // on, unless you plan on caching it yourself. It will use whatever cache // driver you have specified for your application. // Optional // Default: true 'cached' => true, // time in minutes to cache feed // Optional // Default: 60 'cacheTimeout' => 60 ) );
用法
从 Laravel IOC 容器获取客户端并使用配置文件中提供的键获取订阅
$feed_client = App::make('feed-client'); $feed = $feed_client->get('laravel'); // or with the Facade $feed = FeedClient::get('laravel');
用于从订阅获取信息的方法
$feed->getTitle(); // Feed Title $feed->getDescription(); // Feed Description $feed->getLink(); // Link to feed $feed_items = $feed->getItems(); // Items in feed // Feed items are given as a collection of FeedItem objects foreach($feed_items as $item) { $item->getTitle(); // Item Title $item->getTime(); // Publication Time as DateTime object $item->getLink(); // Get link for Item $item->getDescription(); // Item Description }