<?php
namespace PicoFeed\Syndication;
use DateTime;
use DOMDocument;
/**
* Class FeedBuilder
*
* @package PicoFeed\Syndication
* @author Frederic Guillot
*/
abstract class FeedBuilder
{
* @var DOMDocument
protected $document;
* @var string
protected $feedTitle;
protected $feedUrl;
protected $siteUrl;
protected $authorName;
protected $authorEmail;
protected $authorUrl;
* @var DateTime
protected $feedDate;
* @var ItemBuilder[]
protected $items = array();
* Constructor
* @access public
public function __construct()
$this->document = new DomDocument('1.0', 'UTF-8');
$this->document->formatOutput = true;
}
* Get new object instance
* @return static
public static function create()
return new static();
* Add feed title
* @param string $title
* @return $this
public function withTitle($title)
$this->feedTitle = $title;
return $this;
* Add feed url
* @param string $url
public function withFeedUrl($url)
$this->feedUrl = $url;
* Add website url
public function withSiteUrl($url)
$this->siteUrl = $url;
* Add feed date
* @param DateTime $date
public function withDate(DateTime $date)
$this->feedDate = $date;
* Add feed author
* @param string $name
* @param string $email
public function withAuthor($name, $email = '', $url ='')
$this->authorName = $name;
$this->authorEmail = $email;
$this->authorUrl = $url;
* Add feed item
* @param ItemBuilder $item
public function withItem(ItemBuilder $item)
$this->items[] = $item;
* Get DOM document
* @return DOMDocument
public function getDocument()
return $this->document;
* Build feed
* @abstract
* @param string $filename
* @return string
abstract public function build($filename = '');