roumen/feed 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

roumen/feed

Composer 安装命令:

composer require roumen/feed

包简介

Framework-agnostic PHP Feed generator for Laravel, Symfony, and more.

README 文档

README

CI codecov PHP Version Require Latest Stable Version License

A modern, framework-agnostic PHP Feed generator for Laravel, Symfony, and any PHP project. Generate RSS and Atom feeds with full caching support and customizable views.

Features

  • 🚀 Framework Agnostic: Works with Laravel, Symfony, or any PHP project
  • 📡 Multiple Formats: RSS 2.0 and Atom 1.0 support
  • Caching: Built-in caching support with framework adapters
  • 🎨 Custom Views: Use your own templates for feed generation
  • 🔧 Dependency Injection: Clean architecture with adapter pattern
  • 100% Test Coverage: Thoroughly tested with Pest
  • 📋 PSR-12 Compliant: Follows modern PHP standards
  • 🔒 Type Safe: Full PHP 8.3+ type declarations

Requirements

  • PHP 8.3+
  • Composer

Installation

composer require rumenx/php-feed

Usage Examples

Laravel

Basic Usage:

use Rumenx\Feed\FeedFactory;

class FeedController extends Controller
{
    public function feed()
    {
        $feed = FeedFactory::create();
        $feed->setTitle('My Blog Feed');
        $feed->setDescription('Latest posts from my blog');
        $feed->setLink('https://example.com');
        
        $feed->addItem([
            'title' => 'First Post',
            'author' => 'Rumen',
            'link' => 'https://example.com/post/1',
            'pubdate' => now(),
            'description' => 'This is the first post.'
        ]);
        
        // Return XML string directly
        $xml = $feed->render('rss');
        return response($xml, 200, [
            'Content-Type' => 'application/xml'
        ]);
    }
}

Using Laravel Views (Optional):

For more control, you can use the included Blade templates:

use Rumenx\Feed\FeedFactory;

class FeedController extends Controller  
{
    public function feed()
    {
        $feed = FeedFactory::create();
        $feed->setTitle('My Blog Feed');
        $feed->addItem([
            'title' => 'First Post',
            'author' => 'Rumen', 
            'link' => 'https://example.com/post/1',
            'pubdate' => now(),
            'description' => 'This is the first post.'
        ]);
        
        // Get data for your own view template
        $items = $feed->getItems();
        $channel = [
            'title' => $feed->getTitle(),
            'description' => $feed->getDescription(),
            'link' => $feed->getLink()
        ];
        
        return response()->view('feed.rss', compact('items', 'channel'), 200, [
            'Content-Type' => 'application/xml'
        ]);
    }
}

Symfony

Basic Usage:

use Rumenx\Feed\FeedFactory;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;

class FeedController extends AbstractController
{
    public function feed(): Response
    {
        $feed = FeedFactory::create();
        $feed->setTitle('My Blog Feed');
        $feed->setDescription('Latest posts from my blog');
        $feed->setLink('https://example.com');
        
        $feed->addItem([
            'title' => 'First Post',
            'author' => 'Rumen',
            'link' => 'https://example.com/post/1',
            'pubdate' => new \DateTime(),
            'description' => 'This is the first post.'
        ]);
        
        // Return XML response
        $xml = $feed->render('atom');
        return new Response($xml, 200, ['Content-Type' => 'application/xml']);
    }
}

Using Symfony Views (Optional):

For more control, you can use Twig templates:

class FeedController extends AbstractController
{
    public function feed(): Response
    {
        $feed = FeedFactory::create();
        $feed->setTitle('My Blog Feed');
        $feed->addItem([
            'title' => 'First Post',
            'author' => 'Rumen',
            'link' => 'https://example.com/post/1',
            'pubdate' => new \DateTime(),
            'description' => 'This is the first post.'
        ]);
        
        // Get data for your own Twig template
        $items = $feed->getItems();
        $channel = [
            'title' => $feed->getTitle(),
            'description' => $feed->getDescription(),
            'link' => $feed->getLink()
        ];
        
        return $this->render('feed/atom.xml.twig', [
            'items' => $items,
            'channel' => $channel
        ], new Response('', 200, ['Content-Type' => 'application/xml']));
    }
}

