1<?php 2/** 3 * Zend Framework (http://framework.zend.com/) 4 * 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 8 */ 9 10namespace Zend\View\Model; 11 12use Zend\Feed\Writer\Feed; 13use Zend\Feed\Writer\FeedFactory; 14 15/** 16 * Marker view model for indicating feed data. 17 */ 18class FeedModel extends ViewModel 19{ 20 /** 21 * @var Feed 22 */ 23 protected $feed; 24 25 /** 26 * @var false|string 27 */ 28 protected $type = false; 29 30 /** 31 * A feed is always terminal 32 * 33 * @var bool 34 */ 35 protected $terminate = true; 36 37 /** 38 * @return \Zend\Feed\Writer\Feed 39 */ 40 public function getFeed() 41 { 42 if ($this->feed instanceof Feed) { 43 return $this->feed; 44 } 45 46 if (!$this->type) { 47 $options = $this->getOptions(); 48 if (isset($options['feed_type'])) { 49 $this->type = $options['feed_type']; 50 } 51 } 52 53 $variables = $this->getVariables(); 54 $feed = FeedFactory::factory($variables); 55 $this->setFeed($feed); 56 57 return $this->feed; 58 } 59 60 /** 61 * Set the feed object 62 * 63 * @param Feed $feed 64 * @return FeedModel 65 */ 66 public function setFeed(Feed $feed) 67 { 68 $this->feed = $feed; 69 return $this; 70 } 71 72 /** 73 * Get the feed type 74 * 75 * @return false|string 76 */ 77 public function getFeedType() 78 { 79 if ($this->type) { 80 return $this->type; 81 } 82 83 $options = $this->getOptions(); 84 if (isset($options['feed_type'])) { 85 $this->type = $options['feed_type']; 86 } 87 return $this->type; 88 } 89} 90