dev-master
9999999-devMapper-based services for easy use RSS and Atom responses
MIT
The Requires
The Development Requires
by Benjamin Kleiner
atom feed rss response rdf
Wallogit.com
2017 © Pedro Peláez
Mapper-based services for easy use RSS and Atom responses
FeedResponse can be included in the usual way with composer:, (*1)
composer require benkle/feed-response
Feed responses are built using a factory, which requires a bit of a setup:, (*2)
use \Benkle\FeedInterfaces as FeedInterfaces;
use \Benkle\FeedResponse\XmlMappers\Atom as Atom;
use \Benkle\FeedResponse\XmlMappers\RSS20 as RSS20;
use \Benkle\FeedResponse\Collections as Collections;
use \Benkle\FeedResponse\FeedResponseFactory;
// You need two feed mappers, each with a collection of mappers
// for specific parts of the feed.
$atomMappers = new Collections\FeedItemMapperCollection();
$atomMappers
->add(ItemInterface::class, new Atom\FeedItemMapper())
->add(EnclosureInterface::class, new Atom\EnclosureMapper())
->add(RelationLinkInterface::class, new Atom\RelationLinkMapper());
$atomMapper = new Atom\FeedMapper();
$atomMapper->setMapperCollection($atomMappers);
$rssMappers = new Collections\FeedItemMapperCollection();
$rssMappers
->add(ItemInterface::class, new RSS20\FeedItemMapper())
->add(EnclosureInterface::class, new RSS20\EnclosureMapper())
->add(RelationLinkInterface::class, new Atom\RelationLinkMapper(true));
$rssMapper = new RSS20\FeedMapper();
$rssMapper->setMapperCollection($rssMappers);
$feedResponseFactory = new FeedResponseFactory();
$feedResponseFactory
->setAtomMapper($atomMapper)
->setObjectMappers($objectMappers)
->setRssMapper($rssMapper)
->setFeedPrototype(/* Insert an instance of \Benkle\FeedInterfaces\FeedInterface here */)
->setRelationLinkPrototype(/* Insert an instance of \Benkle\FeedInterfaces\RelationLinkInterface here */);
Afterwards you can simply create a response object with the apropriate methods:, (*3)
$atomFeed = $feedResponseFactory->atom($head, $items, $relations); // For an Atom feed $rssFeed = $feedResponseFactory->rss($head, $items, $relations); // For an RSS 2.0 feed
These methods allow for some variation on it's three parameters:, (*4)
$head can be...
title | title |
| description | description | subtitle |
| modified | lastBuildDate | updated |
| link | link | link[rel=self] |
| id | guid | id |\Benkle\FeedInterfaces\FeedInterface
$items is an array of any type of object.
Instances of \Benkle\FeedInterfaces\FeedItemInterface will be handled directly,
for any other type of object you'll also need a matching object mapper.$relations is an array where elements can be any of these:
\Benkle\FeedInterfaces\RelationLinkInterface
<link rel="key" href="value"/>
href |
| relationType, rel | rel |
| mimeType, mime, type | type |
| title | title |PriorityList from benkle/feed-parser)Mapper-based services for easy use RSS and Atom responses
MIT
atom feed rss response rdf