rwslinkman / simple-rss-feed-renderer
用于托管RSS源的基本对象到RSS渲染器
1.5.0
2022-11-27 15:55 UTC
Requires
- ext-dom: *
- ext-simplexml: *
Requires (Dev)
- phpunit/phpunit: ^9.5
README
用于托管RSS源的基本对象到RSS渲染器
安装
使用Composer将simple-rss-feed-renderer
添加到您的依赖项中
composer require rwslinkman/simple-rss-feed-renderer
用法
以下是一个使用SimpleXmlFeedRenderer
的示例。
可以使用FeedBuilder
来创建数据对象。
RSS 2.0规范中的大多数属性都是可配置的。
以下示例中没有显示所有可配置属性。
// Article content loaded in a way preferred by you $articlesList = array(...); $feedBuilder = (new FeedBuilder()) ->withChannelTitle("Fun facts") ->withChannelDescription("Daily fun facts for you to read") ->withChannelUrl("https://funfacts.nl/articles"); foreach ($articlesList as $article) { $feedBuilder ->addItem() ->withTitle($article->getTitle()) ->withDescription($article->getSubtitle()) ->withLink("https://funfacts.nl/articles/" . $article->getId()) ->withPubDate($article->getCreatedAt()) ->buildItem(); } $rssFeed = $feedBuilder->build(); // Don't forget to set "application/rss+xml" for the "Content-Type" header $renderer = new SimpleRssFeedRenderer(); $renderer->configurePrettyPrint(true); $renderer->configureValidateBeforeRender(true); $rssXml = $renderer->render($rssFeed);
配置后,渲染器将对RssFeed
对象中提供的所有数据执行RSS 2.0验证。RssValidator
也可以单独运行
$feedBuilder = (new FeedBuilder()) ->withChannelTitle("Fun facts") ->withChannelDescription("Daily fun facts for you to read") ->withChannelUrl("https://funfacts.nl/articles"); $rssFeed = $feedBuilder->build(); // it will throw InvalidRssException containing the ValdationReport in case of errors $validator = new RssValidator(); $validator->validate($rssFeed);
其他
使用或不需要覆盖率运行phpunit
测试
./scripts/run_phpunit.sh ./scripts/run_phpunit_coverage.sh
可以使用Infection框架运行突变测试。
按照网站上的说明在本地上安装框架。
安装后,从项目根目录运行以下命令
infection --threads=10