torann / podcastfeed
为Laravel 5中的播客生成RSS订阅源。
0.2.2
2016-09-01 20:24 UTC
Requires
- php: >=5.5.9
- illuminate/support: ~5.1
This package is auto-updated.
Last update: 2024-09-08 10:10:56 UTC
README
为Laravel 5生成播客的RSS订阅源。
安装
从命令行运行
$ composer require torann/podcastfeed
设置
一旦安装,您需要将服务提供者注册到应用程序中。打开config/app.php
文件,找到providers
键。
'providers' => [ ... Torann\PodcastFeed\PodcastFeedServiceProvider::class, ... ]
此包还包含一个外观(facade),它提供了一种轻松调用类的方法。打开config/app.php
文件,找到aliases
键
'aliases' => [ ... 'PodcastFeed' => Torann\PodcastFeed\Facades\PodcastFeed::class, ... ];
发布配置
从项目根目录在命令行上运行此命令
$ php artisan vendor:publish --provider="Torann\PodcastFeed\PodcastFeedServiceProvider"
配置文件将被发布到config/podcast-feed.php
。
方法
setHeader 可以通过配置文件或使用setHeader
方法手动设置源头。
PodcastFeed::setHeader([ 'title' => 'All About Everything', 'subtitle' => 'A show about everything', 'description' => 'Great site description', 'link' => 'http://www.example.com/podcasts/everything/index.html', 'image' => 'http://example.com/podcasts/everything/AllAboutEverything.jpg', 'author' => 'John Doe', 'email' => 'john.doe@example.com', 'category' => 'Technology', 'language' => 'en-us', 'copyright' => '2016 John Doe & Family', ]);
addMedia 向源中添加媒体。
foreach($this->podcastRepository->getPublished() as $podcast) { PodcastFeed::addMedia([ 'title' => $podcast->title, 'description' => $podcast->title, 'publish_at' => $podcast->publish_at, 'guid' => route('podcast.show', $podcast->slug), 'url' => $podcast->media->url(), 'type' => $podcast->media_content_type, 'duration' => $podcast->duration, 'image' => $podcast->image->url(), ]); }
toString 将源转换为可展示的字符串。以下示例是从控制器中提取的。理论上,您可以实现一种缓存方法,这样就不需要每次都渲染。
public function index() { foreach($this->podcastRepository->getPublished() as $podcast) { PodcastFeed::addMedia([ 'title' => $podcast->title, 'description' => $podcast->title, 'publish_at' => $podcast->publish_at, 'guid' => route('podcast.show', $podcast->slug), 'url' => $podcast->media->url(), 'type' => $podcast->media_content_type, 'duration' => $podcast->duration, 'image' => $podcast->image->url(), ]); } return Response::make(PodcastFeed::toString()) ->header('Content-Type', 'text/xml'); }
变更日志
v0.2.1
- 修复了像'æ'、'ø'和'å'这样的外文字符
v0.2.0
- 支持Laravel 5
v0.1.0
- 首次发布