2013-06-29 03:50:15 +02:00
|
|
|
<?php
|
|
|
|
|
2014-12-24 03:28:26 +01:00
|
|
|
namespace PicoFeed\Syndication;
|
2013-06-29 03:50:15 +02:00
|
|
|
|
2014-05-20 20:20:27 +02:00
|
|
|
use RuntimeException;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base writer class
|
|
|
|
*
|
2014-10-19 20:42:31 +02:00
|
|
|
* @author Frederic Guillot
|
2014-12-24 03:28:26 +01:00
|
|
|
* @package Syndication
|
2014-05-20 20:20:27 +02:00
|
|
|
*/
|
2013-06-29 03:50:15 +02:00
|
|
|
abstract class Writer
|
|
|
|
{
|
2014-05-20 20:20:27 +02:00
|
|
|
/**
|
|
|
|
* Dom object
|
|
|
|
*
|
|
|
|
* @access protected
|
2014-10-19 20:42:31 +02:00
|
|
|
* @var \DomDocument
|
2014-05-20 20:20:27 +02:00
|
|
|
*/
|
|
|
|
protected $dom;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Items
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @var array
|
|
|
|
*/
|
2013-06-29 03:50:15 +02:00
|
|
|
public $items = array();
|
|
|
|
|
2014-10-19 20:42:31 +02:00
|
|
|
/**
|
|
|
|
* Author
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $author = array();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Feed URL
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $feed_url = '';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Website URL
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $site_url = '';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Feed title
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $title = '';
|
|
|
|
|
2014-12-24 03:28:26 +01:00
|
|
|
/**
|
|
|
|
* Feed description
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $description = '';
|
|
|
|
|
2014-10-19 20:42:31 +02:00
|
|
|
/**
|
|
|
|
* Feed modification date (timestamp)
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @var integer
|
|
|
|
*/
|
|
|
|
public $updated = 0;
|
|
|
|
|
2014-05-20 20:20:27 +02:00
|
|
|
/**
|
|
|
|
* Generate the XML document
|
|
|
|
*
|
|
|
|
* @abstract
|
|
|
|
* @access public
|
|
|
|
* @param string $filename Optional filename
|
|
|
|
* @return string
|
|
|
|
*/
|
2013-06-29 03:50:15 +02:00
|
|
|
abstract public function execute($filename = '');
|
|
|
|
|
2014-05-20 20:20:27 +02:00
|
|
|
/**
|
|
|
|
* Check required properties to generate the output
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @param array $properties List of properties
|
|
|
|
* @param mixed $container Object or array container
|
|
|
|
*/
|
|
|
|
public function checkRequiredProperties(array $properties, $container)
|
2013-06-29 03:50:15 +02:00
|
|
|
{
|
2013-06-29 19:41:36 +02:00
|
|
|
foreach ($properties as $property) {
|
|
|
|
if ((is_object($container) && ! isset($container->$property)) || (is_array($container) && ! isset($container[$property]))) {
|
2014-05-20 20:20:27 +02:00
|
|
|
throw new RuntimeException('Required property missing: '.$property);
|
2013-06-29 03:50:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-05-20 20:20:27 +02:00
|
|
|
}
|