3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Feed\Reader\Extension\Syndication;
14 use Zend\Feed\Reader\Extension;
16 class Feed extends Extension\AbstractFeed
22 * @throws Reader\Exception\InvalidArgumentException
24 public function getUpdatePeriod()
26 $name = 'updatePeriod';
27 $period = $this->getData($name);
29 if ($period === null) {
30 $this->data[$name] = 'daily';
31 return 'daily'; //Default specified by spec
41 throw new Reader\Exception\InvalidArgumentException("Feed specified invalid update period: '$period'."
42 . " Must be one of hourly, daily, weekly or yearly");
47 * Get update frequency
51 public function getUpdateFrequency()
53 $name = 'updateFrequency';
54 $freq = $this->getData($name, 'number');
56 if (! $freq || $freq < 1) {
57 $this->data[$name] = 1;
65 * Get update frequency as ticks
69 public function getUpdateFrequencyAsTicks()
71 $name = 'updateFrequency';
72 $freq = $this->getData($name, 'number');
74 if (! $freq || $freq < 1) {
75 $this->data[$name] = 1;
79 $period = $this->getUpdatePeriod();
84 $ticks *= 52; //TODO: fix generalisation, how?
95 default: //Never arrive here, exception thrown in getPeriod()
99 return $ticks / $freq;
105 * @return DateTime|null
107 public function getUpdateBase()
109 $updateBase = $this->getData('updateBase');
112 $date = DateTime::createFromFormat(DateTime::W3C, $updateBase);
118 * Get the entry data specified by name
120 * @param string $name
121 * @param string $type
124 private function getData($name, $type = 'string')
126 if (array_key_exists($name, $this->data)) {
127 return $this->data[$name];
130 $data = $this->xpath->evaluate($type . '(' . $this->getXpathPrefix() . '/syn10:' . $name . ')');
136 $this->data[$name] = $data;
142 * Register Syndication namespaces
146 protected function registerNamespaces()
148 $this->xpath->registerNamespace('syn10', 'http://purl.org/rss/1.0/modules/syndication/');