rudak/rss-bundle

Modern Symfony RSS Bundle for PHP 8.2+

Installs: 50

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 1

Forks: 0

Open Issues: 0

Type:symfony-bundle

pkg:composer/rudak/rss-bundle

dev-master 2025-12-09 16:47 UTC

This package is auto-updated.

Last update: 2025-12-09 16:47:08 UTC


README

Modern Symfony RSS Bundle for PHP 8.2+ and Symfony 6.4+/7.0+

CI

This bundle generates RSS feeds dynamically for your Symfony application.

Requirements

  • PHP 8.2 or higher
  • Symfony 6.4+ or 7.0+

Installation

Install the bundle via Composer:

composer require rudak/rss-bundle

If you're not using Symfony Flex, register the bundle manually in config/bundles.php:

return [
    // ...
    Rudak\RssBundle\RudakRssBundle::class => ['all' => true],
];

Configuration

Configure the bundle in config/packages/rudak_rss.yaml:

rudak_rss:
    rssparameters:
        entity:
            repository: 'App\Entity\Article'
            methodName: 'findLatestArticles'
        
        channel:
            title: 'My Blog RSS Feed'
            link: 'https://example.com'
            description: 'Latest articles from my blog'
            language: 'en'
            copyright: 'contact@example.com'
            webmaster: 'webmaster@example.com'
            managingEditor: 'editor@example.com'
            generator: 'Symfony RSS Bundle'
            ttl: '3600'
            pubDate:
                type: 'datetime'
            lastBuildDate:
                type: 'datetime'
            image:
                type: 'image'
                url: 'https://example.com/logo.png'
                title: 'My Blog'
                link: 'https://example.com'
        
        items:
            route: 'article_show'
            params:
                id: 'id'
                slug:
                    type: 'slug'
                    index: 'title'
        
        associations:
            title: 'title'
            description: 'description'
            guid: 'id'
            pubDate:
                type: 'datetime'
                index: 'createdAt'

Usage

Basic Usage

Inject the RSS generator service in your controller:

<?php

declare(strict_types=1);

namespace App\Controller;

use Rudak\RssBundle\Classes\RssGenerator;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class RssController extends AbstractController
{
    public function __construct(
        private readonly RssGenerator $rssGenerator
    ) {
    }

    #[Route('/rss.xml', name: 'rss_feed', methods: ['GET'])]
    public function feed(): Response
    {
        // Option 1: Let the generator fetch entities automatically
        $this->rssGenerator->makeTheRssContent();
        
        // Option 2: Or provide your own entities
        // $articles = $this->getDoctrine()
        //     ->getRepository(Article::class)
        //     ->findLatest(15);
        // $this->rssGenerator->setRssEntities($articles);
        // $this->rssGenerator->makeTheRssContent();
        
        // Write RSS file
        $this->rssGenerator->writeTheRssFile();
        
        return new Response('RSS feed generated successfully');
    }
}

Entity Requirements

Your entities should have getter methods matching the configuration:

<?php

declare(strict_types=1);

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
class Article
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    private ?int $id = null;

    #[ORM\Column(length: 255)]
    private ?string $title = null;

    #[ORM\Column(type: 'text')]
    private ?string $description = null;

    #[ORM\Column(type: 'datetime')]
    private ?\DateTimeInterface $createdAt = null;

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getTitle(): ?string
    {
        return $this->title;
    }

    public function getDescription(): ?string
    {
        return $this->description;
    }

    public function getCreatedAt(): ?\DateTimeInterface
    {
        return $this->createdAt;
    }
}

Development

Installing Dependencies

composer install

Running Tests

composer test

Code Style

Check coding standards:

composer cs-check

Fix coding standards:

composer cs-fix

Static Analysis

Run PHPStan:

composer stan

Features

  • ✅ Modern PHP 8.2+ with typed properties and constructor property promotion
  • ✅ Compatible with Symfony 6.4+ and 7.0+
  • ✅ PSR-12 coding standards
  • ✅ Full type hints and strict types
  • ✅ Automated testing with PHPUnit 10+
  • ✅ Static analysis with PHPStan (level 6)
  • ✅ GitHub Actions CI workflow
  • ✅ Automatic slug generation for URLs
  • ✅ Configurable RSS channel and item mapping

Upgrading from Version 1.x

This version introduces several breaking changes to modernize the codebase:

  1. PHP Requirement: Now requires PHP 8.2+
  2. Symfony Requirement: Now requires Symfony 6.4+ or 7.0+
  3. Namespace Changes: Files moved from root to src/ directory (PSR-4 autoloading)
  4. Service Configuration: Changed from YAML to PHP-based configuration
  5. Type Safety: All methods now use strict typing and return type declarations
  6. Service Access: The template namespace changed from RudakRssBundle to @RudakRss

Migration Steps

  1. Update your composer.json to require the new version
  2. Run composer update rudak/rss-bundle
  3. Update your service configuration to use the new parameters format
  4. Ensure your entities have proper getter methods with return type declarations
  5. Test your RSS feed generation

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This bundle is released under the GPL-3.0-or-later license. See the LICENSE file for details.

Credits

  • Original Author: Kadur Arnaud
  • Modernized for PHP 8.2+ and Symfony 6.4+/7.0+