imnotjames/syndicator

解析和序列化聚合源。

dev-master 2014-06-18 01:26 UTC

This package is not auto-updated.

Last update: 2024-09-14 16:13:31 UTC


README

基本的解析和组合聚合源库。

Build Status Coverage Status

目前支持的标准

  • RSS XML 2.0

对于其他标准,请随意打开一个 问题

安装

最简单的安装方法是使用 composer,在 packagist 上。

使用

聚合源的组合

use imnotjames\Syndicator\Article;
use imnotjames\Syndicator\Feed;
use imnotjames\Syndicator\Logo;
use imnotjames\Syndicator\Serializers\RSSXML;

$feed = new Feed(
	'My Rad Feed',
	'This feed is the coolest feed out there.',
	'https://github.com/imnotjames/syndicator'
);

$feed->setLogo(new Logo('http://i.imgur.com/haED2k7.jpg'));

$feed->setGenerator('Coolness Generator v95000');

$feed->setCacheTimeToLive(42);

$article = new Article();

$article->setTitle('How to be cool');
$article->setDescription('Step 1.  Be cool.  Step 2.  Don\'t be not cool.');
$article->setURI('http://example.com/blog/how-to-be-cool');

$feed->addArticle($article);

$serializer = new RSSXML();

$xml = $serializer->serialize($feed);

和解构

use imnotjames\Syndicator\Parsers\RSSXML;

$parser = new RSSXML();

$feed = $parser->parse(file_get_contents('awesome_feed.xml'));

printf("Title: %s\n\n", $feed->getTitle());

echo "Articles:\n";

foreach ($feed as $article) {
	printf("\tTitle: %s", $article->getTitle());
	echo "\n";
}

许可证

MIT 许可证