dark-chyper / open-feed
A lightweight, framework-agnostic PHP library to generate RSS feeds with XMLWriter
Requires
- php: >=8.2
- ext-xmlwriter: *
Requires (Dev)
- ext-dom: *
- friendsofphp/php-cs-fixer: ^3.94
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.0
- psr/http-factory: ^1.0
- psr/http-message: ^1.1 || ^2.0
- symfony/http-foundation: ^6.0 || ^7.0
Suggests
- psr/http-factory-implementation: Required to use the universal PSR-7 bridge
- symfony/http-foundation: Required for Symfony integration (FeedResponseFactory)
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.