Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Feed Bundle Laravel Package

brainwasher/feed-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require brainwasher/feed-bundle
    

    Add to AppKernel.php:

    new Nekland\FeedBundle\NeklandFeedBundle(),
    
  2. 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'
    
  3. 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.


Implementation Patterns

Core Workflow

  1. 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)
    }
    
  2. 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
    
  3. 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
                # ...
    
  4. 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
    
  5. 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');
        }
    }
    

Gotchas and Tips

Common Pitfalls

  1. Route vs. URL in Config

    • Mistake: Using a Symfony route (e.g., post_show) in url.
    • Fix: Always use a full URL (e.g., https://example.com/posts/{id}).
      url: 'https://example.com'  # Base URL for item links
      
  2. ItemInterface Methods

    • Missing Methods: Forgetting to implement all required methods in ItemInterface (e.g., getFeedTitle(), getFeedUpdated()).
    • Fix: Use the wiki as a reference.
  3. Filename Formatting

    • Mistake: Forgetting |format| in feed names for dynamic formats.
    • Fix: Append |format| to the feed name in config:
      my_feed|atom:  # Generates `/feed/atom` and `/feed/rss`
          class: App\Entity\Post
      
  4. Caching Issues

    • Problem: Feeds not updating after entity changes.
    • Fix: Clear the cache or disable caching temporarily:
      nekland_feed:
          feeds:
              my_feed:
                  cache: false
      
  5. Namespace Conflicts

    • Issue: Nekland\FeedBundle namespace clashes in Symfony 4+.
    • Fix: Use fully qualified names or aliases in code:
      use Nekland\FeedBundle\Model\ItemInterface as FeedItemInterface;
      

Debugging Tips

  1. Check Generated XML Enable debug mode and inspect the raw feed output to verify structure:

    $feed = $feedManager->generate('my_feed');
    dump($feed->getXml());
    
  2. 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 }
    
  3. Logging Enable logging in config/packages/monolog.yaml:

    handlers:
        feed:
            type: stream
            path: "%kernel.logs_dir%/feed.log"
            level: debug
            channels: ["feed"]
    

Extension Points

  1. 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;
        }
    }
    
  2. Dynamic Feed Routes Override route generation for feeds:

    nekland_feed:
        feeds:
            my_feed:
                route: 'custom_feed_route'  # Override default `/feed/{name}`
    
  3. 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;
    }
    
  4. 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');
    }
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed