{"id":15063271,"url":"https://github.com/eko/feedbundle","last_synced_at":"2025-05-16T17:04:58.077Z","repository":{"id":3701026,"uuid":"4772115","full_name":"eko/FeedBundle","owner":"eko","description":"A Symfony bundle to build RSS feeds from your entities","archived":false,"fork":false,"pushed_at":"2024-10-07T04:33:33.000Z","size":299,"stargazers_count":141,"open_issues_count":11,"forks_count":49,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-10-30T03:41:25.579Z","etag":null,"topics":["feed","php","symfony","symfony-bundle","xml","xml-feed"],"latest_commit_sha":null,"homepage":"http://vincent.composieux.fr","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eko.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2012-06-24T12:25:36.000Z","updated_at":"2024-03-19T05:40:00.000Z","dependencies_parsed_at":"2024-11-12T22:00:41.351Z","dependency_job_id":"122165ec-1423-4710-acf3-6102edb0cc60","html_url":"https://github.com/eko/FeedBundle","commit_stats":{"total_commits":173,"total_committers":28,"mean_commits":6.178571428571429,"dds":0.6069364161849711,"last_synced_commit":"f57ad60a9b7eafbd8b87d4788c015d02bcde643b"},"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eko%2FFeedBundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eko%2FFeedBundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eko%2FFeedBundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eko%2FFeedBundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eko","download_url":"https://codeload.github.com/eko/FeedBundle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247578556,"owners_count":20961271,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["feed","php","symfony","symfony-bundle","xml","xml-feed"],"created_at":"2024-09-24T23:54:19.628Z","updated_at":"2025-04-07T02:11:24.298Z","avatar_url":"https://github.com/eko.png","language":"PHP","readme":"FeedBundle\n==========\n\nA Symfony bundle to build RSS/Atom feeds from entities\n\n[![SensioLabsInsight](https://insight.sensiolabs.com/projects/5620e128-834b-462c-b6fc-395609c57999/big.png)](https://insight.sensiolabs.com/projects/5620e128-834b-462c-b6fc-395609c57999)\n\n[![Build Status](https://secure.travis-ci.org/eko/FeedBundle.png?branch=master)](http://travis-ci.org/eko/FeedBundle)\n[![Latest Stable Version](https://poser.pugx.org/eko/feedbundle/version.png)](https://packagist.org/packages/eko/feedbundle)\n[![Total Downloads](https://poser.pugx.org/eko/feedbundle/d/total.png)](https://packagist.org/packages/eko/feedbundle)\n\nFeatures\n--------\n\n * Generate XML feeds (RSS \u0026 Atom formats)\n * Easy to configure \u0026 use\n * Items based on your entities\n * Add groups of items\n * Add enclosure media tags\n * Translate your feed data\n * Read XML feeds and populate your Symfony entities\n * Dump your feeds into a file via a Symfony console command\n\nInstallation\n------------\n\nAdd the package to your `composer.json` file\n```\n\"eko/feedbundle\": \"dev-master\",\n```\n\nAdd this to to the `config/bundles.php` file:\n```php\n\u003c?php\n\nreturn [\n    // ...\n    Eko\\FeedBundle\\EkoFeedBundle::class =\u003e ['all' =\u003e true],\n];\n```\n\n\nConfiguration (only 3 quick steps!)\n-----------------------------------\n\n### 1) Create a file: config/packages/eko_feed.yml\n\nThe following configuration lines are required:\n\n```yaml\neko_feed:\n    hydrator: your_hydrator.custom.service # Optional, if you use entity hydrating with a custom hydrator\n    translation_domain: test # Optional, if you want to use a custom translation domain\n    feeds:\n        article:\n            title:       'My articles/posts'\n            description: 'Latests articles'\n            link:        'http://vincent.composieux.fr'\n            encoding:    'utf-8'\n            author:      'Vincent Composieux' # Only required for Atom feeds\n```\n\nYou can also set link as a Symfony route:\n```yaml\nlink:\n    route_name: acme_blog_main_index\n    route_params: {id: 2} # necessary if route contains required parameters\n```\n\n### 2) Implement the ItemInterface\n\nEach 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:\n\n#### Option A: Eko\\FeedBundle\\Item\\Writer\\ItemInterface\n\n```php\n\u003c?php\n\nnamespace Bundle\\BlogBundle\\Entity;\n\nuse Eko\\FeedBundle\\Item\\Writer\\ItemInterface;\n\n/**\n * Bundle\\BlogBundle\\Entity\\Article\n */\nclass Article implements ItemInterface\n{\n```\n\nIn this same entity, just implement those required methods:\n\n * `public function getFeedItemTitle() { … }` : this method returns entity item title\n * `public function getFeedItemDescription() { … }` : this method returns entity item description (or content)\n * `public function getFeedItemPubDate() { … }` : this method returns entity item publication date\n * `public function getFeedItemLink() { … }` : this method returns entity item link (URL)\n\n#### Option B: Eko\\FeedBundle\\Item\\Writer\\RoutedItemInterface\n\nAlternatively, 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.\n\n```php\n\u003c?php\n\nnamespace Bundle\\BlogBundle\\Entity;\n\nuse Eko\\FeedBundle\\Item\\Writer\\RoutedItemInterface;\n\n/**\n * Bundle\\BlogBundle\\Entity\\Article\n */\nclass Article implements RoutedItemInterface\n{\n```\n\nIn this entity, you'll need to implement the following methods:\n\n * `public function getFeedItemTitle() { … }` : this method returns entity item title\n * `public function getFeedItemDescription() { … }` : this method returns entity item description (or content)\n * `public function getFeedItemPubDate() { … }` : this method returns entity item publication date\n * `public function getFeedItemRouteName() { … }` : this method returns the name of the route\n * `public function getFeedItemRouteParameters() { … }` : this method must return an array with the parameters that are required for the route\n * `public function getFeedItemUrlAnchor() { … }` : this method returns the anchor that will be appended to the router-generated url. *Note: can be an empty string.*\n\n\n### 3) Generate the feed!\n\nThe action now takes place in your controller. Just declare a new action with those examples lines:\n\n```php\n\u003c?php\n\nnamespace App\\Controller;\n\nuse Eko\\FeedBundle\\Feed\\FeedManager;\n\nuse Symfony\\Bundle\\FrameworkBundle\\Controller\\AbstractController;\nuse Symfony\\Component\\HttpFoundation\\Response;\nuse Symfony\\Component\\Routing\\Annotation\\Route;\n\nclass BlogController extends AbstractController\n{\n    /**\n     * @var FeedManager\n     */\n    protected $feedManager;\n\n    /**\n     * Constructor.\n     * \n     * @param FeedManager $feedManager\n     */\n    public function __construct(FeedManager $feedManager)\n    {\n        $this-\u003efeedManager = $feedManager;\n    }\n\n    /**\n     * Generate the article feed\n     * \n     * @Route(\"/feed.rss\", name=\"app_feed\")\n     *\n     * @return Response XML Feed\n     */\n    public function feed()\n    {\n        $articles = $this-\u003egetDoctrine()-\u003egetRepository('BundleBlogBundle:Article')-\u003efindAll();\n\n        $feed = $this-\u003efeedManager-\u003eget('article');\n        $feed-\u003eaddFromArray($articles);\n\n        return new Response($feed-\u003erender('rss')); // or 'atom'\n    }\n}\n```\n\nPlease note that for better performances you can add a cache control.\n\nMoreover, entities objects can be added separately with add method:\n\n```php\n\u003c?php\n$feed = $this-\u003eget('eko_feed.feed.manager')-\u003eget('article');\n$feed-\u003eadd($article);\n```\n\nGo further with your feeds\n--------------------------\n\n### Add some custom channel fields\n\nYou can add custom fields to main channel by adding them this way:\n\n```php\n\u003c?php\n$feed = $this-\u003eget('eko_feed.feed.manager')-\u003eget('article');\n$feed-\u003eadd(new FakeEntity());\n$feed-\u003eaddChannelField(new ChannelField('custom_name', 'custom_value'));\n```\n\n### Add some custom items fields\n\n##### Add custom item fields\n\nYou can add custom items fields for your entities nodes by adding them this way:\n\n```php\n\u003c?php\n$feed = $this-\u003eget('eko_feed.feed.manager')-\u003eget('article');\n$feed-\u003eadd(new FakeEntity());\n$feed-\u003eaddItemField(new ItemField('fake_custom', 'getFeedItemCustom'));\n```\n\nOf course, `getFeedItemCustom()` method needs to be declared in your entity.\n\n##### Add a group of custom item fields (optionally, with attributes)\n\nYou can also add group item fields using this way, if your method returns an array:\n\n```php\n\u003c?php\n$feed = $this-\u003eget('eko_feed.feed.manager')-\u003eget('article');\n$feed-\u003eadd(new FakeEntity());\n$feed-\u003eaddItemField(\n    new GroupItemField(\n        'categories',\n        new ItemField('category', 'getFeedCategoriesCustom', array(), array('category-attribute', 'test'),\n        array('categories-attribute', 'getAttributeValue')\n    )\n);\n```\n\nor even, multiple item fields in a group, like this:\n\n```php\n$feed-\u003eaddItemField(\n    new GroupItemField('author', array(\n        new ItemField('name', 'getFeedItemAuthorName', array('cdata' =\u003e true)),\n        new ItemField('email', 'getFeedItemAuthorEmail')\n    )\n);\n```\n\nor even, nested group item field in a group, like this:\n\n```php\n$feed-\u003eaddItemField(\n    new GroupItemField('authors', array(\n        new GroupItemField('author', array(\n            new ItemField('name', 'Vincent', array('cdata' =\u003e true)),\n            new ItemField('email', 'vincent@test.com')\n        )),\n        new GroupItemField('author', array(\n            new ItemField('name', 'Audrey', array('cdata' =\u003e true)),\n            new ItemField('email', 'audrey@test.com')\n        ))\n    )\n);\n```\n\n##### Add a group of custom channel fields\n\nAs you can do for item fields, you can also add a custom group of channel fields like this:\n\n```php\n$feed-\u003eaddChannelField(\n    new GroupChannelField('author', array(\n        new ChannelField('name', 'My author name'),\n        new ChannelField('email', 'myauthor@email.org')\n    )\n);\n```\n\n##### Add custom media item fields\n\nMedia enclosure can be added using the `MediaItemField` field type as below:\n\n```php\n\u003c?php\n$feed = $this-\u003eget('eko_feed.feed.manager')-\u003eget('article');\n$feed-\u003eadd(new FakeEntity());\n$feed-\u003eaddItemField(new MediaItemField('getFeedMediaItem'));\n```\n\nThe `getFeedMediaItem()` method must return an array with the following keys: type, length \u0026 value:\n\n```php\n/**\n * Returns a custom media field\n *\n * @return string\n */\npublic function getFeedMediaItem()\n{\n    return array(\n        'type'   =\u003e 'image/jpeg',\n        'length' =\u003e 500,\n        'value'  =\u003e 'http://website.com/image.jpg'\n    );\n}\n```\n\nThis media items can also be grouped using `GroupItemField`.\n\n### Dump your feeds by using the Symfony console command\n\nYou 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.\n\nHere are the options :\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003cth\u003eOption\u003c/th\u003e\n    \u003cth\u003eDescription\u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e--name\u003c/td\u003e\n    \u003ctd\u003eFeed name defined in eko_feed configuration\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e--entity\u003c/td\u003e\n    \u003ctd\u003eEntity to use to generate the feed\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e--filename\u003c/td\u003e\n    \u003ctd\u003eDefines feed filename\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e--orderBy\u003c/td\u003e\n    \u003ctd\u003eOrder field to sort by using findBy() method\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e--direction\u003c/td\u003e\n    \u003ctd\u003eDirection to give to sort field with findBy() method\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e--format\u003c/td\u003e\n    \u003ctd\u003eFormatter to use to generate, \"rss\" is default\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e--limit\u003c/td\u003e\n    \u003ctd\u003eDefines a limit of entity items to retrieve\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eHost\u003c/td\u003e\n    \u003ctd\u003eDefines the host base to generate absolute Url\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\nAn example with all the options:\n\n`php app/console eko:feed:dump --name=article --entity=AcmeDemoBundle:Fake --filename=test.xml --format=atom --orderBy=id --direction=DESC www.myhost.com`\n\nThis will result:\n```\nStart dumping \"article\" feed from \"AcmeDemoBundle:Fake\" entity...\ndone!\nFeed has been dumped and located in \"/Users/vincent/dev/perso/symfony/web/test.xml\"\n```\n\n### Dump your feeds by using the Eko\\FeedBundle\\Service\\FeedDumpService\nYou can dump your feeds by simply using the \"`Eko\\FeedBundle\\Service\\FeedDumpService`\" service. Used by the dump command, you have the same value to set.\nIf you already have you items feed ready, you can dump it using the setItems().\n\n```php\n\u003c?php\n\nuse Eko\\FeedBundle\\Service\\FeedDumpService;\n\n$feedDumpService = $this-\u003eget(FeedDumpService::class);\n$feedDumpService\n        -\u003esetName($name)\n        //You can set an entity\n        //-\u003esetEntity($entity)\n        // Or set you Items\n        -\u003esetItems($MyOwnItemList)\n        -\u003esetFilename($filename)\n        -\u003esetFormat($format)\n        -\u003esetLimit($limit)\n        -\u003esetDirection($direction)\n        -\u003esetOrderBy($orderBy)\n    ;\n\n$feedDumpService-\u003edump();\n```\n\n\nFor any question, do not hesitate to contact me and/or participate.\n\n### Read an XML feed and populate an entity\n\nIf you only want to read an XML feed, here is the way:\n\n```php\n\u003c?php\n$reader = $this-\u003eget('eko_feed.feed.reader');\n$reader-\u003esetHydrator(new DefaultHydrator());\n$feed = $reader-\u003eload('http://php.net/feed.atom')-\u003eget();\n```\n\n`$feed` will be a `\\Zend\\Feed\\Reader\\Feed\\FeedInterface` that you can manipulate.\n\n--------------------------------------------------------------------------------\n\nYou can also populate an entity from an XML feed. This is very easy.\n\nJust 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:\n\n```php\n\u003c?php\n$reader = $this-\u003eget('eko_feed.feed.reader');\n$reader-\u003esetHydrator(new DefaultHydrator());\n$items = $reader-\u003eload('http://php.net/feed.atom')-\u003epopulate('MyNamespace\\Entity\\Name');\n```\n\nIn this example, `$items` will be an array that will contains an array with your entities populated with the given feed content.\n\n### Use a custom hydrator to populate your entity\n\nYou can also write your own hydrator and use it this way:\n\n```php\n$reader = $this-\u003eget('eko_feed.feed.reader');\n$reader-\u003esetHydrator(new MyCustomHydrator());\n\n$items = $reader-\u003eload('http://php.net/feed.atom')-\u003epopulate('MyNamespace\\Entity\\Name');\n```\n\nThis way, your custom hydrator will be used instead of the `Eko\\FeedBundle\\Hydrator\\DefaultHydrator`\n\n### Define a custom feed formatter\n\nYou can define your own feed formatter by using the following tag:\n\n```xml\n\u003cservice id=\"acme.my_bundle.formatter.custom\" class=\"Acme\\MyBundle\\Feed\\Formatter\\CustomFormatter\"\u003e\n    \u003ctag name=\"eko_feed.formatter\" format=\"custom\"\u003e\u003c/tag\u003e\n\n    \u003cargument type=\"service\" id=\"translator\" /\u003e\n\u003c/service\u003e\n```\n\nThen, use it by simply calling `$feed-\u003erender('custom')`.\n\nContributors\n------------\n\n * Vincent Composieux \u003cvincent.composieux@gmail.com\u003e (Twitter: @vcomposieux)\n * Rob Masters \u003cmastahuk@gmail.com\u003e\n * Thomas P \u003cthomas@scullwm.com\u003e (Twitter: @scullwm)\n\n * Anyone want to contribute ? Do not hesitate, you will be listed here!\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feko%2Ffeedbundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feko%2Ffeedbundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feko%2Ffeedbundle/lists"}