Developed with love by KnpLabs Hire us for your project!
21

FeedIoBundle

by alexdebril

Rss / Atom bundle provided by feed-io

FeedIoBundle

Latest Stable Version
Build Status
Scrutinizer Code Quality
Code Coverage

feed-io bundle for the Symfony Framework

What is feed-io ?

feed-io is a PHP library built to consume and serve RSS / Atom feeds. It features:

  • Atom / RSS read and write support
  • HTTP Headers support when reading feeds in order to save network traffic
  • Detection of the format (RSS / Atom) when reading feeds
  • PSR compliant logging
  • Content filtering to fetch only the newest items
  • DateTime detection and conversion
  • A generic HTTP ClientInterface
  • Guzzle Client integration

FeedIoBundle features

  • A generic StreamController built to write all your feeds. This controller is able to send a 304 HTTP Code if the feed didn't change since the last visit
  • A generic StorageInterface to handle read/write operations on a data source
  • Commands to save external feeds' content

Keep informed about new releases and incoming features : http://debril.org/category/feed-io

FeedIoBundle history

FeedIoBundle is a fork of rss-atom-bundle. The main difference is the integration of feed-io.

 Installation

Edit composer.json and add the following line in the "require" section:

    "debril/feedio-bundle": "dev-master"

Ask Composer to install it:

    composer.phar update debril/feedio-bundle

Alternatively, add the dependence using command line :

    composer.phar require debril/feedio-bundle

Now you need to include the bundle into your project's configuration. First, edit your app/AppKernel.php to register the bundle in the registerBundles() method as above:

class AppKernel extends Kernel
{

    public function registerBundles()
    {
        $bundles = array(
            new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
            // ...
            // register the bundle here
            new Debril\FeedIoBundle\DebrilFeedIoBundle(),

Then add the bundle's routing configuration in app/config/routing.yml :

feedio:
    resource: @DebrilFeedIoBundle/Resources/config/routing.yml

Fetching the repository

Do this if you want to contribute (and you're welcome to do so):

git clone https://github.com/alexdebril/FeedIoBundle.git

composer.phar install

 Unit Testing

You can run the unit test suites using the following command in the Bundle's source director:

bin/phpunit

Usage

feedio-bundle is designed to read feeds across the internet and to publish your own. Its main class is FeedIo, which is accessible as a service called 'feedio' :

reading


// get it through the container
$feedIo = $this->container->get('feedio');

// read a feed
$result = $feedIo->read($url);

// or read a feed since a certain date
$result = $feedIo->readSince($url, new \DateTime('-7 days'));

// get title
$feedTitle = $result->getFeed()->getTitle();

// iterate through items
foreach( $result->getFeed() as $item ) {
    $item->getTitle();
}

formatting an object into a XML stream


// get it through the container
$feedIo = $this->container->get('feedio');

// build the feed
$feed = new \FeedIo\Feed;
$feed->setTitle('...');

// convert it into Atom
$dom = $feedIo->toAtom($feed);

// or ...
$dom = $feedIo->format($feed, 'atom');

Providing feeds using the StreamController


FeedIoBundle offers the ability to provide RSS/Atom feeds. The route will match the following pattern : /{format}/{id}

  • {format} must be "rss" or "atom" (or whatever you want if you add the according routing rule in routing.yml)
  • {id} is an optional argument. Use it you have several feeds

The request will be handled by StreamController, according to the following steps :

  • 1 : grab the ModifiedSince header if it exists
  • 2 : get the storage defined in services.xml and calls the getFeed($id) method
  • 4 : compare the feed's LastModified property with the ModifiedSince header
  • 5 : if LastModified is prior or equal to ModifiedSince then the response contains only a "NotModified" header and the 304 code. Otherwise, the stream is built and sent to the client

StreamController expects the getFeed()'s return value to be a \FeedIo\FeedInterface instance. It can be a \FeedIo\Feed or a class you wrote and if so, your class MUST implement \FeedIo\FeedInterface.

Useful Tips

Skipping 304 HTTP Code

The HTTP cache handling can be annoying during development process, you can skip it through configuration in your app/config/parameters.yml file :

parameters:
    force_refresh:     true

This way, the StreamController will always display your feed's content and return a 200 HTTP code.

 Contributors

RSS and Atom support for Symfony 2
Copyright (C) 2013 Alexandre Debril

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

For full license : <http://opensource.org/licenses/lgpl-3.0.html>
  • php 5.5 and 5.6 support
    By alexdebril, 2 years ago
  • explanation about 'feedio' service
    By alexdebril, 2 years ago
  • turn FeedIoCommandTrait into FeedIoContainerTrait
    By alexdebril, 2 years ago
  • use bundle's routing.yml
    By alexdebril, 2 years ago
  • test on bad provider is outdated
    By alexdebril, 2 years ago
  • added routing configuration in the installation section
    By alexdebril, 2 years ago
  • move samples into a dedicated folder
    By alexdebril, 2 years ago
  • all exceptions are now in the Exception folder
    By alexdebril, 2 years ago
  • remove unused parameters
    By alexdebril, 2 years ago
  • no more xml
    By alexdebril, 2 years ago
  • routing is now defined in yml format
    By alexdebril, 2 years ago
  • complete configuration
    By alexdebril, 2 years ago
  • removed useless file
    By alexdebril, 2 years ago
  • yaml routing
    By alexdebril, 2 years ago
  • StreamController throws a proper exception when storage is invalid
    By alexdebril, 2 years ago
  • remove unused configuration file
    By alexdebril, 2 years ago
  • remove unused $options
    By alexdebril, 2 years ago
  • remove useless statements
    By alexdebril, 2 years ago
  • corect routing configuration
    By alexdebril, 2 years ago
  • strings replacement
    By alexdebril, 2 years ago
  • symfony 2.7 compatibility
    By alexdebril, 2 years ago
  • feed-io 1.0 dependency
    By alexdebril, 2 years ago
  • Fix feed-io's version
    By alexdebril, 2 years ago
  • Blog URL
    By alexdebril, 2 years ago
  • Fix SensioLabs violations
    By alexdebril, 2 years ago
  • first unit test for doctrineStorage
    By alexdebril, 2 years ago
  • class renaming
    By alexdebril, 2 years ago
  • added getContainer() as an abstract method
    By alexdebril, 2 years ago
  • FeedIoCommand turned into a trait
    By alexdebril, 2 years ago
  • FeedIoCommand id not an abstract class
    By alexdebril, 2 years ago