Installation
composer require debril/rss-atom-bundle
Enable the bundle in config/bundles.php:
return [
// ...
Debril\RssAtomBundle\DebrilRssAtomBundle::class => ['all' => true],
];
First Use Case: Consuming a Feed
Inject the FeedIo service and fetch a feed:
use Debril\RssAtomBundle\FeedIo;
public function __construct(private FeedIo $feedIo) {}
public function getFeed(string $url): array
{
return $this->feedIo->load($url);
}
First Use Case: Generating a Feed
Create a controller extending StreamController:
use Debril\RssAtomBundle\Controller\StreamController;
class MyFeedController extends StreamController
{
public function feedAction()
{
return $this->renderFeed(
'my_feed',
[
'title' => 'My Feed',
'items' => [
['title' => 'Item 1', 'link' => '/item1'],
['title' => 'Item 2', 'link' => '/item2'],
],
]
);
}
}
Route it in config/routes.yaml:
my_feed:
path: /feed
controller: App\Controller\MyFeedController::feedAction
methods: GET
Fetching and Parsing
Use FeedIo to load and parse feeds dynamically:
$feed = $this->feedIo->load('https://example.com/feed.rss');
$items = $feed->getItems(); // Array of parsed feed items
Detecting Feed Type Automatically detect format (RSS, Atom, JSONFeed):
$format = $this->feedIo->detectFormat($url);
Handling Enclosures Extract media attachments:
foreach ($feed->getItems() as $item) {
if ($enclosure = $item->getEnclosure()) {
$url = $enclosure->getUrl();
$type = $enclosure->getType();
}
}
StreamController Workflow
Extend StreamController for efficient feed generation:
public function feedAction()
{
return $this->renderFeed(
'blog_feed',
[
'title' => 'Blog Updates',
'items' => $this->getLatestPosts(),
],
['format' => 'atom'] // Optional: Force format
);
}
Dynamic Feed Updates Leverage HTTP caching (304 Not Modified) by comparing ETags:
$this->renderFeed('feed', $data, [
'etag' => md5(json_encode($data)),
]);
Custom Templates
Override default templates in templates/DebrilRssAtomBundle/:
atom.xml.twigrss.xml.twigjsonfeed.json.twigIntegration with Doctrine Fetch entities and map to feed items:
$items = $this->entityManager
->getRepository(Post::class)
->findBy([], ['createdAt' => 'DESC'], 10)
->map(fn(Post $post) => [
'title' => $post->getTitle(),
'link' => $post->getSlug(),
'published' => $post->getCreatedAt()->format(DATE_ATOM),
]);
ETag Mismatches
md5(json_encode($data))).Template Overrides
templates/DebrilRssAtomBundle/ directory exists and permissions are correct.php bin/console cache:clear
FeedIo Timeouts
config/packages/debril_rss_atom.yaml):
debril_rss_atom:
feed_io:
timeout: 30
Character Encoding
$title = mb_convert_encoding($post->getTitle(), 'UTF-8');
Log Feed Parsing Issues Enable debug mode to log parsing errors:
debril_rss_atom:
feed_io:
debug: true
Validate Feed Output Use online validators (e.g., W3C Feed Validation) to check generated feeds.
Check Headers Inspect HTTP headers for caching issues:
curl -I http://your-app/feed
Look for ETag and Last-Modified headers.
Custom Feed Formats
Extend Debril\RssAtomBundle\Feed\FeedInterface to support additional formats.
Event Listeners
Subscribe to feed events (e.g., feed.io.load):
// config/services.yaml
services:
App\EventListener\FeedListener:
tags:
- { name: kernel.event_listener, event: feed.io.load, method: onFeedLoad }
Twig Extensions Add custom Twig filters for feed-specific logic:
// src/Twig/AppExtension.php
class AppExtension extends \Twig\Extension\AbstractExtension
{
public function getFilters()
{
return [
new \Twig\TwigFilter('feed_date', [$this, 'formatFeedDate']),
];
}
public function formatFeedDate(\DateTimeInterface $date): string
{
return $date->format(DATE_ATOM);
}
}
Symfony Messenger Integration Use Messenger to asynchronously process feed updates:
$this->messageBus->dispatch(new UpdateFeedMessage($feedUrl));
How can I help you explore Laravel packages today?