generate RSS feed


RSS stands for Really Simple Syndication, which translates as "really fast distribution." RSS gives the user the opportunity to subscribe to the publication of the site - in whole or in part. Thus, the user gets the opportunity to follow the appearance of new publications on the site and read their summary without visiting the source site.Besides this you can do different useful things,for example create rss feed parser and move your articles to other site or steal articles from other sites that support rss:).
But if serious, theft is a sign of bad intention, do not do it. 

In order to subscribe to RSS-Feed, you will need an RSS-Reader program. This program monitors the automatic update and distribution of publications. There are many RSS readers in Google extensions you can install them.
You can read Wikipedia or other articles on the Internet in more detail. And so, let's start programming).

RSS feed, file in XML format, an example from Wikipedia.

<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
 <title>RSS Title</title>
 <description>This is an example of an RSS feed</description>
 <lastBuildDate>Mon, 06 Sep 2010 00:01:00 +0000 </lastBuildDate>
 <pubDate>Sun, 06 Sep 2009 16:20:00 +0000</pubDate>

  <title>Example entry</title>
  <description>Here is some text containing an interesting description.</description>
  <guid isPermaLink="false">7bd204c6-1655-4c27-aeee-53f933c5395f</guid>
  <pubDate>Sun, 06 Sep 2009 16:20:00 +0000</pubDate>


In order to generate a file in XML format or something like that, it’s convenient to use a design pattern` builder .
There is already a solution in the packagist, you can use one of them for example suin rss writer. 

class RssMap
    private $feed;
    private $channel;
    private $item;

    public function __construct(Feed $feed, Channel $channel, RssItem $item)
        $this->feed = $feed;
        $this->channel = $channel;
        $this->item = $item;


Set channel

    public function setChannel($channel)

        return $this;

Set rss items

    public function setItems(iterable $dataItems)
        foreach ($dataItems as $data) {
            $item = clone $this->item;

                ->guid($data->guid, true)

        return $this;

But if we started programming on the OOP approach, then we will create two objects MapChannel, MapItem


class MapChannel
    public $title;
    public $description;
    public $url;
    public $pubDate;
    public $lastBuildDate;
    public $ttl;

    public function __construct($title, $description, $url, $pubDate, $lastBuildDate, $ttl)
        $this->title = $title;
        $this->description = $description;
        $this->url = $url;
        $this->pubDate = $pubDate;
        $this->lastBuildDate = $lastBuildDate;
        $this->ttl = $ttl;


class MapItem
    public $title;
    public $description;
    public $link;
    public $guid;
    public $pubDate;

    public function __construct($title, $description, $link, $guid, $pubDate)
        $this->title       = $title;
        $this->description = $description;
        $this->link        = $link;
        $this->guid        = $guid;
        $this->pubDate     = $pubDate;

And the last example from the Rss Controller.

class RssController
    private $service;
    private $repository;

    public function __construct(RssMap $rssMap, ArticleRepository $repository)
        $this->service = $rssMap;
        $this->repository = $repository;

    public function create(Page $page)
        $articles = $this->repository->findAll();

        return $this->service
                new MapChannel(
            ->setItems($articles->map(function ($article) use ($page) {
                return new MapItem(

As you can see in the constructor is written ArticleRepository.Simply, in this example uses the design pattern repository.
Read more in this article.