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;
|
|
|
|
|
|
|
|
/**
|
2015-10-20 04:49:30 +02:00
|
|
|
* Base writer class.
|
2014-05-20 20:20:27 +02:00
|
|
|
*
|
2014-10-19 20:42:31 +02:00
|
|
|
* @author Frederic Guillot
|
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
|
|
|
/**
|
2015-10-20 04:49:30 +02:00
|
|
|
* Dom object.
|
2014-05-20 20:20:27 +02:00
|
|
|
*
|
2014-10-19 20:42:31 +02:00
|
|
|
* @var \DomDocument
|
2014-05-20 20:20:27 +02:00
|
|
|
*/
|
|
|
|
protected $dom;
|
|
|
|
|
|
|
|
/**
|
2015-10-20 04:49:30 +02:00
|
|
|
* Items.
|
2014-05-20 20:20:27 +02:00
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2013-06-29 03:50:15 +02:00
|
|
|
public $items = array();
|
|
|
|
|
2014-10-19 20:42:31 +02:00
|
|
|
/**
|
2015-10-20 04:49:30 +02:00
|
|
|
* Author.
|
2014-10-19 20:42:31 +02:00
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $author = array();
|
|
|
|
|
|
|
|
/**
|
2015-10-20 04:49:30 +02:00
|
|
|
* Feed URL.
|
2014-10-19 20:42:31 +02:00
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $feed_url = '';
|
|
|
|
|
|
|
|
/**
|
2015-10-20 04:49:30 +02:00
|
|
|
* Website URL.
|
2014-10-19 20:42:31 +02:00
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $site_url = '';
|
|
|
|
|
|
|
|
/**
|
2015-10-20 04:49:30 +02:00
|
|
|
* Feed title.
|
2014-10-19 20:42:31 +02:00
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $title = '';
|
|
|
|
|
2014-12-24 03:28:26 +01:00
|
|
|
/**
|
2015-10-20 04:49:30 +02:00
|
|
|
* Feed description.
|
2014-12-24 03:28:26 +01:00
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $description = '';
|
|
|
|
|
2014-10-19 20:42:31 +02:00
|
|
|
/**
|
2015-10-20 04:49:30 +02:00
|
|
|
* Feed modification date (timestamp).
|
2014-10-19 20:42:31 +02:00
|
|
|
*
|
2015-10-20 04:49:30 +02:00
|
|
|
* @var int
|
2014-10-19 20:42:31 +02:00
|
|
|
*/
|
|
|
|
public $updated = 0;
|
|
|
|
|
2014-05-20 20:20:27 +02:00
|
|
|
/**
|
2015-10-20 04:49:30 +02:00
|
|
|
* Generate the XML document.
|
2014-05-20 20:20:27 +02:00
|
|
|
*
|
|
|
|
* @abstract
|
2015-10-20 04:49:30 +02:00
|
|
|
*
|
|
|
|
* @param string $filename Optional filename
|
|
|
|
*
|
2014-05-20 20:20:27 +02:00
|
|
|
* @return string
|
|
|
|
*/
|
2013-06-29 03:50:15 +02:00
|
|
|
abstract public function execute($filename = '');
|
|
|
|
|
2014-05-20 20:20:27 +02:00
|
|
|
/**
|
2015-10-20 04:49:30 +02:00
|
|
|
* Check required properties to generate the output.
|
2014-05-20 20:20:27 +02:00
|
|
|
*
|
2015-10-20 04:49:30 +02:00
|
|
|
* @param array $properties List of properties
|
|
|
|
* @param mixed $container Object or array container
|
2014-05-20 20:20:27 +02:00
|
|
|
*/
|
|
|
|
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) {
|
2015-10-20 04:49:30 +02:00
|
|
|
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
|
|
|
}
|