Plain PHP / Other Frameworks

Simple Usage (Recommended):

require 'vendor/autoload.php';

use Rumenx\Feed\FeedFactory;

// Create feed with simple built-in adapters
$feed = FeedFactory::create();
$feed->setTitle('My Feed');
$feed->setDescription('Feed description');
$feed->setLink('https://example.com');

$feed->addItem([
    'title' => 'Hello World',
    'author' => 'Rumen',
    'link' => 'https://example.com/hello',
    'pubdate' => date('c'),
    'description' => 'Hello world post!'
]);

// Output RSS feed
header('Content-Type: application/xml');
echo $feed->render('rss');

Advanced - Custom Adapters:

You can provide your own implementations for cache, config, response, and view:

use Rumenx\Feed\Feed;

$feed = new Feed([
    'cache' => new MyCacheAdapter(),
    'config' => new MyConfigAdapter(),
    'response' => new MyResponseAdapter(),
    'view' => new MyViewAdapter(),
]);

$feed->setTitle('My Feed');
$feed->addItem([
    'title' => 'Hello',
    'author' => 'Rumen',
    'link' => 'https://example.com/hello',
    'pubdate' => date('c'),
    'description' => 'Hello world!'
]);

// Use render() for framework-specific response
// or render() for XML string in plain PHP
echo $feed->render('rss');

Development

Available Composer Scripts

# Run tests
composer test

# Run tests with coverage
composer test:coverage

# Run tests with HTML coverage report
composer test:coverage-html

# Watch tests (automatically re-run on file changes)
composer test:watch

# Static analysis with PHPStan
composer analyse

# Check code style (PSR-12)
composer style

# Fix code style automatically
composer style:fix

# Run all checks (tests + analysis + style)
composer check

# Run CI checks (coverage + analysis + style)
composer ci

API Reference

Factory Method

// Create feed with simple adapters (recommended for most users)
$feed = FeedFactory::create($config);

Core Methods

// Feed configuration
$feed->setTitle(string $title): self
$feed->setDescription(string $description): self
$feed->setLink(string $link): self
$feed->setDateFormat(string $format): self
$feed->setLanguage(string $language): self

// Item management
$feed->addItem(array $item): self
$feed->addItems(array $items): self

// Rendering
$feed->render(string $format = 'rss'): mixed // Returns framework-specific response or XML string

// Caching
$feed->isCached(string $key): bool
$feed->clearCache(string $key): self

Architecture

This package follows a clean architecture pattern with dependency injection:

  • Feed: Core feed generator class
  • Adapters: Framework-specific implementations
    • FeedCacheInterface: Caching operations
    • FeedConfigInterface: Configuration access
    • FeedResponseInterface: HTTP response handling
    • FeedViewInterface: Template rendering

Support This Project

If you find this project useful, please consider supporting its development:

GitHub Sponsors

Other ways to support:

  • Star this repository
  • 🐛 Report bugs and suggest improvements
  • 💻 Contribute code or documentation
  • 💖 Make a donation - See FUNDING.md for details

Contributing

We welcome contributions! Please see our Contributing Guide for details.

Security

If you discover any security-related issues, please check our Security Policy.

License

This package is open-sourced software licensed under the MIT License.

Links

roumen/feed 适用场景与选型建议

roumen/feed 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 598.63k 次下载、GitHub Stars 达 363, 最近一次更新时间为 2013 年 05 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「symfony」 「generator」 「php」 「atom」 「feed」 「rss」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 roumen/feed 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 roumen/feed 我们能提供哪些服务?
定制开发 / 二次开发

基于 roumen/feed 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 598.63k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 379
  • 点击次数: 16
  • 依赖项目数: 8
  • 推荐数: 0

GitHub 信息

  • Stars: 363
  • Watchers: 17
  • Forks: 94
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-05-30