fabricio872/easy-rss-bundle

用于管理RSS订阅的Symfony包,只需添加项目并设置限制,包将自动处理存储项目及删除旧项目。

v0.1.1 2023-06-05 14:36 UTC

This package is auto-updated.

Last update: 2024-09-05 17:28:29 UTC


README

GitHub tag (latest by date) GitHub last commit Packagist Downloads GitHub Repo stars

Easy RSS

用于管理RSS订阅的Symfony包,只需添加项目并设置限制,包将自动处理存储项目及删除旧项目。

安装

请确保全局已安装Composer,如Composer文档中的安装章节所述。

使用Symfony Flex的应用程序

打开命令行控制台,进入您的项目目录并执行

$ composer require fabricio872/easy-rss-bundle

不使用Symfony Flex的应用程序

步骤 1: 下载包

打开命令行控制台,进入您的项目目录,并执行以下命令以下载此包的最新稳定版本

$ composer require fabricio872/easy-rss-bundle

步骤 2: 启用包

然后,通过将其添加到项目中 config/bundles.php 文件中注册的包列表中来启用该包

// config/bundles.php
return [
    // ...
    Fabricio872\RandomMessageBundle\EasyRssBundle::class => ['all' => true],
];

配置选项

# config/services.yaml

# ...

# Default configuration for extension with alias: "easy_rss"
easy_rss:

 # Maximum feeds that would be stored. (0 to unlimited)
 max_feeds:            10

# ...

用法

首先,我们需要创建一个可以连接RSS阅读器的端点

// src/Controller/RssController.php

//...

    #[Route('/rss.xml', name: 'app_rss_feed')]
    public function index(EasyRss $easyRss): Response
    {
        return $easyRss->getResponse('Title for RSS feed');
    }
    
//...

然后,您可以开始添加订阅源

  • 创建Feed对象
// src/any-place-in-your-project

//...

    $feed = new \Fabricio872\EasyRssBundle\DTO\Feed();
    $feed->setTitle('My first post');
    $feed->setDescription('This is my first post.');

//...
  • 发布订阅源
// src/any-place-in-your-project

//...

    public function someMethodWithDependencyInjection(\Fabricio872\EasyRssBundle\EasyRss $easyRss)
    {
        $easyRss->setMaxFeeds(); // OPTIONAL this option is override for what you have set in config
        
        $easyRss->add($feed); // this will put your feed to DB and remove old feeds if there are more than MaxFeeds
    }

//...

如果您的页面只有一个RSS订阅频道,那么您就完成了。

多个RSS频道

为每个频道创建更多端点

// src/Controller/RssController.php

//...

    #[Route('/rss_one.xml', name: 'app_rss_one_feed')]
    public function rss_one(EasyRss $easyRss): Response
    {
        return $easyRss->getResponse('Title for first RSS feed', 'first'); // second parameter is channel identifier
    }

    #[Route('/rss_two.xml', name: 'app_rss_two_feed')]
    public function rss_two(EasyRss $easyRss): Response
    {
        return $easyRss->getResponse('Title for second RSS feed', 'second'); // second parameter is channel identifier
    }
    
//...

使用定义的频道创建订阅源

// src/any-place-in-your-project

//...

    $feed = new \Fabricio872\EasyRssBundle\DTO\Feed();
    $feed->setTitle('My first post');
    $feed->setChannel('first'); // name of the channel has to be same as defined in controller
    $feed->setDescription('This is my first post.');

//...

使用定义的频道添加订阅源的方式与上面所示相同。