hyancat/larss

Laravel 5 的 RSS 构建器

v1.4 2016-10-30 12:50 UTC

This package is auto-updated.

Last update: 2024-09-15 22:03:11 UTC


README

Laravel 5 的 RSS 构建器

安装

  1. 使用 composer 下载此包

     composer require hyancat/larss
    
  2. 将服务提供者添加到 app/config/app.php 文件中的 providers 数组中。

     'Hyancat\Larss\LarssServiceProvider'
    
  3. 最后,将别名添加到 app/config/app.php 文件中的 alias 数组中。

     'RSS'		=> 'Hyancat\Larss\LarssFacade',
    

用法

带缓存的用法

$rss = \RSS::make();
if (! $rss->caching(10)) {

	// make channel.
	$rss->channel([
		'title'       => 'title',
		'description' => 'description',
		'link'        => 'http://www.xxx.yyy',
	])->withImage([
		'url'   => 'http://www.xxx.yyy/logo.png',
	  	'title' => 'title',
	  	'link'  => 'http://www.xxx.yyy',
	]);

	// gen posts data ......
	foreach ($posts as $post) {
		$rss->item([
			'title'             => $post->title,
			'description|cdata' => $post->body,
			'link'              => $post->url,
			// ......
		]);
	}
}

// If you want to save the rss data to file.
$rss->save('rss.xml');

// Or just make a response to the http request.
return \Response::make($rss->render(), 200, ['Content-Type' => 'text/xml']);

不带缓存的用法

// make with channel.
$rss = \RSS::make()->channel([
	'title'       => 'title',
	'description' => 'description',
	'link'        => 'http://www.xxx.yyy',
	// ......
])->withImage([
	'url'   => 'http://www.xxx.yyy/logo.png',
	'title' => 'title',
	'link'  => 'http://www.xxx.yyy',
]);

// gen posts data ......
foreach ($posts as $post) {
	$rss->item([
		'title'             => $post->title,
		'description|cdata' => $post->body,
		'link'              => $post->url,
		// ......
	]);
}

return ...;