roelofjan-elsinga/atom-feed-generator

一个用于轻松生成Atom订阅源的包。

0.2.4 2020-12-29 14:00 UTC

This package is auto-updated.

Last update: 2024-08-29 05:24:30 UTC


README

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

此包可以帮助您非常轻松地为您的网站生成Atom Feed。

安装

您可以通过Composer包含此包,使用

composer require roelofjan-elsinga/atom-feed-generator

用法

use AtomFeedGenerator\AtomFeedGenerator;

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

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

// or

$generator = new AtomFeedGenerator($configuration);

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

$generator->add($feed_item);

$atom_string = $generator->generate();

print $atom_string;

这将生成以下结果:

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

<feed xmlns="http://www.w3.org/2005/Atom">
    <title>Feed title</title>
    <link href="https://example.com"/>
    <updated>2019-01-01T12:00:00+00:00</updated>
    <author>
        <name>Feed Author</name>
    </author>
    <id>https://example.com</id>
    <link rel="self" href='https://example.com/feed'/>
    <entry>
        <title>Article title</title>
        <link href="https://example.com/articles/test-article"/>
        <id>https://example.com/articles/test-article</id>
        <updated>2019-01-02T12:00:00+00:00</updated>
        <published>2019-01-01T12:00:00+00:00</published>
        <content>This is the content of the item</content>
        <summary>This is the summary</summary>
        <media:content xmlns:media="http://search.yahoo.com/mrss/" url="/images/test-image.jpg" medium="image" type="image/jpeg" width="1920" height="1080" />
    </entry>
</feed>

测试

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