PHPackages                             benkle/feeding - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. benkle/feeding

Abandoned → [benkle/feed-parser](/?search=benkle%2Ffeed-parser)Library[Parsing &amp; Serialization](/categories/parsing)

benkle/feeding
==============

Rule-based RSS and Atom parser

1.2.0(9y ago)422MITPHP &gt;=5.6.0

Since May 26Compare

[ Source](https://github.com/benkle-libs/feeding)[ Packagist](https://packagist.org/packages/benkle/feeding)[ RSS](/packages/benkle-feeding/feed)WikiDiscussions Synced 2d ago

READMEChangelogDependencies (4)Versions (4)Used By (0)

A rule-based RSS and Atom parser
================================

[](#a-rule-based-rss-and-atom-parser)

This PHP library contains an extensible, rule based parser for RSS and Atom news feeds. It's way of working is inpsired by [Alex Debril's feed-io](https://packagist.org/packages/debril/feed-io), but it's been rewritten from scratch to be a bit cleaner and more easily extensible. It doesn't have all the features of the original, but you can easily create new parsing standards or extend existing one without rummaging through the library code.

Requirements
------------

[](#requirements)

- PHP 5.6+
- [guzzlehttp/guzzle](https://packagist.org/packages/guzzlehttp/guzzle) 6.2+
- [masterminds/html5](https://packagist.org/packages/masterminds/html5) 2.2+
- [psr/log](https://packagist.org/packages/psr/log) 1.0+

Installation
------------

[](#installation)

*Feeding* can be included in the usual way with composer:

```
    composer require benkle/feeding
```

Usage
-----

[](#usage)

For a quick start you can instantiate the class `\Benkle\Feeding\Reader` and directly fetch a feed:

```
$reader = new \Benkle\Feeding\Reader();
$feed = $reader->read('http://xkcd.com/atom.xml');

echo $feed->getTitle() . PHP_EOL;
foreach ($feed->getItems() as $item) {
    echo "\t" . $item->getTitle() . PHP_EOL;
}
```

The `Reader::read` can take urls, file pathes or the direct feed source, and will select one of the preexisting feed standards to parse the data into objects.

### Create your own rules

[](#create-your-own-rules)

*Feeding* is based on rules, which are organized on standards.

A rule can be any class implementing `\Benkle\Feeding\Interfaces\RuleInterface`:

```
class MyRule implements \Benkle\Feeding\Interfaces\RuleInterface {
    public function canHandle(\DOMNode $node, \Benkle\Feeding\Interfaces\NodeInterface $target)
    {
        return $node->nodeName == 'title' && $target instanceof \Benkle\Feeding\Interfaces\ChannelInterface;
    }

    public function handle(\Benkle\Feeding\Parser $parser, \DOMNode $node, \Benkle\Feeding\Interfaces\NodeInterface $target)
    {
        /** \Benkle\Feeding\Interfaces\ChannelInterface $target */
        $target->setTitle($node->nodeValue);
    }
}
```

Rules can be added to any standard via it's rule set, which is a priority ordered list:

```
/** @var \Benkle\Feeding\Interfaces\StandardInterface $standard */
foreach ($reader->getStandards() as $standard) {
    $standard->getRules()->add(new MyRule(), 5); // Rules are ordered by priority
}
```

But often you might want to aggregate all your rules in a standard. Standards are classes implementing `\Benkle\Feeding\Interfaces\StandardInterface`:

```
class MyStandard implements \Benkle\Feeding\Interfaces\StandardInterface {
    use \Benkle\Feeding\Traits\WithParserTrait;
    use \Benkle\Feeding\Traits\WithRuleSetTrait;

    public function __construct()
    {
        $this->getRules()->add(new MyRule(), 5);
    }

    public function newFeed()
    {
        return new \Benkle\Feeding\Feed();
    }

    public function getRootNode(\DOMDocument $dom)
    {
        return $dom->getElementsByTagName('feed')->item(0);
    }

    public function canHandle(\DOMDocument $dom)
    {
        return $dom->getElementsByTagName('feed')->length > 0;
    }
}
```

Adding a standard to a Reader is just as simple as adding a rule to a standard:

```
$reader->getStandards()->add(new MyStandard(), 5);
```

Included standards are:

- `Atom10Standard` for Atom 1.0
- `RSS09Standard` for RSS 0.9
- `RSS10Standard` for RSS 1.0
- `RSS20Standard` for RSS 2.0

### Set your own DOM parser

[](#set-your-own-dom-parser)

This library uses the PHP DOM library classes for it's XML traversing. To use your own library you have to write a wrapper arround it implementing `\Benkle\Feeding\Interfaces\DOMParserInterface`:

```
$reader->setDomParser(new class implements \Benkle\Feeding\Interfaces\DOMParserInterface {
    public function parse($source)
    {
        $parser = new \MyFancy\DomParser();
        return $parser->parse($source);
    }
});
```

*Feeding* already include a wrapper for the standard library, which is fast but fails when a feeds isn't valid XML, and for the [Masterminds HTML5 parser](https://packagist.org/packages/masterminds/html5), which is more fault tolerant, but also way slower. It also includes a meta wrapper which will try any number of other wrappers it is given, allowing you to balance speed and reliability:

```
$reader->setDomParser(
    new \Benkle\Feeding\DOMParsers\FallbackStackParser(
        new \Benkle\Feeding\DOMParsers\PHPDOMParser(),
        new \Benkle\Feeding\DOMParsers\MastermindsHTML5Parser()
    )
);
```

**Note:** This Wrapper implements `Psr\Log\LoggerAwareInterface` and will write notices whenever any of it's protegé throws an exception!

### Set your own file access

[](#set-your-own-file-access)

If you need your own access (e.g. because you want to use [flysystem](http://flysystem.thephpleague.com/)) you have to write a wrapper as well, this time implementing `\Benkle\Feeding\Interfaces\FileAccessInterface`:

```
$reader->setFileAccess(new class implements \Benkle\Feeding\Interfaces\FileAccessInterface {
    private $myFs;

    public function __construct()
    {
        $this->myFs = new MyFs();
    }

    public function exists($filename)
    {
        return $this->myFs->exists($filename);
    }

    public function get($filename)
    {
        return $this->myFs->open($filename);
    }
});
```

### More control

[](#more-control)

If you need more control over what standards are loaded, and don't need file and http access, you can use the `\Benkle\Feeding\BareReader` class:

```
$reader = new \Benkle\Feeding\BareReader();
$reader->setDomParser(new \Benkle\Feeding\DOMParsers\PHPDOMParser());
$reader->getStandards()->add(new \Benkle\Feeding\Standards\RSS\RSS20Standard());
```

TODO
----

[](#todo)

- Moved included class `PriorityList` to a utility package.
- Put Guzzle behind a facade similar to the `FileAccessInterface`?

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~31 days

Total

3

Last Release

3626d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/424349?v=4)[Benjamin Kleiner](/maintainers/bizzl-greekdog)[@bizzl-greekdog](https://github.com/bizzl-greekdog)

---

Top Contributors

[![bizzl-greekdog](https://avatars.githubusercontent.com/u/424349?v=4)](https://github.com/bizzl-greekdog "bizzl-greekdog (46 commits)")

---

Tags

parseratomfeedrssRDF

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/benkle-feeding/health.svg)

```
[![Health](https://phpackages.com/badges/benkle-feeding/health.svg)](https://phpackages.com/packages/benkle-feeding)
```

###  Alternatives

[laravel/framework

The Laravel Framework.

34.8k543.8M19.9k](/packages/laravel-framework)[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

21866.0M1.7k](/packages/drupal-core)[drupal/core-recommended

Locked core dependencies; require this project INSTEAD OF drupal/core.

6942.5M413](/packages/drupal-core-recommended)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k13](/packages/tempest-framework)[typo3/cms

TYPO3 CMS is a free open source Content Management Framework initially created by Kasper Skaarhoj and licensed under GNU/GPL.

1.2k1.9M122](/packages/typo3-cms)[typo3/cms-core

TYPO3 CMS Core

3713.2M5.1k](/packages/typo3-cms-core)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
