roelofjan-elsinga/rss-feed-generator

一个易于生成RSS订阅源的包。

0.2.0 2019-11-26 13:11 UTC

This package is auto-updated.

Last update: 2024-09-27 00:03:12 UTC


README

Build status StyleCI Status Code coverage Total Downloads Latest Stable Version License

这个包可以帮助您非常容易地为您网站生成Atom Feed。

安装

您可以通过Composer使用以下命令来包含此包:

composer require roelofjan-elsinga/rss-feed-generator

用法

use RssFeedGenerator\RssFeedGenerator;

/**@var \RssFeedGenerator\FeedConfiguration $configuration*/

$generator = RssFeedGenerator::withConfiguration($configuration);

// or

$generator = new RssFeedGenerator($configuration);

/**@var \RssFeedGenerator\FeedItem $feed_item*/

$generator->add($feed_item);

$rss_string = $generator->generate();

print $rss_string;

这将导致以下结果:

<?xml version="1.0" encoding="utf-8"?>

<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>Feed title</title>
        <link href="https://example.com"/>
        <description>RSS 2.0 Description</description>
        <language>en-us</language>
        <pubDate>Tue, 10 Jun 2003 04:00:00 GMT</pubDate>
        <lastBuildDate>Tue, 10 Jun 2003 09:41:01 GMT</lastBuildDate>
        <docs>https://example.com/rss</docs>
        <atom:link href="https://example.com/rss" rel="self" type="application/rss+xml" />
        <generator>https://github.com/roelofjan-elsinga/rss-feed-generator</generator>
        <managingEditor>me@example.com (FirstName LastName)</managingEditor>
        <webMaster>me@example.com (FirstName LastName)</webMaster>
        <item>
            <title>Blog post title</title>
            <link>https://example.com/link/to/page</link>
            <description>Description of the page</description>
            <pubDate>Tue, 03 Jun 2003 09:39:21 GMT</pubDate>
            <guid>https://example.com/link/to/page</guid>
            <author>me@example.com (FirstName LastName)</author>
        </item>
    </channel>
</rss>

测试

您可以通过在终端中运行 ./vendor/bin/phpunit 来运行包含的测试。