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

Laminas Feed Laravel Package

laminas/laminas-feed

Laminas\Feed provides tools for reading and creating RSS and Atom feeds in PHP. Parse feeds, work with entries and metadata, and generate valid syndication output for your applications or services.

View on GitHub
Deep Wiki
Context7

Getting Started

Start by installing laminas/laminas-feed via Composer, then use Laminas\Feed\Reader\Reader::import($url) to fetch and parse RSS or Atom feeds. The method returns either a Feed\RSS or Feed\Atom object (auto-detected), offering a consistent interface: $feed->getTitle(), $feed->getAuthor(), $feed->count(), and iteration over entries via foreach. For entries, access properties like $entry->getTitle(), $entry->getDescription(), and $entry->getLink(). If not using laminas-http, inject an HTTP client into Reader::setHttpClient()—this is critical for import() to function. First use case: pull blog posts or news headlines for aggregation or caching.

Implementation Patterns

  • Caching Feeds: Combine with PSR-6/PSR-16 cache adapters (e.g., using Laminas\Cache) to store parsed feeds and reduce HTTP calls. Store the feed XML or deserialized entry objects, with cache TTL based on feed pubDate or max-age hints.
  • Extending Entry/Feed Classes: Extend Reader\Entry\Rss or Reader\Entry\Atom to add domain-specific getters (e.g., getEnclosureUrl() for podcast feeds), or implement Reader\FeedInterface/Reader\EntryInterface for custom behavior.
  • Hybrid RSS/Atom Handling: Use Reader::import() without type assumptions—both feed types expose consistent methods (getTitle(), getEntries()) even if internally backed by different parsers.
  • Extending with Extensions: Leverage built-in extension support (e.g., podcast-index via Reader::getExtensions()) or register custom namespaces. Use Reader::getReader() to access the underlying reader instance and peek at namespaces via getNamespaces().
  • Background Feed Updates: Integrate into Laravel jobs (e.g., FeedFetcherJob) with error recovery—wrap import() in try/catch to handle network failures or malformed XML.

Gotchas and Tips

  • Missing HTTP Client: Reader::import() silently fails if no HTTP client is available—ensure laminas/laminas-http is installed or inject a PSR-18 client explicitly.
  • Namespace Handling: Extensions like Podcast Index require explicit registration via Reader::registerExtension(). Check availability with Reader::hasExtension('PodcastIndex').
  • String vs Object Getter Returns: Some getters (e.g., getAuthor()) may return arrays (e.g., ['name' => '...', 'email' => '...']) depending on feed structure—always validate return type before accessing keys.
  • Date Parsing: Atom/RSS dates are returned as strings—use DateTime construction to normalize them, e.g., new \DateTime($entry->getDatePublished()).
  • Lazy Parsing: Feeds are parsed on first access (e.g., count(), iteration)—avoid redundant calls to $feed->getEntries() inside loops.
  • Error Handling: Fetch failures throw Exception\RuntimeException; malformed feeds may throw Exception\DomException—log feed URLs alongside exceptions for debugging.
  • Content vs Description: Atom entries distinguish getSummary() and getContent(); RSS uses getDescription(). Prefer getContent() or getDescription() conditionally based on feed type.
  • UTF-8 Encoding Enforcement: As of v2.26.1, DOM documents are explicitly set to UTF-8 encoding when the feed lacks an XML declaration (e.g., <?xml version="1.0" encoding="UTF-8"?>). This prevents garbled characters in multi-byte fields (e.g., titles/descriptions in non-Latin scripts). Verify output with mb_check_encoding() if handling localized content.
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4