Installation
composer require brainwasher/feed-bundle
Add to AppKernel.php:
new Nekland\FeedBundle\NeklandFeedBundle(),
Basic Configuration
In config/packages/nekland_feed.yaml (Symfony 4+) or app/config/config.yml (Symfony 2.1+):
nekland_feed:
feeds:
my_feed:
class: App\Entity\Post
title: 'My Posts'
description: 'Latest posts'
url: 'https://example.com'
language: 'en'
First Use Case Create a route to generate the feed:
# config/routes.yaml
nekland_feed_feed:
path: /feed
defaults: { _controller: 'NeklandFeedBundle:Feed:feed', feed: 'my_feed' }
Visit /feed to see the generated RSS/Atom feed.
Define Feed Entities
Implement Nekland\FeedBundle\Model\ItemInterface for your entity (e.g., Post):
use Nekland\FeedBundle\Model\ItemInterface;
class Post implements ItemInterface
{
public function getFeedRoutes()
{
return ['post_show']; // Array of routes for item links
}
public function getFeedTitle()
{
return $this->title;
}
// ... other required methods (see ItemInterface)
}
Dynamic Feed Generation
Use on-the-fly generation (default) or at-save (via event listeners):
# config.yml
nekland_feed:
feeds:
my_feed:
# ... config
save_feed: true # Enable at-save generation
Multiple Feeds
Configure multiple feeds in config.yml and route them separately:
nekland_feed:
feeds:
posts_feed:
class: App\Entity\Post
# ...
comments_feed:
class: App\Entity\Comment
# ...
Custom Feed Formats
Override the default Rss20 or Atom10 formats by extending Nekland\FeedBundle\Feed\FeedInterface:
class CustomFeed extends \Nekland\FeedBundle\Feed\Rss20
{
protected function getCustomXml()
{
return '<custom>...</custom>';
}
}
Register in config:
nekland_feed:
feeds:
my_feed:
class: App\Entity\Post
feed_class: App\Feed\CustomFeed
Integration with Controllers Manually trigger feed generation:
use Nekland\FeedBundle\Manager\FeedManager;
class FeedController extends AbstractController
{
public function generate(FeedManager $feedManager)
{
return $feedManager->generate('my_feed');
}
}
Route vs. URL in Config
post_show) in url.https://example.com/posts/{id}).
url: 'https://example.com' # Base URL for item links
ItemInterface Methods
ItemInterface (e.g., getFeedTitle(), getFeedUpdated()).Filename Formatting
|format| in feed names for dynamic formats.|format| to the feed name in config:
my_feed|atom: # Generates `/feed/atom` and `/feed/rss`
class: App\Entity\Post
Caching Issues
nekland_feed:
feeds:
my_feed:
cache: false
Namespace Conflicts
Nekland\FeedBundle namespace clashes in Symfony 4+.use Nekland\FeedBundle\Model\ItemInterface as FeedItemInterface;
Check Generated XML Enable debug mode and inspect the raw feed output to verify structure:
$feed = $feedManager->generate('my_feed');
dump($feed->getXml());
Event Listeners
Use feed.save events to debug at-save generation:
// src/EventListener/FeedListener.php
public function onFeedSave(FeedEvent $event)
{
if (!$event->isValid()) {
throw new \RuntimeException('Feed generation failed');
}
}
Register in services.yaml:
services:
App\EventListener\FeedListener:
tags:
- { name: kernel.event_listener, event: feed.save }
Logging
Enable logging in config/packages/monolog.yaml:
handlers:
feed:
type: stream
path: "%kernel.logs_dir%/feed.log"
level: debug
channels: ["feed"]
Custom Feed Classes
Extend Nekland\FeedBundle\Feed\FeedInterface to add custom logic (e.g., OpenGraph tags):
class OpenGraphFeed extends \Nekland\FeedBundle\Feed\Atom10
{
protected function getItemXml(ItemInterface $item)
{
$xml = parent::getItemXml($item);
$xml .= '<og:title>' . htmlspecialchars($item->getFeedTitle()) . '</og:title>';
return $xml;
}
}
Dynamic Feed Routes Override route generation for feeds:
nekland_feed:
feeds:
my_feed:
route: 'custom_feed_route' # Override default `/feed/{name}`
Query Customization Modify the default repository query for feeds:
// src/Entity/Post.php
public function getFeedQueryBuilder(FeedManager $manager)
{
$qb = $manager->getEntityManager()->createQueryBuilder();
$qb->select('p')
->from('App\Entity\Post', 'p')
->where('p.published = :published')
->setParameter('published', true);
return $qb;
}
Localization Use Symfony’s translation system for feed titles/descriptions:
nekland_feed:
feeds:
my_feed:
title: 'app.feed.posts_title' # Translatable key
description: 'app.feed.posts_desc'
In your entity:
public function getFeedTitle()
{
return $this->translator->trans('app.feed.posts_title');
}
How can I help you explore Laravel packages today?