2017 © Pedro Peláez
 

library feeder

Library containing functions to download, parse, transform and export different types of feeds.

image

treehouselabs/feeder

Library containing functions to download, parse, transform and export different types of feeds.

  • Tuesday, December 12, 2017
  • by pkruithof
  • Repository
  • 5 Watchers
  • 3 Stars
  • 9,467 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 9 Versions
  • 1 % Grown

The README.md

Feeder

![Latest Version on Packagist][ico-version] Software License ![Build Status][ico-travis] Coverage Status ![Quality Score][ico-code-quality], (*1)

Library containing functions to download, parse, transform and export different types of feeds., (*2)

Installation

composer require treehouselabs/feeder:~1.0

Usage

Here's a simple feed processing script:, (*3)

// create a new reader, in this case we'll fetch a feed from the interwebs
$resource = new FileResource(HttpTransport::create('http://example.org/feed'));
$reader = new XmlReader($resource);

// tell the reader to pull <item> nodes
$reader->setNodeCallback('item');

// create a feed for this reader
$feed = new Feed($reader);

// now simply iterate over the items
foreach ($feed as $item) {
    // $item is a ParameterBag instance with the serialized <item> node as data
}

Modifiers

Feeder becomes really powerful when you start adding modifiers. Modifiers are applied to each item and can be used to transform field values, remap keys, remove/add new values, etc., (*4)

Say we have the following <item> node in the feed we want to process:, (*5)

<item>
  <title>The quick brown fox jumps over the lazy dog</title>
  <publishDate>Thu, 05 Mar 2015 20:24:38 +0000</publishDate>
  <explicit>yes</explicit>
  <link href="http://example.org/articles/1"/>
</item>

This will give the following item:, (*6)

[
  'title' => 'The quick brown fox jumps over the lazy dog',
  'publishDate' => 'Thu, 05 Mar 2015 20:24:38 +0000',
  'explicit' => 'yes',
  'link' => [
    '#'     => '',
    '@href' => 'http://example.org/articles/1'
  ],
]

If for some reason your OCD-levels are like mine and you want data to be snake_cased:, (*7)

$feed->addTransformer(new LowercaseKeysTransformer());

// will return:
[
  'title' => 'The quick brown fox jumps over the lazy dog',
  'publish_date' => 'Thu, 05 Mar 2015 20:24:38 +0000',
  'explicit' => 'yes',
  'link' => [
    '#'     => '',
    '@href' => 'http://example.org/articles/1'
  ],
]

Now we want the publish date to be an actual DateTime instance:, (*8)

// the DataTransformer wraps a transformer for a specific field,
// instead of the whole item
$transformer = new DataTransformer(
    new StringToDateTimeTransformer(DATE_RFC2822),
    'publish_date'
);
$feed->addTransformer($transformer);

// will return:
[
  'title' => 'The quick brown fox jumps over the lazy dog',
  'publish_date' => DateTime::__set_state(array(
    'date' => '2015-03-05 20:24:38.000000',
    'timezone_type' => 1,
    'timezone' => '+00:00',
  )),
  'explicit' => 'yes',
  'link' => [
    '#'     => '',
    '@href' => 'http://example.org/articles/1'
  ],
]

Some more examples:, (*9)

$feed->addTransformer(
  new DataTransformer(
    new StringToBooleanTransformer(),
    'explicit'
  )
);
$feed->addTransformer(
    new DataTransformer(
        new CallbackTransformer(function ($value) { return $value['@href']; }),
        'link'
    )
);

// will return:
[
  'title' => 'The quick brown fox jumps over the lazy dog',
  'publish_date' => DateTime::__set_state(array(
    'date' => '2015-03-05 20:24:38.000000',
    'timezone_type' => 1,
    'timezone' => '+00:00',
  )),
  'explicit' => true,
  'link' => 'http://example.org/articles/1',
]

As you can see you can create really powerful chains of modifiers to get the outcome you want. Modifiers are not limited to transformative functions, there are mappers (map keys in the item to your own fields), filters (exclude items based on your own logic) and validators (raises exceptions when an item is invalid). There are a lot of modifiers that come with this library, check them out!, (*10)

Testing

bash composer test, (*11)

Security

If you discover any security related issues, please email peter@treehouse.nl instead of using the issue tracker., (*12)

License

The MIT License (MIT). Please see License File for more information., (*13)

Credits

The Versions

12/12 2017

dev-master

9999999-dev

Library containing functions to download, parse, transform and export different types of feeds.

  Sources   Download

MIT

The Requires

 

The Development Requires

feed

12/12 2017

v1.1.5

1.1.5.0

Library containing functions to download, parse, transform and export different types of feeds.

  Sources   Download

MIT

The Requires

 

The Development Requires

feed

05/12 2017

v1.1.4

1.1.4.0

Library containing functions to download, parse, transform and export different types of feeds.

  Sources   Download

MIT

The Requires

 

The Development Requires

feed

05/12 2017

v1.1.3

1.1.3.0

Library containing functions to download, parse, transform and export different types of feeds.

  Sources   Download

MIT

The Requires

 

The Development Requires

feed

30/01 2017

v1.1.2

1.1.2.0

Library containing functions to download, parse, transform and export different types of feeds.

  Sources   Download

MIT

The Requires

 

The Development Requires

feed

09/11 2016

v1.1.1

1.1.1.0

Library containing functions to download, parse, transform and export different types of feeds.

  Sources   Download

MIT

The Requires

 

The Development Requires

feed

26/04 2016

v1.1.0

1.1.0.0

Library containing functions to download, parse, transform and export different types of feeds.

  Sources   Download

MIT

The Requires

 

The Development Requires

feed

12/10 2015

v1.0.0

1.0.0.0

Library containing functions to download, parse, transform and export different types of feeds.

  Sources   Download

MIT

The Requires

 

The Development Requires

feed

03/04 2015

v0.1.0

0.1.0.0

Library containing functions to download, parse, transform and export different types of feeds.

  Sources   Download

MIT

The Requires

 

The Development Requires

feed