Download the PHP package muspi/feedbundle without Composer
On this page you can find all versions of the php package muspi/feedbundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package feedbundle
FeedBundle - A bundle to build RSS/Atom feeds from entities
Features
- Generate XML feeds (RSS & Atom formats)
- Easy to configure & use
- Items based on your entities
- Add groups of items
- Add enclosure media tags
- Translate your feed data
- Read XML feeds and populate your Symfony entities
- Dump your feeds into a file via a Symfony console command
Installation
Add the package to your composer.json file
Add this to app/AppKernel.php
Add this to app/autoload.php
Configuration (only 3 quick steps!)
1) Edit app/config.yml
The following configuration lines are required:
You can set link as route:
2) Implement the ItemInterface
Each entities you will use to generate an RSS feed needs to implement Eko\FeedBundle\Item\Writer\ItemInterface
or Eko\FeedBundle\Item\Writer\RoutedItemInterface
as demonstrated in this example for an Article
entity of a blog:
Option A: Eko\FeedBundle\Item\Writer\ItemInterface
In this same entity, just implement those required methods:
public function getFeedItemTitle() { … }
: this method returns entity item titlepublic function getFeedItemDescription() { … }
: this method returns entity item description (or content)public function getFeedItemPubDate() { … }
: this method returns entity item publication datepublic function getFeedItemLink() { … }
: this method returns entity item link (URL)
Option B: Eko\FeedBundle\Item\Writer\RoutedItemInterface
Alternatively, if you need to make use of the router service to generate the link for your entity you can use the following interface. You don't need to worry about injecting the router to your entity.
In this entity, you'll need to implement the following methods:
public function getFeedItemTitle() { … }
: this method returns entity item titlepublic function getFeedItemDescription() { … }
: this method returns entity item description (or content)public function getFeedItemPubDate() { … }
: this method returns entity item publication datepublic function getFeedItemRouteName() { … }
: this method returns the name of the routepublic function getFeedItemRouteParameters() { … }
: this method must return an array with the parameters that are required for the routepublic function getFeedItemUrlAnchor() { … }
: this method returns the anchor that will be appended to the router-generated url. Note: can be an empty string.
3) Generate the feed!
The action now takes place in your controller. Just declare a new action with those examples lines:
Please note that for better performances you can add a cache control.
Moreover, entities objects can be added separately with add method:
Go further with your feeds
Add some custom channel fields
You can add custom fields to main channel by adding them this way:
Add some custom items fields
Add custom item fields
You can add custom items fields for your entities nodes by adding them this way:
Of course, getFeedItemCustom()
method needs to be declared in your entity.
Add a group of custom item fields (optionally, with attributes)
You can also add group item fields using this way, if your method returns an array:
or even, multiple item fields in a group, like this:
Add a group of custom channel fields
As you can do for item fields, you can also add a custom group of channel fields like this:
Add custom media item fields
Media enclosure can be added using the MediaItemField
field type as below:
The getFeedMediaItem()
method must return an array with the following keys: type, length & value:
This media items can also be grouped using GroupItemField
.
Dump your feeds by using the Symfony console command
You can dump your feeds into a .xml file if you don't want to generate it on the fly by using the php app/console eko:feed:dump
Symfony command.
Here are the options :
Option | Description |
---|---|
--name | Feed name defined in eko_feed configuration |
--entity | Entity to use to generate the feed |
--filename | Defines feed filename |
--orderBy | Order field to sort by using findBy() method |
--direction | Direction to give to sort field with findBy() method |
--format | Formatter to use to generate, "rss" is default |
--limit | Defines a limit of entity items to retrieve |
Host | Defines the host base to generate absolute Url |
An example with all the options:
php app/console eko:feed:dump --name=article --entity=AcmeDemoBundle:Fake --filename=test.xml --format=atom --orderBy=id --direction=DESC www.myhost.com
This will result:
Dump your feeds by using the eko_feed.feed.dump
You can dump your feeds by simply using the "eko_feed.feed.dump" service. Used by the dump command, you have the same value to set. If you already have you items feed ready, you can dump it using the setItems().
For any question, do not hesitate to contact me and/or participate.
Read an XML feed and populate an entity
If you only want to read an XML feed, here is the way:
$feed
will be a \Zend\Feed\Reader\Feed\FeedInterface
that you can manipulate.
You can also populate an entity from an XML feed. This is very easy.
Just load the feed and call the populate method with your entity name which needs to implement Eko\FeedBundle\Item\Reader\ItemInterface
, take a look on this example:
In this example, $items
will be an array that will contains an array with your entities populated with the given feed content.
Use a custom hydrator to populate your entity
You can also write your own hydrator and use it this way:
This way, your custom hydrator will be used instead of the Eko\FeedBundle\Hydrator\DefaultHydrator
Define a custom feed formatter
You can define your own feed formatter by using the following tag:
Then, use it by simply calling $feed->render('custom')
.
Contributors
- Vincent Composieux [email protected] (Twitter: @vcomposieux)
- Rob Masters [email protected]
-
Thomas P [email protected] (Twitter: @scullwm)
- Anyone want to contribute ? Do not hesitate, you will be listed here!
All versions of feedbundle with dependencies
symfony/framework-bundle Version ^2.5|^3.0|^4.0
zendframework/zend-feed Version >=2.0
zendframework/zend-servicemanager Version >=2.0
zendframework/zend-http Version >=2.0