dark-chyper/open-feed 问题修复 & 功能扩展

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

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

dark-chyper/open-feed

最新稳定版本:v0.1.0

Composer 安装命令:

composer require dark-chyper/open-feed

包简介

A lightweight, framework-agnostic PHP library to generate RSS feeds with XMLWriter

README 文档

README

A lightweight, framework-agnostic PHP library to generate RSS 2.0 and Atom 1.0 feeds.

Designed to be simple, reliable, and decoupled, OpenFeed separates your data models from the rendering logic, allowing you to switch formats with ease.

Features

  • Multi-format support: RSS 2.0 and Atom 1.0 compliant.
  • Clean Architecture: Data models are format-agnostic.
  • XMLWriter-based: Memory-efficient and safe XML generation.
  • Full Support for:
    • Channel/Feed metadata (Title, Link, Subtitle, ID).
    • Images and Logos.
    • Item enclosures (absolute URLs: http, https, gemini, gopher).
    • Categories (with optional domain/scheme).
    • Authors (Email and Name).
    • Rich HTML content (via CDATA).
  • No framework dependency.
  • Bridges: Native support for Symfony and PSR-7/17.

Installation

composer require dark-chyper/open-feed

Note on Dates: It is highly recommended to provide dates in UTC. The library automatically formats them to RFC 2822 for RSS compliance.

> Note on Enclosures: For RSS 2.0 compliance, enclosure URLs must be absolute. OpenFeed natively supports http, https, and decentralized protocols like gemini and gopher.

Basic usage

OpenFeed uses a common set of models for both formats.

Generating an Atom Feed

use OpenFeed\AtomFeed;
use OpenFeed\Common\FeedItem;
use OpenFeed\Common\FeedItemAuthor;

$feed = (new AtomFeed())
    ->setTitle('OpenFeed News')
    ->setId('urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6')
    ->setLink('[https://example.com](https://example.com)')
    ->setSubtitle('Latest updates from the library');

$item = (new FeedItem())
    ->setTitle('Atom Support Added')
    ->setId('[https://example.com/news/1](https://example.com/news/1)')
    ->setLink('[https://example.com/news/1](https://example.com/news/1)')
    ->setDescription('OpenFeed now supports Atom 1.0!')
    ->setContent('<p>Check out our <strong>new architecture</strong>.</p>')
    ->setAuthor(new FeedItemAuthor('dev@example.com', 'Simon'));

$feed->addItem($item);

echo $feed->render();

Generating an RSS 2.0 Feed

use OpenFeed\RssFeed;
use OpenFeed\Common\FeedItem;

$feed = (new RssFeed())
    ->setTitle('My RSS Feed')
    ->setLink('[https://example.com](https://example.com)')
    ->setDescription('A classic RSS feed')
    ->setTtl(60); // RSS specific method

$item = (new FeedItem())
    ->setTitle('Hello World')
    ->addEnclosure('[https://example.com/audio.mp3](https://example.com/audio.mp3)', 'audio/mpeg', 12345);

$feed->addItem($item);

echo $feed->render();

Sending output

Plain PHP

$feed->render();

The library provides bridges to handle HTTP responses automatically with the correct Content-Type.

Symfony Bridge

use OpenFeed\Bridge\Symfony\FeedResponseFactory;

// Works with RssFeed or AtomFeed
return (new FeedResponseFactory())->toResponse($feed);

PSR-7 (Universal)

Works with any PSR-7/PSR-17 compliant implementation (Slim, Mezzio, Laravel, etc.).

use OpenFeed\Bridge\Psr\PsrFeedResponseFactory;

// Requires PSR-17 factories (e.g. Nyholm/Psr7)
$bridge = new PsrFeedResponseFactory($responseFactory, $streamFactory);

return $bridge->toResponse($feed);

Structure

src/
├── AbstractFeed.php          # Base class for all feeds
├── RssFeed.php               # RSS specific implementation
├── AtomFeed.php              # Atom specific implementation
├── Common/                   # Agnostic data models
│   ├── FeedCategory.php
│   ├── FeedEnclosure.php
│   ├── FeedImage.php
│   ├── FeedItem.php
│   └── FeedItemAuthor.php
├── Bridge/                   # Framework integrations
│   ├── Psr/
│   └── Symfony/
└── Renderer/                 # Format-specific rendering logic
    ├── FeedRendererInterface.php
    ├── Rss20Renderer.php
    └── AtomRenderer.php

Philosophy

OpenFeed focuses on:

  • simplicity over abstraction
  • correctness over magic
  • portability across projects

Roadmap

  • [X] Atom renderer
  • [X] Categories support
  • [X] Author support
  • [ ] Cache headers helpers

License

This project is licensed under the GNU Lesser General Public License v3.0 or later.

See the LICENSE and COPYING.LESSER files for more details.

统计信息

  • 总下载量: 2
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 5
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-03

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固