├── .gitignore ├── README.md ├── README_zh.md ├── composer.json └── src ├── RssFacade.php └── RssServiceProvider.php /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## moell/rss 2 | Laravel package developed on the basis of [moell/rss](https://github.com/moell-peng/rss) 3 | 4 | ### RSS specification 5 | [http://www.rssboard.org/rss-specification](http://www.rssboard.org/rss-specification) 6 | 7 | ### 中文README 8 | [README](README_zh.md) 9 | 10 | ### Requirement 11 | Laravel 5+ 12 | 13 | ### Installation 14 | ```shell 15 | composer require moell/laravel-rss:1.* 16 | ``` 17 | ### Modify config/app.php 18 | ```shell 19 | #Append in providers 20 | Moell\LaravelRss\RssServiceProvider::class, 21 | 22 | #Append in aliases 23 | 'Rss' => Moell\LaravelRss\RssFacade::class, 24 | ``` 25 | 26 | ### Provides an interface 27 | ```php 28 | 29 | public function setEncode($encode); //默认UTF-8 30 | 31 | public function channel(array $channel); 32 | 33 | public function item(array $item); 34 | 35 | public function items(array $items); 36 | 37 | public function build(); 38 | 39 | public function fastBuild(array $channel, array $item); 40 | 41 | public function __toString(); 42 | ``` 43 | 44 | ### Usage 45 | ```php 46 | 47 | namespace App\Http\Controllers; 48 | 49 | use Illuminate\Http\Request; 50 | 51 | use App\Http\Requests; 52 | use Rss; 53 | 54 | class RssController extends Controller 55 | { 56 | public function index() 57 | { 58 | $channel = [ 59 | 'title' => 'title', 60 | 'link' => 'http://moell.cn', 61 | 'description' => 'description', 62 | 'category' => [ 63 | 'value' => 'html', 64 | 'attr' => [ 65 | 'domain' => 'http://www.moell.cn' 66 | ] 67 | ] 68 | ]; 69 | 70 | $rss = Rss::channel($channel); 71 | 72 | $items = []; 73 | for($i = 0; $i < 2; $i++) { 74 | $item = [ 75 | 'title' => "title".$i, 76 | 'description' => 'description', 77 | 'source' => [ 78 | 'value' => 'moell.cn', 79 | 'attr' => [ 80 | 'url' => 'http://www.moell.cn' 81 | ] 82 | ] 83 | ]; 84 | $items[] = $item; 85 | $rss->item($item); 86 | } 87 | 88 | return response($rss, 200, ['Content-Type' => 'text/xml']); 89 | 90 | //Other acquisition methods 91 | //return response($rss->build()->asXML(), 200, ['Content-Type' => 'text/xml']); 92 | 93 | //return response($rss->fastBuild($channel, $items)->asXML(), 200, ['Content-Type' => 'text/xml']); 94 | 95 | //return response($rss->channel($channel)->items($items)->build()->asXML(), 200, ['Content-Type' => 'text/xml']); 96 | 97 | } 98 | } 99 | ``` 100 | ### Generate results 101 | ```xml 102 | 103 | 106 | 107 | title 108 | http://moell.cn 109 | description 110 | html 111 | 112 | title0 113 | description 114 | moell.cn 115 | 116 | 117 | title1 118 | description 119 | moell.cn 120 | 121 | 122 | 123 | ``` 124 | 125 | ### License 126 | MIT 127 | -------------------------------------------------------------------------------- /README_zh.md: -------------------------------------------------------------------------------- 1 | ## moell/laravel-rss 2 | 在[moell/rss](https://github.com/moell-peng/rss)基础上开发的laravel包 3 | 4 | ### RSS规范 5 | [http://www.rssboard.org/rss-specification](http://www.rssboard.org/rss-specification) 6 | 7 | 8 | ### 要求 9 | Laravel 5+ 10 | 11 | ### 安装 12 | ```shell 13 | composer require moell/laravel-rss:1.* 14 | ``` 15 | 16 | ### 修改config/app.php 17 | ```shell 18 | #在providers中追加 19 | Moell\LaravelRss\RssServiceProvider::class, 20 | 21 | #在aliases中追加 22 | 'Rss' => Moell\LaravelRss\RssFacade::class, 23 | ``` 24 | ### 提供接口 25 | ```php 26 | //设置字符集 27 | public function setEncode($encode); //默认UTF-8 28 | 29 | public function channel(array $channel); 30 | 31 | public function item(array $item); 32 | 33 | public function items(array $items); 34 | 35 | //构造xml 36 | public function build(); 37 | 38 | //快速构造 39 | public function fastBuild(array $channel, array $item); 40 | 41 | public function __toString(); 42 | ``` 43 | 44 | ### 用法 45 | ```php 46 | namespace App\Http\Controllers; 47 | 48 | use Illuminate\Http\Request; 49 | 50 | use App\Http\Requests; 51 | use Rss; 52 | 53 | class RssController extends Controller 54 | { 55 | public function index() 56 | { 57 | $channel = [ 58 | 'title' => 'title', 59 | 'link' => 'http://moell.cn', 60 | 'description' => 'description', 61 | 'category' => [ 62 | 'value' => 'html', 63 | 'attr' => [ 64 | 'domain' => 'http://www.moell.cn' 65 | ] 66 | ] 67 | ]; 68 | 69 | $rss = Rss::channel($channel); 70 | 71 | $items = []; 72 | for($i = 0; $i < 2; $i++) { 73 | $item = [ 74 | 'title' => "title".$i, 75 | 'description' => 'description', 76 | 'source' => [ 77 | 'value' => 'moell.cn', 78 | 'attr' => [ 79 | 'url' => 'http://www.moell.cn' 80 | ] 81 | ] 82 | ]; 83 | $items[] = $item; 84 | $rss->item($item); 85 | } 86 | 87 | return response($rss, 200, ['Content-Type' => 'text/xml']); 88 | 89 | //其他获取方式 90 | //return response($rss->build()->asXML(), 200, ['Content-Type' => 'text/xml']); 91 | 92 | //return response($rss->fastBuild($channel, $items)->asXML(), 200, ['Content-Type' => 'text/xml']); 93 | 94 | //return response($rss->channel($channel)->items($items)->build()->asXML(), 200, ['Content-Type' => 'text/xml']); 95 | 96 | } 97 | } 98 | 99 | ``` 100 | ### 生成结果 101 | ```xml 102 | 103 | 106 | 107 | title 108 | http://moell.cn 109 | description 110 | html 111 | 112 | title0 113 | description 114 | moell.cn 115 | 116 | 117 | title1 118 | description 119 | moell.cn 120 | 121 | 122 | 123 | ``` 124 | 125 | ### License 126 | MIT 127 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "moell/laravel-rss", 3 | "description": "Based on moell/rss development laravel version", 4 | "keywords": ["rss","laravel"], 5 | "type": "library", 6 | "license": "MIT", 7 | "authors": [ 8 | { 9 | "name": "Moell", 10 | "email": "moell91@foxmail.com" 11 | } 12 | ], 13 | "minimum-stability": "dev", 14 | "require": { 15 | "moell/rss" : "1.*" 16 | }, 17 | "autoload" : { 18 | "psr-4": { 19 | "Moell\\LaravelRss\\": "src/" 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/RssFacade.php: -------------------------------------------------------------------------------- 1 | app->singleton('rss', function($app) { 30 | return new Rss(); 31 | }); 32 | } 33 | 34 | /** 35 | * @return array 36 | */ 37 | public function provides() 38 | { 39 | return ['rss']; 40 | } 41 | } 42 | --------------------------------------------------------------------------------