dotzecker/larafeed

适用于任何框架的 Feed (Atom 和 RSS) 生成器

2.1.0 2015-10-19 21:25 UTC

This package is not auto-updated.

Last update: 2024-09-14 13:45:38 UTC


README

Total Downloads

适用于任何框架的 Feed (Atom 和 RSS) 生成器

安装

为了安装,请通过 composer 执行此命令

composer require dotzecker/larafeed

用法

它有一个非常直观的 API。首先,我们需要实例化类(注意第一个参数是格式:atomrss)。

use DotZecker\Larafeed\Larafeed as Feed;

$feed = Feed::make(
    'atom', 
    [
        'title'       => 'My cool blog about my super afro hair',
        'link'        => 'http://rafa.im',
        'lang'        => 'en',
        'feedLink'    => 'http://rafa.im/blog/feed',
        'logo'        => 'http://rafa.im/images/logo.png',
        'icon'        => 'http://rafa.im/favicon.ico',
        'description' => "I'm super awesome and I like to code, do you?"
    ]
);

或者,如果您愿意,可以逐个属性填充

use DotZecker\Larafeed\Larafeed as Feed;

$feed = Feed::make('atom');

$feed->title       = 'My cool blog about my super afro hair';
$feed->link        = 'http://rafa.im';
$feed->description = "I don't say 'Hello World', the World says 'Hello Rafa' to me!";

然后,您可以添加作者

// Only with the name
$feed->addAuthor('Rafael Antonio');

// With full info
$feed->addAuthor(
    [
        'name'  => 'Rafa',
        'email' => 'mail@mail.foo',
        'uri'   => 'http://rafa.im'
    ]
);

现在轮到添加条目了。当然,在您的应用程序中,它将位于一个 foreach 循环中。

$feed->addEntry(
    [
        'title'   => 'Mi primer post',
        'link'    => 'http://rafa.im/blog/p/los-labels-y-la-usabilidad',
        'author'  => 'Rafael Antonio Gómez Casas',
        'pubDate' => '2013-03-15',
        'content' => 'Hola, este es mi primer post, Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nihil, quos, reprehenderit, nemo minus consectetur ipsum molestias cumque voluptatum deserunt impedit totam ab aspernatur rem voluptatibus dolore optio distinctio sequi vero harum neque qui suscipit libero deleniti minima repellat recusandae delectus beatae dignissimos corporis quaerat et nesciunt inventore architecto voluptates voluptatem.'
    ]
);

或者您可以逐个属性填充

$entry = $feed->entry();

$entry->title   = 'My super title';
$entry->content = '¿Qué tal? :P Lorem ipsum dolor sit amet, consectetur adipisicing elit. Error, aperiam!';
// $entry->...
$feed->setEntry($entry); // We "inject" the entry

最后,我们返回生成的 Feed,这将返回一个 Symfony\Component\HttpFoundation\Response 实例

return $feed->render();

许可证

Larafeed 使用 MIT 许可证授权。