Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ancoka/atom-feed

A simple atom feed builder for PHP
https://github.com/ancoka/atom-feed

atom-feed composer php rss rss-generator

Last synced: 2 months ago
JSON representation

A simple atom feed builder for PHP

Awesome Lists containing this project

README

        

# atom-feed
atom-feed是一个采用Atom协议的用于生成网站聚合应用信息的一个简单的PHP程序。

##安装
环境要求:PHP >= 5.4
直接使用composer命令安装:

```
composer require "ancoka/atom-feed:~1.0"
```
或者添加如下代码到composer.json文件中:

```
{
"require": {
"ancoka/atom-feed" : "~1.0"
}
}
```
然后运行composer来安装它

```
composer install
```
使用前引入 "vendor/autoload.php" 文件:

```
require_once 'vendor/autoload.php';
```
##使用

```
title('title')
->subtitle('subtitle')
->id('http://www.example.com')
->updated(time())
->link(['href' => 'http://www.example.com'])
->link(['href' => 'http://www.example.com/atom.xml', 'rel' => 'self'])
->rights('© 2005 Example, Inc.')
->appendTo($atom);

$entry = new Entry();
$entry->id('http://www.example.com/article/1')
->title('article title 1')
->subtitle('article subtitle 1')
->summary('article summary 1')
->content('article content 1')
->category(['term' => 'category1', 'scheme' => 'http://www.ucoolife.com/category/category1'])
->author(['name' => 'kevin', 'email' => '[email protected]', 'uri' => 'http://example.com/~kevin'])
->appendTo($feed);

$entry = new Entry();
$entry->id('http://www.example.com/article/2')
->title('article title 2')
->subtitle('article subtitle 2')
->summary('article summary 2')
->content('article content 2')
->category(['term' => 'category2', 'scheme' => 'http://www.ucoolife.com/category/category2'])
->author(['name' => 'kevin', 'email' => '[email protected]', 'uri' => 'http://example.com/~kevin'])
->appendTo($feed);

header('Content-type:application/atom+xml; charset=utf-8');
echo $atom;
```
上面代码涵盖常用用法,更多请查看接口文件源码:[AtomInterface](https://github.com/ancoka/atom-feed/blob/master/src/XMLBuilder/AtomInterface.php)、[FeedInterface](https://github.com/ancoka/atom-feed/blob/master/src/XMLBuilder/FeedInterface.php)和[EntryInterface](https://github.com/ancoka/atom-feed/blob/master/src/XMLBuilder/EntryInterface.php)

##参考

* [About atom feed](https://tools.ietf.org/html/rfc4287)

##License
MIT